有我的CMakeList.txt:
cmake_minimum_required( VERSION 2.6 )
project( FlamingSkull )
find_package(OpenThreads)
find_package(osg)
find_package(osgDB)
find_package(osgUtil)
find_package(osgViewer)
find_package(osgText)
find_package(X11)
macro( config_project PROJNAME LIBNAME )
include_directories( ${${LIBNAME}_INCLUDE_DIR} )
target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARY} )
endmacro()
add_executable(FlamingSkull main.cc)
config_project(FlamingSkull OPENTHREADS)
config_project(FlamingSkull OSG)
config_project(FlamingSkull OSGTEXT)
config_project(FlamingSkull OSGDB)
config_project(FlamingSkull OSGUTIL)
config_project(FlamingSkull OSGVIEWER)
config_project(FlamingSkull X11)
(这是我从头开始编写的第一个CMakeList.txt ...)
然后在控制台中输入cmake .
并获取:
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found OpenThreads: /usr/lib/libOpenThreads.so
-- Found osg: /usr/lib/libosg.so
-- Found osgDB: /usr/lib/libosgDB.so
-- Found osgUtil: /usr/lib/libosgUtil.so
-- Found osgViewer: /usr/lib/libosgViewer.so
-- Found osgText: /usr/lib/libosgText.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/libX11.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/theGraveyard
对我来说一切都很好,但是当我输入make
时,我得到:
Linking CXX executable FlamingSkull
/usr/bin/ld: CMakeFiles/FlamingSkull.dir/main.cc.o: undefined reference to symbol 'XCreateColormap'
/usr/bin/ld: note: 'XCreateColormap' is defined in DSO /usr/lib/libX11.so.6 so try adding it to the linker command line
/usr/lib/libX11.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make[2]: *** [FlamingSkull] Error 1
make[1]: *** [CMakeFiles/FlamingSkull.dir/all] Error 2
make: *** [all] Error 2
如果我使用像g++ ... -lX11
这样的命令,我就不会遇到麻烦。
我想知道人们如何找到要传递给find_package()
的“包”的变量名称,我想这是区分大小写的......
答案 0 :(得分:3)
config_project宏使用了错误的变量。您不应该链接到作为查找模块的内部值的* _LIBRARY,而应该使用* _LIBRARIES。所以这是固定代码:
macro( config_project PROJNAME LIBNAME )
include_directories( ${${LIBNAME}_INCLUDE_DIR} )
target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARIES} )
endmacro()
答案 1 :(得分:1)
好吧,首先你可以添加
set (CMAKE_VERBOSE_MAKEFILE ON)
到您的CMakeLists.txt,您将看到哪个命令失败。
现在,通过简要查看错误消息,它似乎与要传递给链接器的库的顺序有关。更多细节在这里: