在导致未定义符号错误的示例代码上使用 Boost 库
Using Boost Library on an example code causing Undefined symbols error?
我希望g++ reference_counted.cpp
运行一个示例代码,但程序产生了错误
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccD1hl7z.o
boost::system::error_code::error_code() in ccD1hl7z.o
boost::asio::error::get_system_category() in ccD1hl7z.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccD1hl7z.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
运行brew doctor
会产生以下警告,但不清楚导致失败的原因。如何解决这个问题?
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/opt/local/bin/curl-config
/opt/local/bin/freetype-config
/opt/local/bin/icu-config
/opt/local/bin/libpng-config
/opt/local/bin/libpng15-config
/opt/local/bin/nc-config
/opt/local/bin/ncurses5-config
/opt/local/bin/ncursesw5-config
/opt/local/bin/pcre-config
/opt/local/bin/ppl-config
/opt/local/bin/python-config
/opt/local/bin/python2.7-config
/opt/local/bin/xml2-config
Warning: /Library/Frameworks/Mono.framework detected
This can be picked up by CMake's build system and likely cause the build to
fail. You may need to move this file out of the way to compile CMake.
Warning: You have MacPorts or Fink installed:
/opt/local/bin/port
This can cause trouble. You don't have to uninstall them, but you may want to
temporarily move them out of the way, e.g.
sudo mv /opt/local ~/macports
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libasan.0.dylib
/usr/local/lib/libatomic.1.dylib
/usr/local/lib/libgcc_ext.10.4.dylib
/usr/local/lib/libgcc_ext.10.5.dylib
/usr/local/lib/libgcc_s.1.dylib
/usr/local/lib/libgfortran.3.dylib
/usr/local/lib/libgomp.1.dylib
/usr/local/lib/libitm.1.dylib
/usr/local/lib/libmca_common_sm.3.dylib
/usr/local/lib/libmpi.1.dylib
/usr/local/lib/libmpi_cxx.1.dylib
/usr/local/lib/libmpi_f77.1.dylib
/usr/local/lib/libompitrace.0.dylib
/usr/local/lib/libopen-pal.4.dylib
/usr/local/lib/libopen-rte.4.dylib
/usr/local/lib/libopen-trace-format.1.dylib
/usr/local/lib/libotfaux.0.dylib
/usr/local/lib/libquadmath.0.dylib
/usr/local/lib/libssp.0.dylib
/usr/local/lib/libstdc++.6.dylib
/usr/local/lib/libvt-hyb.0.dylib
/usr/local/lib/libvt-mpi-unify.0.dylib
/usr/local/lib/libvt-mpi.0.dylib
/usr/local/lib/libvt-mt.0.dylib
/usr/local/lib/libvt.0.dylib
Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .la files:
/usr/local/lib/libasan.la
/usr/local/lib/libatomic.la
/usr/local/lib/libgfortran.la
/usr/local/lib/libgmp.la
/usr/local/lib/libgomp.la
/usr/local/lib/libitm.la
/usr/local/lib/libmca_common_sm.la
/usr/local/lib/libmpc.la
/usr/local/lib/libmpfr.la
/usr/local/lib/libmpi.la
/usr/local/lib/libmpi_cxx.la
/usr/local/lib/libmpi_f77.la
/usr/local/lib/libmpi_f90.la
/usr/local/lib/libompitrace.la
/usr/local/lib/libopen-pal.la
/usr/local/lib/libopen-rte.la
/usr/local/lib/libopen-trace-format.la
/usr/local/lib/libotfaux.la
/usr/local/lib/libquadmath.la
/usr/local/lib/libssp.la
/usr/local/lib/libssp_nonshared.la
/usr/local/lib/libstdc++.la
/usr/local/lib/libsupc++.la
/usr/local/lib/libvt-hyb.la
/usr/local/lib/libvt-mpi-unify.la
/usr/local/lib/libvt-mpi.la
/usr/local/lib/libvt-mt.la
/usr/local/lib/libvt-pomp.la
/usr/local/lib/libvt.la
Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .pc files:
/usr/local/lib/pkgconfig/ompi-c.pc
/usr/local/lib/pkgconfig/ompi-cxx.pc
/usr/local/lib/pkgconfig/ompi-f77.pc
/usr/local/lib/pkgconfig/ompi-f90.pc
/usr/local/lib/pkgconfig/ompi.pc
/usr/local/lib/pkgconfig/orte.pc
Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected static libraries:
/usr/local/lib/libatomic.a
/usr/local/lib/libgfortran.a
/usr/local/lib/libgmp.a
/usr/local/lib/libgomp.a
/usr/local/lib/libitm.a
/usr/local/lib/libmpc.a
/usr/local/lib/libmpfr.a
/usr/local/lib/libmpi_f90.a
/usr/local/lib/libopen-trace-format.a
/usr/local/lib/libotfaux.a
/usr/local/lib/libquadmath.a
/usr/local/lib/libssp.a
/usr/local/lib/libssp_nonshared.a
/usr/local/lib/libstdc++.a
/usr/local/lib/libsupc++.a
/usr/local/lib/libvt-hyb.a
/usr/local/lib/libvt-mpi-unify.a
/usr/local/lib/libvt-mpi.a
/usr/local/lib/libvt-mt.a
/usr/local/lib/libvt-pomp.a
/usr/local/lib/libvt.a
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python
Warning: You have uncommitted modifications to Homebrew
If this a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
cd /usr/local/Library && git stash && git clean -d -f
Warning: Some directories in your path end in a slash.
Directories in your path should not end in a slash. This can break other
doctor checks. The following directories should be edited:
/usr/local/facebook/arcanist/bin/
Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
echo export PATH="/usr/local/sbin:$PATH" >> ~/.bash_profile
Warning: Your Xcode (4.6.2) is outdated
Please install Xcode 5.0.
467502-mitll:Boost ch24515$ echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile
467502-mitll:Boost ch24515$ g++ reference_counted.cpp
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccmaaqd0.o
boost::system::error_code::error_code() in ccmaaqd0.o
boost::asio::error::get_system_category() in ccmaaqd0.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccmaaqd0.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
467502-mitll:Boost ch24515$ brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/opt/local/bin/curl-config
/opt/local/bin/freetype-config
/opt/local/bin/icu-config
/opt/local/bin/libpng-config
/opt/local/bin/libpng15-config
/opt/local/bin/nc-config
/opt/local/bin/ncurses5-config
/opt/local/bin/ncursesw5-config
/opt/local/bin/pcre-config
/opt/local/bin/ppl-config
/opt/local/bin/python-config
/opt/local/bin/python2.7-config
/opt/local/bin/xml2-config
Warning: /Library/Frameworks/Mono.framework detected
This can be picked up by CMake's build system and likely cause the build to
fail. You may need to move this file out of the way to compile CMake.
Warning: You have MacPorts or Fink installed:
/opt/local/bin/port
This can cause trouble. You don't have to uninstall them, but you may want to
temporarily move them out of the way, e.g.
sudo mv /opt/local ~/macports
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libasan.0.dylib
/usr/local/lib/libatomic.1.dylib
/usr/local/lib/libgcc_ext.10.4.dylib
/usr/local/lib/libgcc_ext.10.5.dylib
/usr/local/lib/libgcc_s.1.dylib
/usr/local/lib/libgfortran.3.dylib
/usr/local/lib/libgomp.1.dylib
/usr/local/lib/libitm.1.dylib
/usr/local/lib/libmca_common_sm.3.dylib
/usr/local/lib/libmpi.1.dylib
/usr/local/lib/libmpi_cxx.1.dylib
/usr/local/lib/libmpi_f77.1.dylib
/usr/local/lib/libompitrace.0.dylib
/usr/local/lib/libopen-pal.4.dylib
/usr/local/lib/libopen-rte.4.dylib
/usr/local/lib/libopen-trace-format.1.dylib
/usr/local/lib/libotfaux.0.dylib
/usr/local/lib/libquadmath.0.dylib
/usr/local/lib/libssp.0.dylib
/usr/local/lib/libstdc++.6.dylib
/usr/local/lib/libvt-hyb.0.dylib
/usr/local/lib/libvt-mpi-unify.0.dylib
/usr/local/lib/libvt-mpi.0.dylib
/usr/local/lib/libvt-mt.0.dylib
/usr/local/lib/libvt.0.dylib
Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .la files:
/usr/local/lib/libasan.la
/usr/local/lib/libatomic.la
/usr/local/lib/libgfortran.la
/usr/local/lib/libgmp.la
/usr/local/lib/libgomp.la
/usr/local/lib/libitm.la
/usr/local/lib/libmca_common_sm.la
/usr/local/lib/libmpc.la
/usr/local/lib/libmpfr.la
/usr/local/lib/libmpi.la
/usr/local/lib/libmpi_cxx.la
/usr/local/lib/libmpi_f77.la
/usr/local/lib/libmpi_f90.la
/usr/local/lib/libompitrace.la
/usr/local/lib/libopen-pal.la
/usr/local/lib/libopen-rte.la
/usr/local/lib/libopen-trace-format.la
/usr/local/lib/libotfaux.la
/usr/local/lib/libquadmath.la
/usr/local/lib/libssp.la
/usr/local/lib/libssp_nonshared.la
/usr/local/lib/libstdc++.la
/usr/local/lib/libsupc++.la
/usr/local/lib/libvt-hyb.la
/usr/local/lib/libvt-mpi-unify.la
/usr/local/lib/libvt-mpi.la
/usr/local/lib/libvt-mt.la
/usr/local/lib/libvt-pomp.la
/usr/local/lib/libvt.la
Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .pc files:
/usr/local/lib/pkgconfig/ompi-c.pc
/usr/local/lib/pkgconfig/ompi-cxx.pc
/usr/local/lib/pkgconfig/ompi-f77.pc
/usr/local/lib/pkgconfig/ompi-f90.pc
/usr/local/lib/pkgconfig/ompi.pc
/usr/local/lib/pkgconfig/orte.pc
Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected static libraries:
/usr/local/lib/libatomic.a
/usr/local/lib/libgfortran.a
/usr/local/lib/libgmp.a
/usr/local/lib/libgomp.a
/usr/local/lib/libitm.a
/usr/local/lib/libmpc.a
/usr/local/lib/libmpfr.a
/usr/local/lib/libmpi_f90.a
/usr/local/lib/libopen-trace-format.a
/usr/local/lib/libotfaux.a
/usr/local/lib/libquadmath.a
/usr/local/lib/libssp.a
/usr/local/lib/libssp_nonshared.a
/usr/local/lib/libstdc++.a
/usr/local/lib/libsupc++.a
/usr/local/lib/libvt-hyb.a
/usr/local/lib/libvt-mpi-unify.a
/usr/local/lib/libvt-mpi.a
/usr/local/lib/libvt-mt.a
/usr/local/lib/libvt-pomp.a
/usr/local/lib/libvt.a
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python
Warning: You have uncommitted modifications to Homebrew
If this a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
cd /usr/local/Library && git stash && git clean -d -f
Warning: Some directories in your path end in a slash.
Directories in your path should not end in a slash. This can break other
doctor checks. The following directories should be edited:
/usr/local/facebook/arcanist/bin/
Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
echo export PATH="/usr/local/sbin:$PATH" >> ~/.bash_profile
Warning: Your Xcode (4.6.2) is outdated
Please install Xcode 5.0.
将-lboost_system
添加到链接器标志:
g++ reference_counted.cpp -lboost_system
您需要
将应用程序链接到boost_system库。我认为对于asio,您还需要boost_thread,因此总而言之:
g++ -lboost_system -lboost_thread reference_counted.cpp
相关文章:
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 如何替换此示例代码片段中已弃用的handler_type_t或 boost::asio::handler_type?
- 我在使用 boost::serialization 时遇到了一个问题,我的代码在 Linux 中运行良好,但在 Wind
- 在cpp中使用boost-python的python代码是否进行动态内存分配
- boost::spirit--试图编译大多数简单代码的编译器错误
- boost::asio-async_read_some示例代码没有读取套接字中的所有数据
- Boost tread 代码在 VC++ 下编译,但不在 GCC 下编译:如何获得更好的调试信息
- 我已经编写了C++代码将 boost::optional 视为一个范围,但它无法编译
- Boost FFT示例-编译时出错,这段代码在做什么
- 编译在 Python 代码内部调用的 C++ 代码时出错,使用 Boost Python
- 使用 boost::序列化代码将 *this 传递给模板函数会产生错误
- 在 boost::p ython 中的 python 对象中运行 python 代码
- 使用 C++11 选项编译 C++98 代码时由于 Boost 标头而导致的不明确重载
- 如何在不使用Boost的情况下重写此代码
- 我不知道如何使用 boost,虽然我的老师确实提供了代码,但我遇到了一个错误
- 编译用于创建boost.log格式的代码时出错
- 使用Visual Studio编译代码时,boost::iostreams::multichar_input_filte
- 试图用Boost::Beast替换我的libwebsocket代码
- Boost.thread代码在Ubuntu和Windows中表现出不同的行为
- 以 C++11 方式重写 boost 风味代码(Boost.Bind、Boost.Function)