未定义对Boost timer :: auto_cpu_timer的引用 [英] Undefined reference to Boost timer::auto_cpu_timer

查看:101
本文介绍了未定义对Boost timer :: auto_cpu_timer的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CMake项目,该项目使用boost中的unit_test_framework和文件系统库.我正在尝试使用boost::timer::auto_cpu_timer,无法在Ubuntu 12.04上链接它.在Win32上的构建工作正常.

I have a CMake project which uses the unit_test_framework and filesystem libraries from boost. I'm trying to use boost::timer::auto_cpu_timer and can't get it to link on Ubuntu 12.04. The build on Win32 works fine.

有问题的代码.

#include <boost/timer/timer.hpp>

long some_function()
{
    boost::timer::auto_cpu_timer t;
    ...rest omitted...
}

我使用人工构建的boost 1.52.0(完整;版本化; d,mt,mt-d,mt-s,mt-sd,s,sd;静态和共享).

I use boost 1.52.0 which was build by hand (complete; versioned; d, mt, mt-d, mt-s, mt-sd, s, sd; static and shared).

我在CMakeLists.txt主文件中使用以下配置(查找增强功能;正常工作)

I'm using the following configuration in the main CMakeLists.txt (finds boost; works correctly)

set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
if (MSVC)   
    set (Boost_USE_STATIC_RUNTIME OFF)
else () 
    set (Boost_USE_STATIC_RUNTIME ON)
endif ()

find_package (
    Boost ${BOOST_VERSION_MAJOR}.${BOOST_VERSION_MINOR}.${BOOST_VERSION_MICRO} COMPONENTS           
    system filesystem unit_test_framework chrono timer REQUIRED
)

if (Boost_FOUND)
    include_directories (${Boost_INCLUDE_DIRS})
endif ()

在可执行文件的子项目中,我正在使用以下说明.如果没有chrono,Win32项目将无法链接.我还尝试了rt和pthread库(发行版中的pthread),但无济于事.

In the subproject for the executable I'm using the following instructions. The Win32 project wouldn't link without chrono. I also tried it with rt and pthread libraries (pthread from the distribution) to no avail.

target_link_libraries (
    <exename> ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_TIMER_LIBRARY}       
    <other company libs>
)

产生的命令给了我错误.我添加了-Q -v -Wl,-t部分,以查看链接器正在尝试执行的操作. (boost也使用-std=c++0x标志进行编译,否则文件系统将无法工作)

It is the resulting command that gives me the error. I added the -Q -v -Wl,-t part to see what the linker is trying to do. (boost was also compiled with the -std=c++0x flag, otherwise filesystem wouldn't work)

/usr/bin/c++ -Q -v -Wl,-t -Wextra -fPIC -std=c++0x  -Wextra -fPIC -std=c++0x -D_DEBUG \
    <our object files> -o ../bin/<exe name> -rdynamic \
    <some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_system-gcc46-mt-sd-1_52.a \
    <some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_filesystem-gcc46-mt-sd-1_52.a \
    <some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a \
    <some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_timer-gcc46-mt-sd-1_52.a \
    <some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_chrono-gcc46-mt-sd-1_52.a \
    <our other static libs>

链接器的日志.

/usr/bin/ld: mode elf_i386
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o
/usr/lib/gcc/i686-linux-gnu/4.6/crtbegin.o
/lib/i386-linux-gnu/libpthread.so.0
-lrt (/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/librt.so)
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_system-gcc46-mt-sd-1_52.a)error_code.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_filesystem-gcc46-mt-sd-1_52.a)operations.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_filesystem-gcc46-mt-sd-1_52.a)path.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)framework.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)progress_monitor.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)results_collector.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)results_reporter.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)test_tools.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)unit_test_log.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)unit_test_main.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)unit_test_monitor.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)unit_test_parameters.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)unit_test_suite.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)xml_log_formatter.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)xml_report_formatter.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)compiler_log_formatter.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)debug.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)execution_monitor.o
(<some dir>/libs/boost_1_52_0/stage_x86/lib/libboost_unit_test_framework-gcc46-mt-sd-1_52.a)plain_report_formatter.o
<our object files>
-lstdc++ (/usr/lib/gcc/i686-linux-gnu/4.6/libstdc++.so)
-lm (/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libm.so)
-lgcc_s (/usr/lib/gcc/i686-linux-gnu/4.6/libgcc_s.so)
/lib/i386-linux-gnu/libc.so.6
(/usr/lib/i386-linux-gnu/libc_nonshared.a)elf-init.oS
(/usr/lib/i386-linux-gnu/libc_nonshared.a)stat64.oS
(/usr/lib/i386-linux-gnu/libc_nonshared.a)lstat64.oS
(/usr/lib/i386-linux-gnu/libc_nonshared.a)stack_chk_fail_local.oS
/lib/i386-linux-gnu/ld-linux.so.2
-lgcc_s (/usr/lib/gcc/i686-linux-gnu/4.6/libgcc_s.so)
/usr/lib/gcc/i686-linux-gnu/4.6/crtend.o
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crtn.o

似乎它没有使用计时器库中的任何内容.这是我不明白的部分.有人遇到过类似的问题吗?我是否缺少依赖关系?产生的错误很简单:

It seems that it is not using anything from the timer library. This is the part I don't understand. Has anybody experienced a similar problem? Am I missing a dependency? The resulting error is simply:

<some file>.cpp:(.text+0x38): undefined reference to `boost::timer::auto_cpu_timer::auto_cpu_timer(short)'
<some file>.cpp:(.text+0x4e8): undefined reference to `boost::timer::auto_cpu_timer::~auto_cpu_timer()'
<some file>.cpp:(.text+0x543): undefined reference to `boost::timer::auto_cpu_timer::~auto_cpu_timer()'

我希望我不要忘记提任何东西.预先感谢您的任何建议.

I hope I didn't forget to mention anything. Thanks in advance for any advice.

推荐答案

如果您遇到静态库中未定义引用的问题,则可以尝试明确告诉链接程序包括整个存档,即使它(对于出于某种原因)认为不需要.相关的编译器选项为-Wl,--whole-archive,必须放置在应影响的静态库之前.可以在此问题中找到更多背景.

If you're running into problems with undefined references from static libraries, you can try to tell the linker explicitly to include the whole archive, even if it (for some reason) thinks that it's not needed. The relevant compiler option is -Wl,--whole-archive and has to be placed before the static libraries it should affect. More background can be found in this question.

这篇关于未定义对Boost timer :: auto_cpu_timer的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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