[CMake] Debug build compiles and links, but Release build fails to link?

Jean-Sébastien Guay jean-sebastien.guay at polymtl.ca
Wed Mar 14 18:50:25 EST 2007


Hello,

I am new to CMake, and I imagine this must be caused by a newbie error  
in the CMakeLists.txt files I'm using... My project compiles and links  
fine in Debug, but in Release, it fails to link. The error I get is:


[ ..... snipped for brevity, only keeping errors ..... ]
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Raytracing/bin/libRaytracing.a(BlinnShadingModel.o): In function `BlinnShadingModel::shade(Ray const&, ws::sg::Geode const*, osg::Vec3f const&, osg::Vec3f const&, osg::Vec3f const&, unsigned  
int)':
BlinnShadingModel.cpp:(.text+0x3c4): undefined reference to  
`General::greaterThan(float, float)'
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Raytracing/bin/libRaytracing.a(Intersector.o): In function  
`Intersector::ShapeNormalVisitor::apply(osg::Sphere&)':
Intersector.cpp:(.text+0x46d): undefined reference to  
`General::greaterThan(float, float)'
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/SceneGraph/bin/libSceneGraph.a(SceneBruteForce.o): In function  
`ws::sg::SceneBruteForce::IntersectionVisitor::apply(osg::Geode&)':
SceneBruteForce.cpp:(.text+0x902): undefined reference to  
`General::lessThan(float, float)'
collect2: ld returned 1 exit status
make[2]: *** [src/Core/bin/ws] Error 1
make[2]: Leaving directory  
`/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release'
make[1]: *** [src/Core/CMakeFiles/ws.dir/all] Error 2
make[1]: Leaving directory  
`/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release'
make: *** [all] Error 2


The link command (gotten using VERBOSE=1 make) is:


cd /home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Core  
&& /usr/bin/c++     -O3 -DNDEBUG  -fPIC "CMakeFiles/ws.dir/Main.o"    
-o bin/ws -rdynamic -L/home/guayj/local_apps/OpenSceneGraph/lib  
-L/home/guayj/local_apps/OpenThreads/lib  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/General/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Image/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Raytracing/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Realtime/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/SceneGraph/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Util/bin  
-lOpenThreads -losg -losgDB -losgGA -losgViewer -lSDL -Wl,-Bstatic  
-lGeneral -lImage -lRaytracing -lRealtime -lSceneGraph -lUtil  
-Wl,-Bdynamic -Wl,-rpath,/home/guayj/local_apps/OpenSceneGraph/lib:
/home/guayj/local_apps/OpenThreads/lib:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/General/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Image/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Raytracing/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Realtime/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/SceneGraph/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Release/src/Util/bin


(I added line breaks after the colons in the -Wl,-rpath,[...] part  
otherwise it would be one very long line)

Now, the symbols it says it cannot find in the link phase are in  
-lGeneral, which is supposedly found (at least I don't get a message  
stating otherwise). Also, since the build links fine in Debug, using  
the same CMakeLists.txt and the same external libs, I'm not sure why  
in Release it wouldn't link correctly.

Is there any way I can get to the source of the problem? VERBOSE=1  
doesn't seem to be helping (well, at least it helps me post a detailed  
problem report).

If it's any help, here's the link command for the Debug build (which links):


cd /home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Core &&  
/usr/bin/c++     -g  -fPIC "CMakeFiles/ws.dir/Main.o"   -o bin/ws  
-rdynamic -L/home/guayj/local_apps/OpenSceneGraph/lib  
-L/home/guayj/local_apps/OpenThreads/lib  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/General/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Image/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Raytracing/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Realtime/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/SceneGraph/bin  
-L/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Util/bin  
-lOpenThreads -losg -losgDB -losgGA -losgViewer -lSDL -Wl,-Bstatic  
-lGeneral -lImage -lRaytracing -lRealtime -lSceneGraph -lUtil  
-Wl,-Bdynamic -Wl,-rpath,/home/guayj/local_apps/OpenSceneGraph/lib:
/home/guayj/local_apps/OpenThreads/lib:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/General/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Image/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Raytracing/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Realtime/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/SceneGraph/bin:
/home/guayj/Cours/Recherche/Projets/WhiteStar/bin/Debug/src/Util/bin


I personally can't spot a major difference between the two (aside from  
-g replaced by -O3 and NDEBUG being defined, which shouldn't prevent  
it from linking).

My CMakeLists.txt files are pretty simple, here's an example (the one  
that builds the executable after all the static libs are built):


SET(CORE_SRCS Main.cpp)
INCLUDE_DIRECTORIES($ENV{OSG_INCLUDE_PATH} $ENV{OPENTHREADS_INC_DIR}
                     ../../third_party//tclap-1.1.0/include/)
LINK_DIRECTORIES($ENV{OSG_LIB_PATH} $ENV{OPENTHREADS_LIB_DIR})
LINK_LIBRARIES(OpenThreads osg osgDB osgGA osgViewer SDL General Image  
Raytracing Realtime SceneGraph Util)
ADD_EXECUTABLE(ws ${CORE_SRCS})


And an example of one of those that builds a static lib:


SET(RAYTRACING_SRCS BlinnShadingModel.cpp Intersector.cpp Ray.cpp
                     RayResult.cpp Raytracer.cpp  
ReflectionShadingDecorator.cpp)
INCLUDE_DIRECTORIES($ENV{OSG_INCLUDE_PATH} $ENV{OPENTHREADS_INC_DIR})
ADD_LIBRARY(Raytracing STATIC ${RAYTRACING_SRCS})


Pretty basic, I guess. And just to reiterate, this all works in Debug,  
just not in Release (with the results stated above).

Any help would be appreciated. Thanks in advance,

J-S
-- 
______________________________________________________
Jean-Sebastien Guay     jean-sebastien.guay at polymtl.ca
                         http://whitestar02.webhop.org/

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the CMake mailing list