2017-03-31 3 views
0

대학 시험을위한 개인 프로젝트를 만들어야하고 네트워킹 기능으로 뭔가를하고 싶습니다. 나는 이미이 특정 라이브러리에 관한 책을 가지고 있지만, 이제는 내 프로젝트에서 이것을 링크 할 수 없다. (나의 책은 GCC와 리눅스를 연결하는 방법에 대해서만 설명하고 있지만, Windows 10에서는 MinGW와 함께 CLion을 사용하고있다.) 나는이 같은 간단한 빈 프로젝트 컴파일하면 다음과 같습니다 Boost.Asio를 Clion에 연결할 때 Static_initialization_and_distruction 오류가 발생했습니다.

CMakeFiles\Hello.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\Hello.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio5error19get_system_categoryEv': 
    C:/boost_1_63_0/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()' 
    CMakeFiles\Hello.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7startupERNS2_4dataEhh': 
    C:/boost_1_63_0/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `[email protected]' 
    CMakeFiles\Hello.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7cleanupERNS2_4dataE': 
    C:/boost_1_63_0/boost/asio/detail/impl/winsock_init.ipp:56: undefined  reference to `[email protected]' 
    collect2.exe: error: ld returned 1 exit status 
    CMakeFiles\Hello.dir\build.make:96: recipe for target 'Hello.exe' failed 
    CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Hello.dir/all' failed 
    mingw32-make.exe[3]: *** [Hello.exe] Error 1 
    mingw32-make.exe[2]: *** [CMakeFiles/Hello.dir/all] Error 2 
    mingw32-make.exe[1]: *** [CMakeFiles/Hello.dir/rule] Error 2 
    CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Hello.dir/rule' failed 
    mingw32-make.exe: *** [Hello] Error 2 
    Makefile:117: recipe for target 'Hello' failed 

cmake_minimum_required(VERSION 3.6) 
    project(Hello) 


    set(CMAKE_CXX_STANDARD 14) 

    set(SRC_FILES main.cpp) 
    include_directories(C:\\boost_1_63_0) 
    link_directories(C:\\boost_1_63_0) 

    find_package(BOOST 1.63.0 REQUIRED) 

    add_executable(Hello ${SRC_FILES}) 

가 어떻게이 내 CMakeLists.txt 해결할 수있다

:
#include <boost/asio.h> 

int main (int argc, char ** argv) { 

    return 0; 
} 

내가이 인상적인 오류를? 미리 감사드립니다.

편집

는 다음과 같이 내 CMakeLists.txt 업데이트 :

cmake_minimum_required(VERSION 3.8.0) 
project(Hello) 


set(CMAKE_CXX_STANDARD 14) 

set(SRC_FILES main.cpp) 

set(BOOST_ROOT C:\\boost_1_63_0) 
find_package(Boost 1.63.0 COMPONENTS system REQUIRED) 
find_library(WS2_32_LIBRARY ws2_32) 

link_directories(C:\\boost_1_63_0) 
link_libraries(${BOOST_LIBRARIES}) 

add_executable(Hello ${SRC_FILES}) 
target_link_libraries(Hello ${WS2_32_LIBRARY} ${BOOST_LIBRARIES}) 

을 그리고 난 내 프로그램 말할 때 지금은 어쨌든, 어떤 오류가 발생하지 않습니다

#include <boost/asio.hpp> 

부스트가 빨간색으로 표시되고 정적 분석기가 "부스트를 찾을 수 없음"이라고 알려줍니다. 지금 문제가 어디 있습니까? 감사합니다.

답변

0

당신은 Boost.SystemWinsock와 연결, 그래서 당신의 CMakeLists.txt이 같은 것을 추가해야합니다 :

find_package(Boost COMPONENTS system REQUIRED) 
find_library(WS2_32_LIBRARY ws2_32) 
target_link_libraries(Hello ${WS2_32_LIBRARY} ${Boost_SYSTEM_LIBRARY}) 
+0

을 RASTA의 IUUC @Baffo, 지금은 프로그램이 컴파일 및 실행, 그러나 당신의 IDE가 포함 인식하지 못하는 이유는 무엇입니까? IDE를 구성하고 헤더 파일의 위치를 ​​알려줘야한다고 생각합니다. 도움이 필요하면 다른 질문을 올리고 적절하게 태그를 답니다. –

+0

아니요, 내 프로그램도 컴파일되지 않습니다. 빌드에서 "부스트를 찾을 수 없습니다"라는 메시지가 표시됩니다. 어쨌든 CMake 디버그는 Boost 1.63.0과 boost :: system을 찾을 수 있다고 알려줍니다. –

+0

@Baffo rasta 아마도 mingw를위한 Boost를 구축하지 않았습니까? –

관련 문제