在CLion窗口中设置Boost 1.62

时间:2016-10-11 07:29:06

标签: c++ boost clion

我过去两天一直试图在克里昂设置1.62提升。我已经看到几乎所有的堆栈问题,但仍然无法做到。

我的CMakeList.txt如下所示:

cmake_minimum_required(VERSION 3.6)
project(DeSNN_CPP)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

SET (BOOST_ROOT "C:/Program Files/boost/boost_1_62_0")
SET (BOOST_INCLUDEDIR "/opt/boost/boost-1.57.0/boost")
SET (BOOST_LIBRARYDIR "/opt/boost/boost-1.57.0/boost")

SET (BOOST_MIN_VERSION "1.62.0")
set (Boost_NO_BOOST_CMAKE ON)
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
if (NOT Boost_FOUND)
    message(FATAL_ERROR "Fatal error: Boost (version >= 1.62) required.")
else()
    message(WARNING "Setting up BOOST")
    message(WARNING " Includes - ${Boost_INCLUDE_DIRS}")
    message(WARNING " Library  - ${Boost_LIBRARY_DIRS}")
    include_directories(${Boost_INCLUDE_DIRS})
    link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)

set(SOURCE_FILES main.cpp)
add_executable(DeSNN_CPP ${SOURCE_FILES})

警告,因为我的cmake没有为STATUS提供输出。

这似乎找到了boost目录,我可以导入所有头文件。 CMAKE输出以下内容

Warning:start running cmake...
Warning:Setting up BOOST
Warning:Includes - C:/Program Files/boost/boost_1_62_0
Warning:Library  -

Warning:Library似乎没有出现。当我输入FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED filesystem)时,我收到以下错误

Error:Unable to find the requested Boost libraries.
Boost version: 1.62.0
Boost include path: C:/Program Files/boost/boost_1_62_0
Could not find the following Boost libraries:
        boost_filesystem
No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.

如果我尝试包含一个头文件并运行它,我会收到一个非常大的错误。

C:\Users\aksha\.CLion2016.2\system\cygwin_cmake\bin\cmake.exe --build "C:\Users\aksha\.CLion2016.2\system\cmake\generated\DeSNN CPP-4334ec6a\4334ec6a\Debug" --target DeSNN_CPP -- -j 4
[ 25%] Linking CXX executable DeSNN_CPP.exe
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `__static_initialization_and_destruction_0':
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:221:(.text+0x1ba): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:222:(.text+0x1c6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:223:(.text+0x1d2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::string&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938: undefined reference to `boost::filesystem::path::codecvt()'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938:(.text$_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs[_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs]+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path::codecvt()'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938: undefined reference to `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::string&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:938:(.text$_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs[_ZN5boost10filesystem11path_traits7convertEPKwS3_RSs]+0x32): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*, std::string&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::path_traits::convert(char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946: undefined reference to `boost::filesystem::path::codecvt()'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946:(.text$_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE]+0x37): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path::codecvt()'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:946:(.text$_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE[_ZN5boost10filesystem11path_traits7convertEPKcRSbIwSt11char_traitsIwESaIwEE]+0x52): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::exists(boost::filesystem::path const&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:446: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:446:(.text$_ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::is_directory(boost::filesystem::path const&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:451: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:451:(.text$_ZN5boost10filesystem12is_directoryERKNS0_4pathE[_ZN5boost10filesystem12is_directoryERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::is_regular_file(boost::filesystem::path const&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:456: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:456:(.text$_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE[_ZN5boost10filesystem15is_regular_fileERKNS0_4pathE]+0x1e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
CMakeFiles/DeSNN_CPP.dir/main.cpp.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:614: undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:614:(.text$_ZN5boost10filesystem9file_sizeERKNS0_4pathE[_ZN5boost10filesystem9file_sizeERKNS0_4pathE]+0x16): additional relocation overflows omitted from the output
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `FileReader::list_dir()':
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/DeSNN CPP/FileReader.cpp:41: undefined reference to `boost::filesystem::path::filename() const'
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `__static_initialization_and_destruction_0':
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Program Files/boost/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:930: undefined reference to `boost::filesystem::path::codecvt()'
C:/Program Files/boost/boost_1_62_0/boost/filesystem/path.hpp:930: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, _mbstate_t> const&)'
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::detail::dir_itr_imp::~dir_itr_imp()':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:872: undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)'
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&)':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:903: undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
CMakeFiles/DeSNN_CPP.dir/FileReader.cpp.o: In function `boost::filesystem::directory_iterator::increment()':
C:/Program Files/boost/boost_1_62_0/boost/filesystem/operations.hpp:939: undefined reference to `boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/DeSNN_CPP.dir/build.make:147: DeSNN_CPP.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/DeSNN_CPP.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/DeSNN_CPP.dir/rule] Error 2
make: *** [Makefile:118: DeSNN_CPP] Error 2

我不知道这里发生了什么。关于如何克服这个问题的任何想法?

更新

我设法完成了以下操作,但仍无法找到libs

Warning:start running cmake...
Warning:Setting up BOOST
Warning:Includes - C:/Users/aksha/Desktop/boost_1_62_0
Warning:Library  - C:/Users/aksha/Desktop/boost_1_62_0/stage/lib

1 个答案:

答案 0 :(得分:0)

你告诉它在哪里寻找库文件,但没有告诉它要找哪些。

您需要添加

target_link_libraries(DeSNN_CPP ...list of boost libraries...)

到您的CMakeLists.txt文件