[CMake] Re: CMake and Qt3

E. Wing ewmailing at gmail.com
Mon Jul 18 21:15:25 EDT 2005


> From: "Olivier Stern" 
> 
> After creating the makefile and compiling the program I have lots of errors
> but all the same type : undefined reference to

> 
> main.o(.text+0x17): In function `main':
> 
> : undefined reference to `QApplication::QApplication(int &, char **)'
> 

I've never done anything with Qt, but I'll take a stab until somebody
more knowledgeable steps in...

This is what the header of my FindQt.cmake module looks like. I'm
running a CVS version so it might be different than yours. If it is
different, maybe you should try CVS because maybe that means somebody
fixed your problem:

# Locate Qt include paths and libraries

# This module defines
# QT_INCLUDE_DIR, where to find qt.h, etc.
# QT_LIBRARIES, the libraries to link against to use Qt.
# QT_DEFINITIONS, definitions to use when compiling code that uses Qt.
# QT_FOUND, If false, don't try to use Qt.

#if you need the multithreaded version of Qt, set QT_MT_REQUIRED to TRUE

# also defined, but not for general use are
# QT_MOC_EXECUTABLE, where to find the moc tool.
# QT_UIC_EXECUTABLE, where to find the uic tool.
# QT_QT_LIBRARY, where to find the Qt library.
# QT_QTMAIN_LIBRARY, where to find the qtmain library. This is only
required by Qt3 on Windows.

# These are around for backwards compatibility 
# they will be set
# QT_WRAP_CPP, set true if QT_MOC_EXECUTABLE is found
# QT_WRAP_UI set true if QT_UIC_EXECUTABLE is found


So first, you have these following lines and they don't make a lot of
sense to me:

> SET (QT_WRAP_CPP "On")
> SET (QT_MOC_EXE "echo")
>
> SET (QT_WRAP_UI "On")
> SET (QT_UIC_EXE "${QT_UIC_EXECUTABLE}")
>
> QT_WRAP_UI (myqtlib QTUI_H_SRCS QTUI_S_SRCS ${QTUI_SRCS})
> QT_WRAP_CPP (myqtlib QT_MOC_SRCS ${SRCS} essai.h)

The header says QT_WRAP_CPP and QT_WRAP_UI are boolean flags and are
set for you, so I'm not sure why you are setting these. Also, in the
bottom two lines, you seem to be using them as a function call? I
didn't know you could do that. But this doesn't make a lot of sense to
me.

Next, do these two lines actually give you any valid output?
> MESSAGE("QT files are ${QTUI_S_SRCS}")
> MESSAGE("QT other files are ${QTUI_H_SRCS}")

I see you set QTUI_SRCS, but I don't know CMake's feature list well
enough to know if it splits the list into S and H.

I'm also not familiar with the .ui extension. Is this standard and
something CMake knows how to handle?

Next, I'm not sure where QT_MOC_SRCS gets defined. I presume the
variable will be empty. You might not be compiling all the files you
think you are.
> ADD_LIBRARY(myqtlib ${QTUI_S_SRCS} ${QT_MOC_SRCS})

 
> ADD_EXECUTABLE (qtwrapping main.cpp) 
> TARGET_LINK_LIBRARIES(qtwrapping myqtlib)
> TARGET_LINK_LIBRARIES( qtwrapping ${QT_LIBRARIES} )

Have you tried changing the 2 TARGET_LINK_LIBRARIES to a single
command? I'm not sure if CMake accumulates the settings or resets them
on subsequent commands.

Also, I'm wondering if you need to explicitly link against the
QT_QTMAIN_LIBRARY. There are comments about this being needed in Qt3
for Windows. The comment doesn't say if you need to explicitly link
against this or if it is done for you though.

So maybe you should try:
TARGET_LINK_LIBRARIES(qtwrapping myqtlib ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})


-Eric


More information about the CMake mailing list