cmake在编译ur_rtde时could not find boost

img

boost包已经安装编译过了(我也很奇怪虽然只经过了几分钟),有stage里面的lib文件了,但是cmake编译的时候就显示couldnot find,用VS编译也总是在230行报错,怎么解决呢?

我看到了一篇博客,也是这个问题,特别好
https://blog.csdn.net/qq_26565435/article/details/129040032

系统变量加了吗

Boost库的安装路径未正确配置:将其添加到系统的环境变量中。
CMake缓存未正确更新: 删除CMake生成的缓存文件,然后重新运行CMake来重新生成缓存。
CMake版本不兼容?
缺少CMake依赖项?

boost与动态库之间的软链接问题:
具体可以参考一下下面这两篇文章,大佬写的很细
1、https://blog.csdn.net/alien_y/article/details/127670345
2、
https://blog.csdn.net/lc315yuhuofei/article/details/117999481

在cmake生成的工程里面手动添加lib依赖就可以。

BOOST_LIBRARYDIR环境变量没有设置,看下这篇文章修改一下:https://blog.csdn.net/lc315yuhuofei/article/details/117999481。

确保你的boost路径版本库文件都配置正确
参考
https://www.cnblogs.com/tang-zhou-zhou/p/16067695.html

cmake时提示错误Could NOT find Boost: missing: python-py27 ,boost依赖库报错原因以及解决方法
可以参考这个例子

(windows系统)

在CMakeLists.txt中添加:

(改成自己的路径)

set(BOOST_ROOT "D:/local/boost_1_79_0")

set(BOOST_INCLUDEDIR "D:/local/boost_1_79_0/boost")

set(BOOTS_LIBRARYDIR "D:/local/boost_1_79_0/stage/lib")

可能还是会报错


继续在CMakeLists.txt中添加:

set(Boost_LIB_PREFIX "lib")

set(Boost_ARCHITECTURE "-x64")

然后成功:

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这篇博客: cmake-windows-boost中的 cmake中使用: 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    main.cpp

    //测试头文件库( Header-Only Libraries)
    #include <boost/lambda/lambda.hpp>  
    #include <iostream>  
    #include <iterator>  
    #include <algorithm>
    
    //测试库文件库(Boost Library Binary)
    #include <boost/regex.hpp>
    #include <string>
    int main()  
    {  
        using namespace boost::lambda;  
        typedef std::istream_iterator<int> in;  
        std::for_each(  
            in(std::cin), in(), std::cout << (_1 * 3) << " " ); 
    
        std::string line;
        boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
    
        while (std::cin)
        {
            std::getline(std::cin, line);
            boost::smatch matches;
            if (boost::regex_match(line, matches, pat))
                std::cout << matches[2] << std::endl;
        }
    }
    
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.0)
    
    set(PROJECT_NAME testboost)
    project(${PROJECT_NAME})
    
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
    
    file(GLOB_RECURSE HEADERS *.h)
    source_group("Header Files" FILES ${HEADERS})
    aux_source_directory(. DIR_SRCS)
    
    
    
    # 方法1: 显性设置boost的头文件与库文件目录, 发现此方法无效
    #set(BOOST_INCLUDEDIR "H:\\cpp\\boost_1_61_0\\boost_1_61_0")
    #set(BOOST_LIBRARYDIR "H:\\cpp\\boost_1_61_0\\boost_1_61_0\\stage\\lib")
    
    
    #方法2:隐性设置 猜测通过设置BOOST_ROOT, 可以让cmake-3.10/Modules/FindBoost.cmake找到Boost相关的变量
    #但是切记前提是 BOOST_ROOT符合目录结构规范
    # 实验发现 当目录结构是 "BOOST_ROOT/include/boost-1_65_1/boost"和"BOOST_ROOT/lib"时可以找到${Boost_INCLUDE_DIRS}和${Boost_LIBRARIES}
    # 如果目录结构是 "BOOST_ROOT/boost"和"BOOST_ROOT/stage/lib" 只能找到${Boost_INCLUDE_DIRS}
    set(BOOST_ROOT "H:\\cpp\\build_boost_1_65_0\\")
    
    SET(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_MULTITHREADED ON)  
    set(Boost_USE_STATIC_RUNTIME OFF)
    #set(BOOST_NO_SYSTEM_PATHS TRUE)
    
    #find_package(Boost 1.45.0 COMPONENTS *boost libraries here*)
    #find_package(Boost REQUIRED) # wrong, ${Boost_LIBRARIES} will be empty
    find_package(Boost REQUIRED COMPONENTS filesystem regex)
    if(Boost_FOUND)
        MESSAGE(STATUS "Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIRS}")
        MESSAGE(STATUS "Boost_LIBRARIES ${Boost_LIBRARIES}")
        include_directories(${Boost_INCLUDE_DIRS})
        add_executable(${PROJECT_NAME} ${DIR_SRCS} ${HEADERS})  
        target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
    endif()
    

    生成:

    cmake -G "Visual Studio 12 2013" ..

    打开*.sln,可以看到项目文件中已经配置好头文件与库文件


    vs编译

    cmake无法找到 boost

    情况1:

      Unable to find the Boost header files.  Please set BOOST_ROOT to the root
      directory containing Boost or BOOST_INCLUDEDIR to the directory containing
      Boost's headers.

    情况2:

      Could not find the following Boost libraries:
    
              boost_filesystem
              boost_regex
    
      Some (but not all) of the required Boost libraries were found.  You may
      need to install these additional Boost libraries.  Alternatively, set
      BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
      to the location of Boost.

    参考:

    http://www.boost.org/doc/libs/1_65_1/more/getting_started/windows.html

    其它可以借鉴的方案:

    set( BOOST_COMPONENTS_NEEDED serialization )
    
        # The following verifyies that BOOST_ROOT is set properly.
        if(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
            FILE( TO_CMAKE_PATH $ENV{BOOST_ROOT} BOOST_ROOT )
            if( NOT EXISTS ${BOOST_ROOT} ) 
                MESSAGE( STATUS  ${BOOST_ROOT} " does not exist. Checking if BOOST_ROOT was a quoted string.." )
                STRING( REPLACE "\"" "" BOOST_ROOT ${BOOST_ROOT} ) 
                if( EXISTS ${BOOST_ROOT} ) 
                    MESSAGE( STATUS "After removing the quotes " ${BOOST_ROOT} " was now found by CMake" )
                endif( EXISTS ${BOOST_ROOT})
            endif( NOT EXISTS ${BOOST_ROOT} )
    
        # Save the BOOST_ROOT in the cache
            if( NOT EXISTS ${BOOST_ROOT} ) 
                MESSAGE( WARNING ${BOOST_ROOT} " does not exist." )
            else(NOT EXISTS ${BOOST_ROOT})
                SET (BOOST_ROOT ${BOOST_ROOT} CACHE STRING "Set the value of BOOST_ROOT to point to the root folder of your boost install." FORCE)
                #SET (BOOST_INCLUDEDIR ${BOOST_ROOT}/Include)
                #SET (BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
            endif( NOT EXISTS ${BOOST_ROOT} )
    
        endif(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
    
        if( WIN32 AND NOT BOOST_ROOT )
            MESSAGE( WARNING "Please set the BOOST_ROOT environment variable." )
        endif( WIN32 AND NOT BOOST_ROOT )
    
        set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
        set(Boost_DEBUG ON)
        set(Boost_USE_STATIC_LIBS       OFF)
        set(Boost_USE_MULTITHREADED      ON)
        set(Boost_USE_STATIC_RUNTIME    OFF)
        FIND_PACKAGE(Boost 1.47.0 COMPONENTS ${BOOST_COMPONENTS_NEEDED})
        if(Boost_FOUND)
            MESSAGE( STATUS "Setting up boost." )
            include_directories(${Boost_INCLUDE_DIRS})
            if(Boost_DEBUG) 
                MESSAGE( STATUS "BOOST Libraries " ${Boost_LIBRARIES} )
                FOREACH(BOOST_COMPONENT ${BOOST_COMPONENTS_NEEDED})
                    STRING( TOUPPER ${BOOST_COMPONENT} BOOST_COMPONENT_UPCASE )
                    MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} ": " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY} )
                    MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Debug: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_DEBUG} )
                    MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Release: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_RELEASE} )
                ENDFOREACH(BOOST_COMPONENT)
            endif(Boost_DEBUG)
        endif(Boost_FOUND)

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

这是cmake找不到boost库产生的错误,解决办法是手动安装这个库:

sudo apt-get install libboost-all-dev
再次执行安装。应该可以解决你的问题哦。

重新安装一下boost库

boost库的安装有问题,重新安装一下试试