0

我想运行需要提升库的代码。我使用 CMake 构建了它。其他人已经编写了此代码和 cmakelist。它需要与 boost 正则表达式、文件系统和系统库链接。

我下载了 boost 1.48 并构建了上面提到的 3 个库。现在我有 dll 和静态库(.a)。我运行了一个使用这些库的简单程序。它工作得很好。

现在在使用 CMake 时,它​​给出了与 boost 库相关的链接器错误。我检查了cmakelist,但我不明白要修改什么。cmakelist 的相关部分是:

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

我认为我只是在指定链接路径时犯了一个错误,但我无法找到如何更正它。

通过成功指定该程序和库的目标文件的路径,我成功地运行了一个与 boost_regex 的动态和静态库链接的简单示例程序。

现在在这段代码中,还有各种其他模块。它说 boost_regex 库丢失。link.txt 在那里说明要链接到哪些库,如下所示:

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

它成功链接到 opencv 库,但没有链接到 boost 库。我认为指定链接库的路径有误。我试图通过浏览所有 cmakelist 文件来查找指定此路径的位置。

如果有人想提供帮助,请先从 VOSM 下载代码。使用 CMake 构建它。从 boost 网站下载 boost 1.48 库。如果它有效,请告诉我你是如何做到的。

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

这是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 ()
4

1 回答 1

0

我建议使用find_package来查找所需的 Boost 库:

  • BOOST_ROOT环境变量设置为 Boost 根目录,即包含boost,和其余部分的环境变量,例如libs(全局或执行 CMake 时)stageC:\boost_1_48_0
  • 将以下内容添加到您的CMakeLists.txt

    find_package(Boost 1.48 COMPONENTS regex system filesystem REQUIRED)
    target_link_libraries(your_target ${Boost_LIBRARIES})
    include_directories(${Boost_INCLUDE_DIRS})
    
  • 如果您只需要静态库,请将Boost_USE_STATIC_LIBS变量设置为TRUE(在 find_package 之前!)

  • 如果您的 Boost 链接到静态 C++ 运行时,Boost_USE_STATIC_RUNTIME请将TRUE
于 2012-07-01T14:07:35.847 回答