Solved FreeBSD and CMake: compilation is fine but end up with linking errors.

System info:

Code:
uname -a
FreeBSD vm-freebsd 10.2-RELEASE-p7 FreeBSD 10.2-RELEASE-p7 #0: Mon Nov  2 14:19:39 UTC 2015  root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64

Code:
% cmake --version
cmake version 3.4.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Description:

This is a C++ program, and it is developed with Debian. Now, I hope I can run it with FreeBSD, the problem is I can compile but it finally end up with linking errors:

Code:
/home/fender/pj/project/src/main.cpp:17: undefined reference to `boost::program_options::eek:ptions_description::eek:ptions_description(std::string const&, unsigned int, unsigned int)'
/home/fender/pj/project/src/main.cpp:37: undefined reference to `boost::program_options::eek:perator<<(std::eek:stream&, boost::program_options::eek:ptions_description const&)'
/home/fender/pj/project/src/main.cpp:68: undefined reference to `boost::program_options::eek:perator<<(std::eek:stream&, boost::program_options::eek:ptions_description const&)'

Here is a part from the cmake(1) config file, I think it is fine, because I can compile and link the code on Debian.

The CMAKE_SYSTEM_LIBRARY_PATH variable was checked, and it looks fine. So, I have no idea.

Code:
add_executable(${target} ${source_file_list})


find_library(boost_program_options libboost_program_options.so)
find_library(boost_system  libboost_system.so)
find_library(boost_regex  libboost_regex.so)
find_library(boost_date_time  libboost_date_time.so)
find_library(pqxx  libpqxx.so)

target_link_libraries(${target} ${boost_program_options})
target_link_libraries(${target} ${boost_system})
target_link_libraries(${target} ${boost_regex})
target_link_libraries(${target} ${boost_date_time})
target_link_libraries(${target} ${pqxx})

#target           is the binary file name
#source_file_list is the source file list
Debian use gnu make, but FreeBSD provide a different make, it that matters?
 
The boost lib was installed.
Code:
cd /usr/local/lib
ls | grep -i boost
libboost_atomic.a
libboost_atomic.so
libboost_atomic.so.1.55.0
libboost_atomic.so.5
libboost_chrono.a
libboost_chrono.so
libboost_chrono.so.1.55.0
libboost_chrono.so.5
libboost_context.a
libboost_context.so
libboost_context.so.1.55.0
libboost_context.so.5
libboost_coroutine.a
libboost_coroutine.so
libboost_coroutine.so.1.55.0
libboost_coroutine.so.5
libboost_date_time.a
libboost_date_time.so
libboost_date_time.so.1.55.0
libboost_date_time.so.5
libboost_exception.a
libboost_filesystem.a
libboost_filesystem.so
libboost_filesystem.so.1.55.0
libboost_filesystem.so.5
libboost_graph.a
libboost_graph.so
libboost_graph.so.1.55.0
libboost_graph.so.5
libboost_iostreams.a
libboost_iostreams.so
libboost_iostreams.so.1.55.0
libboost_iostreams.so.5
libboost_locale.a
libboost_locale.so
libboost_locale.so.1.55.0
libboost_locale.so.5
libboost_log.a
libboost_log.so
libboost_log.so.1.55.0
libboost_log.so.5
libboost_log_setup.a
libboost_log_setup.so
libboost_log_setup.so.1.55.0
libboost_log_setup.so.5
libboost_math_c99.a
libboost_math_c99.so
libboost_math_c99.so.1.55.0
libboost_math_c99.so.5
libboost_math_c99f.a
libboost_math_c99f.so
libboost_math_c99f.so.1.55.0
libboost_math_c99f.so.5
libboost_math_tr1.a
libboost_math_tr1.so
libboost_math_tr1.so.1.55.0
libboost_math_tr1.so.5
libboost_math_tr1f.a
libboost_math_tr1f.so
libboost_math_tr1f.so.1.55.0
libboost_math_tr1f.so.5
libboost_prg_exec_monitor.a
libboost_prg_exec_monitor.so
libboost_prg_exec_monitor.so.1.55.0
libboost_prg_exec_monitor.so.5
libboost_program_options.a
libboost_program_options.so
libboost_program_options.so.1.55.0
libboost_program_options.so.5
libboost_random.a
libboost_random.so
libboost_random.so.1.55.0
libboost_random.so.5
libboost_regex.a
libboost_regex.so
libboost_regex.so.1.55.0
libboost_regex.so.5
libboost_serialization.a
libboost_serialization.so
libboost_serialization.so.1.55.0
libboost_serialization.so.5
libboost_signals.a
libboost_signals.so
libboost_signals.so.1.55.0
libboost_signals.so.5
libboost_system.a
libboost_system.so
libboost_system.so.1.55.0
libboost_system.so.5
libboost_test_exec_monitor.a
libboost_thread.a
libboost_thread.so
libboost_thread.so.1.55.0
libboost_thread.so.5
libboost_timer.a
libboost_timer.so
libboost_timer.so.1.55.0
libboost_timer.so.5
libboost_unit_test_framework.a
libboost_unit_test_framework.so
libboost_unit_test_framework.so.1.55.0
libboost_unit_test_framework.so.5
libboost_wave.a
libboost_wave.so
libboost_wave.so.1.55.0
libboost_wave.so.5
libboost_wserialization.a
libboost_wserialization.so
libboost_wserialization.so.1.55.0
libboost_wserialization.so.5
 
I put the following lines into the cmake config file:
Code:
message(${boost_program_options})
message(${boost_system})
message(${boost_regex})
When I run cmake -Wno-dev ../project in the build dir, cmake shows:
Code:
/usr/local/lib/libboost_program_options.so
/usr/local/lib/libboost_system.so
/usr/local/lib/libboost_regex.so
So, the libs are fine and cmake can find them correctly.
 
Back
Top