有我的 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()
“包”的变量的名称是什么,我想它区分大小写......