G ++找不到boost库。我说他们很明显

时间:2021-02-19 21:00:49

I'm trying to build some code. Here is the error I'm getting:

我正在尝试构建一些代码。这是我得到的错误:

main.o: In function `__static_initialization_and_destruction_0':
/home/jmbeck/Downloads/boost_1_48_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'

There is more, but I don't think it's relevant.

还有更多,但我不认为这是相关的。

Here is the build command:

这是构建命令:

g++ -I/home/jmbeck/Downloads/boost_1_48_0 
    -L/home/jmbeck/Downloads/boost_1_48_0/stage/lib 
    -lm 
    -lboost_system 
    -lboost_thread
    -lboost_regex 
    main.cpp

The /home/jmbeck/Downloads/boost_1_48_0/stage/lib directory contains the expected files:

/ home / jmbeck / Downloads / boost_1_48_0 / stage / lib目录包含预期的文件:

libboost_system.a
libboost_system.so@
libboost_system.so.1.48.0*
libboost_thread.a
libboost_thread.so@
libboost_thread.so.1.48.0* 
libboost_regex.a
libboost_regex.so@
libboost_regex.so.1.48.0*
... etc...

I've tried building a quick program that didn't use the pre-compiled libraries, and it compiled just fine. It finds the appropriate headers, but not the libraries.

我已经尝试构建一个没有使用预编译库的快速程序,它编译得很好。它找到了合适的头文件,但没有查找库。

What am I doing wrong?

我究竟做错了什么?

2 个解决方案

#1


6  

Try putting the libraries after main.cpp.

尝试在main.cpp之后放置库。

I've experienced some weirdness in the past when GCC ignores libraries because it doesn't think they're used, before reaching my source files.

在GCC忽略库时,我经历了一些奇怪的事情,因为它不认为它们在到达我的源文件之前被使用了。

#2


1  

Often linkers require that libraries be ordered as most dependent to least dependent (I believe MS does not). In this case probably thread or regex depends on system, so you'd need to list the -lsystem after the other boost library that depends on it.

链接器通常要求库被排序为最依赖于最不依赖的库(我相信MS不会)。在这种情况下,线程或正则表达式可能依赖于系统,因此您需要在依赖于它的其他boost库之后列出-lsystem。

#1


6  

Try putting the libraries after main.cpp.

尝试在main.cpp之后放置库。

I've experienced some weirdness in the past when GCC ignores libraries because it doesn't think they're used, before reaching my source files.

在GCC忽略库时,我经历了一些奇怪的事情,因为它不认为它们在到达我的源文件之前被使用了。

#2


1  

Often linkers require that libraries be ordered as most dependent to least dependent (I believe MS does not). In this case probably thread or regex depends on system, so you'd need to list the -lsystem after the other boost library that depends on it.

链接器通常要求库被排序为最依赖于最不依赖的库(我相信MS不会)。在这种情况下,线程或正则表达式可能依赖于系统,因此您需要在依赖于它的其他boost库之后列出-lsystem。