The Unholy Metal Machine
The Unholy Metal Machine

Reputation: 1103

what's going wrong with my CMakeList.txt?

there is my 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)

(this is my first CMakeList.txt written from scratch...)

then in the console I type cmake . and get :

-- 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

for me everything looks fine, but when I type make, I get :

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

If I use a command like g++ ... -lX11 I don't get trouble. I wonder how people do to find what is the name of the variable to pass to find_package() for a "package", I guess it's case sensitive...

Upvotes: 0

Views: 812

Answers (2)

RobertJMaynard
RobertJMaynard

Reputation: 2257

The config_project macro is using the wrong variable. You shouldn't link to *_LIBRARY that is an internal value for the find module, instead you should use *_LIBRARIES. So here is the fixed code:

macro( config_project PROJNAME LIBNAME )
include_directories( ${${LIBNAME}_INCLUDE_DIR} )
target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARIES} )
endmacro()

Upvotes: 3

Artem Shinkarov
Artem Shinkarov

Reputation: 379

Well, first of all you can add

set (CMAKE_VERBOSE_MAKEFILE ON)

to your CMakeLists.txt and you'll see which exactly command is failing.

Now, from the brief look over the error message it seems that it has something to do wit the order of the libraries that are being passed to the linker. More details here:

Problem description

Upvotes: 1

Related Questions