2017-05-05 12 views
2

にリンクできません。タイトルから、CMakeを介してBoostライブラリをリンクすると思います(クロスプラットフォームコードを書くためにCLionと作業していますので、他のチャンスはありません)。私はVisual Studio内で使用すると、問題なく動作するため、すべてを正しく構築したと確信しています。 は、ここに私のcmakeのコードです:Boost 1.63.0をCMake

cmake_minimum_required(VERSION 3.7) 
project(BoostHello) 

set(BOOST_ROOT C:/boost_1.63.0) 
find_package(BOOST 1.6.0 REQUIRED) 
include_directories(${Boost_INCLUDE_DIR}) 
set(CMAKE_CXX_STANDARD 14) 

set(SOURCE_FILES main.cpp) 
add_executable(BoostHello ${SOURCE_FILES}) 
target_link_libraries(BoostHello ${Boost_LIBRARIES}) 

そして、ここでは私のコンパイルエラーです:

"C:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" --build C:\Users\Admin\CLionProjects\BoostHello\cmake-build-debug --target all --  -j 8 
Scanning dependencies of target BoostHello 
[ 50%] Building CXX object CMakeFiles/BoostHello.dir/main.cpp.obj 
[100%] Linking CXX executable BoostHello.exe 
CMakeFiles\BoostHello.dir/objects.a(main.cpp.obj): In function `main': 
C:/Users/Admin/CLionProjects/BoostHello/main.cpp:6: undefined reference to  `boost::filesystem::path::root_path() const' 
C:/Users/Admin/CLionProjects/BoostHello/main.cpp:7: undefined reference to  `boost::filesystem::path::relative_path() const' 
C:/Users/Admin/CLionProjects/BoostHello/main.cpp:8: undefined reference to `boost::filesystem::path::filename() const' 
CMakeFiles\BoostHello.dir/objects.a(main.cpp.obj): In function  `_static_initialization_and_destruction_0': 
C:/boost_1.63.0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()' 
C:/boost_1.63.0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()' 
C:/boost_1.63.0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()' 
CMakeFiles\BoostHello.dir/objects.a(main.cpp.obj): In function  `ZN5boost10filesystem11path_traits7convertEPKwS3_RNSt7__cxx1112basic_stringIcSt1 1char_traitsIcESaIcEEE': 
C:/boost_1.63.0/boost/filesystem/path.hpp:989: undefined reference to  `boost::filesystem::path::codecvt()' 
C:/boost_1.63.0/boost/filesystem/path.hpp:989: undefined reference to `boost::filesystem::path_traits::convert(wchar_t const*, wchar_t const*,  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>  >&, std::codecvt<wchar_t, char, int> const&)' 
collect2.exe: error: ld returned 1 exit status 
CMakeFiles\BoostHello.dir\build.make:96: recipe for target 'BoostHello.exe'  failed 
mingw32-make.exe[2]: *** [BoostHello.exe] Error 1 
mingw32-make.exe[1]: *** [CMakeFiles/BoostHello.dir/all] Error 2 
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/BoostHello.dir/all'  failed 
mingw32-make.exe: *** [all] Error 2 
Makefile:82: recipe for target 'all' failed 

そして、最終的には、ここで私がコンパイルしようとしているコードです:私は

#include <iostream> 
#include <boost/filesystem.hpp> 

int main(int argc, char** argv) { 
    boost::filesystem::path myPath =  {L"C:/Users/Admin/ClionProjects/BoostHello"}; 
    std::cout << "Root:\t"  << myPath.root_path()   << std::endl; 
    std::cout << "Relative:\t" << myPath.relative_path()  << std::endl; 
    std::cout << "Filename:\t" << myPath.filename()    << std::endl; 
    return 0; 
} 

何をやっているが違う? 私はMinGWでコンパイルしています。 ありがとうございます!

答えて

2

そうcmakeのはに対してリンクするライブラリを後押しどの知らない

find_package(Boost 1.63.0 REQUIRED filesystem system) 

によって

find_package(BOOST 1.6.0 REQUIRED) 

を交換してください。

+0

あなたはそれを持っていましたが、私はこれを追加しなければなりませんでした: find_package(ブースト1.63.0ファイルシステムが必要です) –

+0

ありがとう、私は答えを更新しました – oLen

関連する問題