public
Created

CMake static linker issue

  • Download Gist
CMakeLists.txt
CMake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
project(foo)
 
SET(CMAKE_EXE_LINKER_FLAGS -static)
 
# add ZeroMQ library
add_library(imp_zeromq STATIC IMPORTED)
set_property(TARGET imp_zeromq PROPERTY
IMPORTED_LOCATION $ENV{ZEROMQ_HOME}/libzmq.a)
 
# add C bindings for ZeroMQ library
add_library(imp_zeromq STATIC IMPORTED)
set_property(TARGET imp_czmq PROPERTY
IMPORTED_LOCATION $ENV{CZMQ_HOME}/libczmq.a)
 
add_library(Config ./Config/Config.c ./Config.minIni.c)
 
add_library(Comm ./Comm/Comm.c)
 
add_executable(Runtime Runtime.cpp)
target_link_libraries(Runtime imp_zeromq imp_czmq ${CMAKE_THREAD_LIBS_INIT} rt Comm Config)
Make output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
------------- Failure on Ubuntu 12.04 ----------------
 
make -f src/CMakeFiles/Runtime.dir/build.make src/CMakeFiles/Runtime.dir/depend
make[2]: Entering directory `/home/davis/git/firmware/build'
cd /home/davis/git/firmware/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" \
/home/davis/git/firmware /home/davis/git/firmware/src /home/davis/git/firmware/build \
/home/davis/git/firmware/build/src /home/davis/git/firmware/build/src/CMakeFiles/Runtime.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/davis/git/firmware/build'
make -f src/CMakeFiles/Runtime.dir/build.make src/CMakeFiles/Runtime.dir/build
make[2]: Entering directory `/home/davis/git/firmware/build'
Linking CXX executable ../bin/Runtime
cd /home/davis/git/firmware/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/Runtime.dir/link.txt --verbose=1
/usr/bin/c++ -static CMakeFiles/Runtime.dir/Runtime.cpp.o -o ../bin/Runtime \
-rdynamic /usr/local/lib/libzmq.a /usr/local/lib/libczmq.a -lpthread -lrt ../lib/libComm.a ../lib/libConfig.a
../lib/libComm.a(Comm.c.o): In function `Comm_Create':
Comm.c:(.text+0x42): undefined reference to `zctx_new'
Comm.c:(.text+0x5c): undefined reference to `zsocket_new'
collect2: ld returned 1 exit status
make[2]: *** [bin/Runtime] Error 1
make[2]: Leaving directory `/home/davis/git/firmware/build'
make[1]: *** [src/CMakeFiles/Runtime.dir/all] Error 2
make[1]: Leaving directory `/home/davis/git/firmware/build'
make: *** [all] Error 2
 
------------ Success on Mac OS X ------------------
 
make -f src/CMakeFiles/Runtime.dir/build.make src/CMakeFiles/Runtime.dir/depend
cd /Users/davis/git/firmware/build && /usr/local/Cellar/cmake/2.8.9/bin/cmake -E cmake_depends "Unix Makefiles" \
/Users/davis/git/firmware /Users/davis/git/firmware/src /Users/davis/git/firmware/build /Users/davis/git/firmware/build/src \
/Users/davis/git/firmware/build/src/CMakeFiles/Runtime.dir/DependInfo.cmake --color=
make -f src/CMakeFiles/Runtime.dir/build.make src/CMakeFiles/Runtime.dir/build
/usr/local/Cellar/cmake/2.8.9/bin/cmake -E cmake_progress_report /Users/davis/git/firmware/build/CMakeFiles 7
[ 50%] Building CXX object src/CMakeFiles/Runtime.dir/Runtime.cpp.o
cd /Users/davis/git/firmware/build/src && /usr/bin/c++ -I/Users/davis/git/firmware/src/../include \
-I/Users/davis/git/firmware/src/../include/LedDriver -I/usr/local/Cellar/msgpack/0.5.7/include \
-o CMakeFiles/Runtime.dir/Runtime.cpp.o -c /Users/davis/git/firmware/src/Runtime.cpp
Linking CXX executable ../bin/Runtime
cd /Users/davis/git/firmware/build/src && /usr/local/Cellar/cmake/2.8.9/bin/cmake -E cmake_link_script CMakeFiles/Runtime.dir/link.txt --verbose=1
/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/Runtime.dir/Runtime.cpp.o -o ../bin/Runtime \
-L/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/x86_64 \
-L/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/x86_64 \
-L/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1 \
-L/usr/llvm-gcc-4.2/lib/gcc \
-L/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1 \
-L/usr/llvm-gcc-4.2/lib -L/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib \
../lib/libComm.a ../lib/libConfig.a /usr/local/lib/libzmq.a /usr/local/lib/libczmq.a
/usr/local/Cellar/cmake/2.8.9/bin/cmake -E cmake_progress_report /Users/davis/git/firmware/build/CMakeFiles 7
[ 50%] Built target Runtime

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.