I want to run code which needs boost libraries. I built it using CMake. Someone else has written this code and cmakelist. It needs to be linked with boost regex, filesystem and system libraries.
I downloaded boost 1.48 and built the above mentioned 3 libraries. Now I have dll and static libraries(.a). I ran a simple program which used these libraries. It worked fine.
Now while using CMake, it gives a linker error relating to the boost libraries. I have checked the cmakelist, but I don’t understand what to modify. The relevant part of the cmakelist is:
set(WITH_BOOST_REGEX ON CACHE BOOL "Include BOOST REGEX support")
set(WITH_BOOST_FILESYSTEM ON CACHE BOOL "Include BOOST FILESYSTEM support")
set(WITH_BOOST_SYSTEM ON CACHE BOOL "Include BOOST SYSTEM support")
if(WITH_BOOST_REGEX)
CHECK_MODULE(libboost-regex HAVE_BOOST_REGEX)
else()
set(HAVE_BOOST_REGEX FALSE)
endif()
if(WITH_BOOST_FILESYSTEM)
CHECK_MODULE(libboost-filesystem HAVE_BOOST_FILESYSTEM)
else()
set(HAVE_BOOST_FILESYSTEM FALSE)
endif()
I think that I am just making an error in specifying the path for linking, but I am not able to find how to correct it.
I am successfully running a simple example program linking with both dynamic and static libraries of boost_regex by successfully specifying the path of the object file of that program and libraries.
Now in this code, there are various other modules. It says boost_regex library is missing. link.txt is there which says which libraries to link to, and which is like this:
/usr/bin/c++ CMakeFiles/test_ensembletraining.dir/ensembletraining.o -o ../../bin/test_ensembletraining -rdynamic ../../lib/libensembletraining.so.0.3.2 ../../lib/libutils.so.0.3.2 ../../lib/libfeatureextraction.so.0.3.2 ../../lib/libintegraltransform.so.0.3.2 -lboost_regex.so -lboost_filesystem -lboost_system.so -lopencv_core -lopencv_flann -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_objdetect -lopencv_features2d -lopencv_calib3d -lopencv_legacy -lopencv_contrib -Wl,-rpath,/home/rizwan/vosm-0.3.3/lib:
It successfully links with opencv libraries, but not with boost libraries. I think there is a mistake in specifying the path for link libraries. I tried to find where this path is specified by going through all the cmakelist files.
If anyone wants to help, first download code from VOSM. Build it using CMake. Download boost 1.48 libraries from the boost website. If it’s working then please tell me how you do that.
This is part of the cmakecachelist:
//Include BOOST FILESYSTEM support
WITH_BOOST_FILESYSTEM:BOOL=ON
//Include BOOST REGEX support
WITH_BOOST_REGEX:BOOL=ON
//Include BOOST SYSTEM support
WITH_BOOST_SYSTEM:BOOL=ON
//Include OPENCV 2.x support
WITH_OPENCV:BOOL=ON
here is cmakelist..
if (BUILD_EXAMPLES)
project(ensembletraining_exe)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
endif()
include_directories(
"${CMAKE_SOURCE_DIR}/modules/ensembletraining/include"
"${CMAKE_SOURCE_DIR}/modules/common/include"
"${CMAKE_SOURCE_DIR}/modules/featureextraction/include"
)
# ---------------------------------------------
# Define executable targets
# ---------------------------------------------
MACRO(VO_DEFINE_EXAMPLE name srcs)
set(the_target "test_${name}")
add_executable(${the_target} ${srcs})
set_target_properties(${the_target} PROPERTIES
OUTPUT_NAME "test_${name}"
PROJECT_LABEL "(EXAMPLE) test_${name}")
add_dependencies(${the_target} ensembletraining
opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib)
target_link_libraries(${the_target} ${VOSM_LINKER_LIBS} ensembletraining utils featureextraction integraltransform
boost_regex boost_filesystem boost_system opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib)
if(WIN32)
install(TARGETS ${the_target}
RUNTIME DESTINATION "tests" COMPONENT main)
endif()
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
ENDMACRO(VO_DEFINE_EXAMPLE)
file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c)
foreach(sample_filename ${cpp_samples})
get_filename_component(sample ${sample_filename} NAME_WE)
VO_DEFINE_EXAMPLE(${sample} ${sample_filename})
endforeach()
endif(BUILD_EXAMPLES)
if (INSTALL_C_EXAMPLES AND NOT WIN32)
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
install(FILES ${C_SAMPLES}
DESTINATION share/vosm/tests
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
endif ()
I’d recommend using
find_packageto find required Boost libraries:BOOST_ROOTenvironment variable to the Boost root directory, i.e. the one that containsboost,libs,stageand the rest, e.g.C:\boost_1_48_0(either globally or when executing CMake)add the following to your
CMakeLists.txt:if you need only static libraries, set the
Boost_USE_STATIC_LIBSvariable toTRUE(before find_package!)Boost_USE_STATIC_RUNTIMEtoTRUE