[CMake] cmake linking problem

Anders Sandholm anders.sandholm at gmail.com
Fri Jul 13 07:26:55 EDT 2007


Hi

Using Cmake (vtk) with QT and trying to build using visual studio
2005. Now I have compiled both vtk and QT with visual studio 2005, and
simple QT applications (like hello world workes perfekt) but now I try
to do some a little more advanced and I get a linking problem.
The source code that I try to compile is the Sliders Example
(http://doc.trolltech.com/4.0/widgets-sliders.html)
(the HelloWorld example I can compile with cmake)

Now I am new to CMake, but the CMake file I am using look like:


------------------------------------------------------------------------------------------------

PROJECT (Test)

FIND_PACKAGE(VTK REQUIRED)
find_package(Qt4 REQUIRED)

IF(NOT VTK_USE_RENDERING)
  MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")
ENDIF(NOT VTK_USE_RENDERING)

INCLUDE(${VTK_USE_FILE})
include(${QT_USE_FILE})

# the next line sets up include and link directories and defines some
variables that we will use.
# you can modify the behavior by setting some variables, e.g.
#   set(QT_USE_OPENGL TRUE)
# -> this will cause cmake to include and link against the OpenGL module
include(${QT_USE_FILE})

# the variable "qtproject_SRCS" contains all .cpp files of this project
set(qtproject_SRCS
main.cpp
window.h
window.cpp
slidersgroup.h
slidersgroup.cpp
)

INCLUDE_DIRECTORIES(qtproject_SRCS
   ${QT_INCLUDE_DIR}
   ${QT_QTNETWORK_INCLUDE_DIR}
   ${QT_QTTEST_INCLUDE_DIR}
)

link_directories(qtproject_srcs
   ${QT_LIBRARIES}
   ${QT_QTNETWORK_LIBRARIES}
   ${QT_QTTEST_LIBRARIES}

)


# tell cmake to create .moc files for all files in the variable
qtproject_SRCS that require such a file.
# note: this assumes that you use #include "header.moc" in your files
qt4_automoc(${qtproject_SRCS})

# create an executable file named "qtproject" from the source files in
the variable "qtproject_SRCS".
add_executable(qtproject ${qtproject_SRCS})

TARGET_LINK_LIBRARIES(qtproject
   ${QT_LIBRARIES}
   ${QT_QTNETWORK_LIBRARIES}
   ${QT_QTTEST_LIBRARIES}
)

------------------------------------------------------------------------------------------------

Now when I build in vs2005 it says:

------------------------------------------------------------------------------------------------

1>------ Build started: Project: qtproject, Configuration: Release Win32 ------
1>Linking...
1>window.obj : error LNK2019: unresolved external symbol "public:
static struct QMetaObject const Window::staticMetaObject"
(?staticMetaObject at Window@@2UQMetaObject@@B) referenced in function
"public: static class QString __cdecl Window::tr(char const *,char
const *)" (?tr at Window@@SA?AVQString@@PBD0 at Z)
1>window.obj : error LNK2001: unresolved external symbol "public:
virtual struct QMetaObject const * __thiscall
Window::metaObject(void)const "
(?metaObject at Window@@UBEPBUQMetaObject@@XZ)
1>window.obj : error LNK2001: unresolved external symbol "public:
virtual void * __thiscall Window::qt_metacast(char const *)"
(?qt_metacast at Window@@UAEPAXPBD at Z)
1>window.obj : error LNK2001: unresolved external symbol "public:
virtual int __thiscall Window::qt_metacall(enum
QMetaObject::Call,int,void * *)"
(?qt_metacall at Window@@UAEHW4Call at QMetaObject@@HPAPAX at Z)
1>slidersgroup.obj : error LNK2001: unresolved external symbol
"public: virtual struct QMetaObject const * __thiscall
SlidersGroup::metaObject(void)const "
(?metaObject at SlidersGroup@@UBEPBUQMetaObject@@XZ)
1>slidersgroup.obj : error LNK2001: unresolved external symbol
"public: virtual void * __thiscall SlidersGroup::qt_metacast(char
const *)" (?qt_metacast at SlidersGroup@@UAEPAXPBD at Z)
1>slidersgroup.obj : error LNK2001: unresolved external symbol
"public: virtual int __thiscall SlidersGroup::qt_metacall(enum
QMetaObject::Call,int,void * *)"
(?qt_metacall at SlidersGroup@@UAEHW4Call at QMetaObject@@HPAPAX at Z)
1>Release\qtproject.exe : fatal error LNK1120: 7 unresolved externals
1>Build log was saved at "file://z:\temp2\qtproject.dir\Release\BuildLog.htm"
1>qtproject - 8 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

------------------------------------------------------------------------------------------------

The BuildLog.htm says

------------------------------------------------------------------------------------------------

Build Log      Build started: Project: qtproject, Configuration: Release|Win32
 Command Lines      Creating temporary file
"z:\temp2\qtproject.dir\Release\RSP00000136204020.rsp" with contents
[
/OUT:"Release\qtproject.exe" /VERSION:0.0 /INCREMENTAL:NO
/LIBPATH:"c:\vtkBin\bin\Release" /LIBPATH:"c:\vtkBin\bin"
/LIBPATH:"qtproject_srcs\Release" /LIBPATH:"qtproject_srcs"
/LIBPATH:"optimized\Release" /LIBPATH:"optimized"
/LIBPATH:"c:\QT\lib\QtGui4.lib\Release"
/LIBPATH:"c:\QT\lib\QtGui4.lib" /LIBPATH:"debug\Release"
/LIBPATH:"debug" /LIBPATH:"c:\QT\lib\QtGuid4.lib\Release"
/LIBPATH:"c:\QT\lib\QtGuid4.lib" /LIBPATH:"Imm32\Release"
/LIBPATH:"Imm32" /LIBPATH:"Winmm\Release" /LIBPATH:"Winmm"
/LIBPATH:"c:\QT\lib\QtCore4.lib\Release"
/LIBPATH:"c:\QT\lib\QtCore4.lib"
/LIBPATH:"c:\QT\lib\QtCored4.lib\Release"
/LIBPATH:"c:\QT\lib\QtCored4.lib" /LIBPATH:"Ws2_32\Release"
/LIBPATH:"Ws2_32" /LIBPATH:"c:\QT\lib\QtNetwork4.lib\Release"
/LIBPATH:"c:\QT\lib\QtNetwork4.lib"
/LIBPATH:"c:\QT\lib\QtNetworkd4.lib\Release"
/LIBPATH:"c:\QT\lib\QtNetworkd4.lib"
/LIBPATH:"c:\QT\lib\QtTest4.lib\Release"
/LIBPATH:"c:\QT\lib\QtTest4.lib"
/LIBPATH:"c:\QT\lib\QtTestd4.lib\Release"
/LIBPATH:"c:\QT\lib\QtTestd4.lib" /LIBPATH:"c:\QT\lib\Release"
/LIBPATH:"c:\QT\lib" /MANIFEST
/MANIFESTFILE:"qtproject.dir\Release\qtproject.exe.intermediate.manifest"
/PDB:"Release\qtproject.pdb" /SUBSYSTEM:CONSOLE /STACK:10000000
/STACK:10000000 /machine:I386   kernel32.lib user32.lib gdi32.lib
winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib
advapi32.lib  QtGui4.lib Imm32.lib Winmm.lib QtCore4.lib Ws2_32.lib
QtNetwork4.lib QtTest4.lib

".\qtproject.dir\Release\main.obj"

".\qtproject.dir\Release\window.obj"

".\qtproject.dir\Release\slidersgroup.obj"
]
Creating command line "link.exe
@z:\temp2\qtproject.dir\Release\RSP00000136204020.rsp /NOLOGO
/ERRORREPORT:PROMPT"
 Output Window      Linking...
window.obj : error LNK2019: unresolved external symbol "public: static
struct QMetaObject const Window::staticMetaObject"
(?staticMetaObject at Window@@2UQMetaObject@@B) referenced in function
"public: static class QString __cdecl Window::tr(char const *,char
const *)" (?tr at Window@@SA?AVQString@@PBD0 at Z)
window.obj : error LNK2001: unresolved external symbol "public:
virtual struct QMetaObject const * __thiscall
Window::metaObject(void)const "
(?metaObject at Window@@UBEPBUQMetaObject@@XZ)
window.obj : error LNK2001: unresolved external symbol "public:
virtual void * __thiscall Window::qt_metacast(char const *)"
(?qt_metacast at Window@@UAEPAXPBD at Z)
window.obj : error LNK2001: unresolved external symbol "public:
virtual int __thiscall Window::qt_metacall(enum
QMetaObject::Call,int,void * *)"
(?qt_metacall at Window@@UAEHW4Call at QMetaObject@@HPAPAX at Z)
slidersgroup.obj : error LNK2001: unresolved external symbol "public:
virtual struct QMetaObject const * __thiscall
SlidersGroup::metaObject(void)const "
(?metaObject at SlidersGroup@@UBEPBUQMetaObject@@XZ)
slidersgroup.obj : error LNK2001: unresolved external symbol "public:
virtual void * __thiscall SlidersGroup::qt_metacast(char const *)"
(?qt_metacast at SlidersGroup@@UAEPAXPBD at Z)
slidersgroup.obj : error LNK2001: unresolved external symbol "public:
virtual int __thiscall SlidersGroup::qt_metacall(enum
QMetaObject::Call,int,void * *)"
(?qt_metacall at SlidersGroup@@UAEHW4Call at QMetaObject@@HPAPAX at Z)
Release\qtproject.exe : fatal error LNK1120: 7 unresolved externals
 Results      Build log was saved at
"file://z:\temp2\qtproject.dir\Release\BuildLog.htm"
qtproject - 8 error(s), 0 warning(s)

------------------------------------------------------------------------------------------------

Anybody that knows what I am doing wrong?

Regards
// anders


More information about the CMake mailing list