正在尝试将Boost库添加到Cmake.txt(Clion Ide)
我看到很多问题与此类似,但不尽相同 我在使用Clion的Cmake中识别boost/工作时遇到了一个问题。我尝试了几种方法,包括Clion附带的incboost模板,然后继续 Cmake版本3.4 Boost版本1.60.0正在尝试将Boost库添加到Cmake.txt(Clion Ide),boost,cmake,Boost,Cmake,我看到很多问题与此类似,但不尽相同 我在使用Clion的Cmake中识别boost/工作时遇到了一个问题。我尝试了几种方法,包括Clion附带的incboost模板,然后继续 Cmake版本3.4 Boost版本1.60.0 find_package(Boost) if (Boost_FOUND) include_directories(${Boost_INCLUDE_DIR}) endif() 这是我上面提到的自动生成的incboost,不会产生任何结果 第二次尝试如下 set(Bo
find_package(Boost)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
这是我上面提到的自动生成的incboost,不会产生任何结果
第二次尝试如下
set(Boost_Dir "C:\\Program Files (x86)\\boost_1_60_0\\")
find_package(Boost 1.60.0 COMPONENTS filesystem)
include_directories(${Boost_Dir})
CmakeFiles\Svp.dir/objects.a(main.cpp.obj):
In function`_static_initialization_and_destruction_0':
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:221: undefined reference
to `boost::system::generic_category()'
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:222: undefined
reference to `boost::system::generic_category()'
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:223: undefined
reference to `boost::system::system_category()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Svp.exe] Error 1
CMakeFiles\Svp.dir\build.make:96: recipe for target 'Svp.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Svp.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Svp.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2
Makefile:117: recipe for target 'Svp' failed
mingw32-make.exe: *** [Svp] Error 2
我的第三次尝试产生了这种效果
set(boost "C:\\Program Files (x86)\\boost_1_60_0\\boost\\")
INCLUDE_DIRECTORIES(${boost})
fatal error: boost/filesystem/config.hpp: No such file or directory
# include <boost/filesystem/config.hpp>
^
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles/Svp.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2
set(boost“C:\\Program Files(x86)\\boost\u 1\u 60\u 0\\boost\”)
包含目录(${boost})
致命错误:boost/filesystem/config.hpp:没有这样的文件或目录
#包括
^
编译终止。
mingw32 make.exe[3]:***[CMakeFiles/Svp.dir/main.cpp.obj]错误1
mingw32 make.exe[2]:***[CMakeFiles/Svp.dir/all]错误2
mingw32 make.exe[1]:***[CMakeFiles/Svp.dir/rule]错误2
最后,这里给出的解决方案没有改变我的错误输出。以下是我如何在项目中以可移植的方式使用它:
if (WIN32)
set(BOOST_ROOT "C:/Program Files (x86)/boost_1_60_0/")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREAD ON)
include_directories(${BOOST_ROOT})
link_directories(${BOOST_ROOT}/stage/lib) # add this before add_executable()
endif()
# Here call your add_executable method
# add_executable(TARGET_NAME ... )
if(NOT MSVC)
find_package(Boost REQUIRED COMPONENTS date_time filesystem wserialization system serialization thread regex)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(TARGET_NAME ${Boost_LIBRARIES})
endif()
endif()
有时需要指定Boost\u USE\u STATIC\u LIBS
和Boost\u USE\u multi-thread
变量来帮助查找包查找Boost
另外,请使用设置指定boost库的正确路径(boost\u ROOT,$path)
。此外,在find_包中指定所需的boost包。比如说
find_包(Boost所需组件日期时间文件系统线程regex)
如果您只需要日期\u时间
文件系统
线程
正则表达式
包
让我知道它是否适用于您。另外,让我澄清一下,我在其他使用不同编译器的项目中使用过我的boost设置,它工作得很好,因此我知道它在Cmake.txt中的位置存在问题。您希望使用什么编译器?现在只使用g++看起来您正在使用mingw,我的答案对你来说应该是有效的。是的,很抱歉我刚刚把它拿起来测试:)谢谢你的帮助!