Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build simple boost program on Mac OS (Lion)

Tags:

boost

osx-lion

Steps:
1. sudo port boost
The boost file installed in /opt/local/boost, library files are in /opt/local/lib

2. use XCode to create c++ project

#include <iostream>
#include <boost/asio.hpp>
int main () {
    return 0;
}


3. set XCode to find out boost
in "Build Settings" -> "HEADER_SEARCH_PATHS"
in both Debug and Release add path /opt/local/include

4. "Build Settings" -> "LIBRARY_SEARCH_PATHS" --> add /opt/local/lib both for debug and release.

5. build program and failed.
Error Messages,

Undefined symbols for architecture x86_64:
  "boost::system::generic_category()", referenced from:
  ___cxx_global_var_init1 in main.o
  ___cxx_global_var_init2 in main.o
  "boost::system::system_category()", referenced from:
  ___cxx_global_var_init3 in main.o
  boost::asio::error::get_system_category() in main.o
  "boost::asio::error::get_netdb_category()", referenced from:
  ___cxx_global_var_init5 in main.o <br>
  "boost::asio::error::get_addrinfo_category()", referenced from:
  ___cxx_global_var_init6 in main.o <br>
  "boost::asio::error::get_misc_category()", referenced from:
  ___cxx_global_var_init7 in main.o <br>
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Am I wrong in the procedure?

like image 400
CCC Avatar asked Jun 13 '12 02:06

CCC


2 Answers

You need to link with Boost.System, which should be in /opt/local/lib/libboost_system (with some suffix, that depends on how you built boost)

Add that to your Xcode project.

like image 95
Marshall Clow Avatar answered Nov 15 '22 10:11

Marshall Clow


  1. select on your "targets"
  2. in "Link Binary with libraries" section under "build phases" tab, add boost library.
  3. if install via MacPort, the boost will be at /opt/local/lib,
    if install via brew, the boost will be at /usr/local/Cellar/boost ,
    if build by yourself, it will be at /usr/local/lib by default or yourBoostLib/stage/lib
like image 44
CCC Avatar answered Nov 15 '22 10:11

CCC