1

我想运行一个示例代码 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.
4

2 回答 2

2

添加-lboost_system到您的链接器标志:

g++ reference_counted.cpp -lboost_system
于 2013-10-11T19:56:10.197 回答
1

您需要将您的应用程序链接到 boost_system 库。我认为对于 asio,您还需要 boost_thread,所以总的来说它是:

g++ -lboost_system -lboost_thread reference_counted.cpp
于 2013-10-11T19:58:21.817 回答