cmake并加速 [英] CMake and Boost

查看:364
本文介绍了cmake并加速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并发现很多人有同样的问题,但没有解决方法。

I've searched and found out that a lot of people have the same problem, but no solution exists.

和编译时,我得到一个错误:

I'm using CMake to generate Makefiles for MinGW and when compiling I'm getting an error:

CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x5e): undefined reference to `_imp___ZN5boost6thread4joinEv'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x71): undefined reference to `_imp___ZN5boost6threadD1Ev'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x88): undefined reference to `_imp___ZN5boost6threadD1Ev'

这似乎是一个连接问题,我明白了。我的CMake的配置是:

This seems to be a linking problem, I get it. My CMake configuration is:

project(boosttest)
cmake_minimum_required(VERSION 2.6)

include_directories(${boosttest_SOURCE_DIR}/include c:/boost_1_48_0/)
link_directories(c:/boost_1_48_0/lib)

file(GLOB_RECURSE cppFiles src/*.cpp)

add_executable(boosttest ${cppFiles})

target_link_libraries(boosttest libboost_thread-mgw46-mt-1_48.a)

首先,我尝试使用 find_package(升压组件线程),它正在以同样的方式,所以我想尝试手动做到这一点,我仍然得到同样的错误

First I tried using find_package(Boost COMPONENTS thread) and it was working the same way, so I thought to try to do this manually and I still get the same error.

对此有何见解?

我已经编译它使用的bjam MinGW和作为一个静态链接。也试着这样做的:

I've compiled it for mingw using bjam and as a static link. Also tried doing:

add_library(imp_libboost_thread STATIC IMPORTED)
set_property(TARGET imp_libboost_thread PROPERTY IMPORTED_LOCATION c:/boost_1_48_0/lib/libboost_thread-mgw46-mt-1_48.a)
target_link_libraries(boosttest imp_libboost_thread)

和我仍然得到同样的错误消息。

And I still get the same error messages.

推荐答案

有关的mingw32您可以添加定义 BOOST_THREAD_USE_LIB 。并与升压联::线程工作。您可能还需要主题包(但我不知道,可能是它需要只对* nix平台)。

For mingw32 you may add definition BOOST_THREAD_USE_LIB. And linking with boost::thread will work. Also you may need Threads package (but i'm not sure, may be it needs only for *nix platforms).

下面是我CMakeLists的一部分。我复制从项目,该项目采用的boost ::线程,并在MinGW的海湾合作​​委员会(和其他编译器)编译:

Here is part of my CMakeLists. I copied it from project, which uses boost::thread, and compiles under mingw-gcc (and other compilers):

    set(Boost_USE_STATIC_LIBS   ON)
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0")
    find_package(Boost COMPONENTS thread date_time program_options filesystem system REQUIRED)
    include_directories(${Boost_INCLUDE_DIRS})

    find_package(Threads REQUIRED)

    #...

    if (WIN32 AND __COMPILER_GNU)
        # mingw-gcc fails to link boost::thread
        add_definitions(-DBOOST_THREAD_USE_LIB)
    endif (WIN32 AND __COMPILER_GNU)

    #...

    target_link_libraries(my_exe
            ${CMAKE_THREAD_LIBS_INIT}
            #...
        ${Boost_LIBRARIES}
    )

这篇关于cmake并加速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆