How do you install Boost on MacOS?
Download MacPorts, and run the following command:
sudo port install boost
Include boost in xcode
I'm using boost with Xcode 3.2.1 on mac os 10.6.8
I had problems with using boost and Xcode today, finally I managed to make it work so I hope this helps:
download boost, I got the 1.52.0 today, untar it
install boost:
at first I couldn't do the
./bootstrap.sh
, it stopped after the first few lines. After some googling, I got the answer, it was because when I installed Xcode a long time ago, for some reason I didn't check the “Unix development" in the install options. At this point, reinstall a newer version of Xcode and check the "unix development line"after that, the
./bootstrap
and./b2
install worked finethe lambda example:
at this point, the first example should work fine, if it doesn't try adding
/usr/local/include
in the project settings/header search pathusing thread or something else that requires to be built
threads require a specific dylib to work: libboost_system.dylib. on my system it was located in
/usr/local/lib
after the./b2 install
thingyin the left part of the GUI, you can right click anywhere and select Add Existing File
if the file is hidden you can find a shortcut to get to usr/local/lib in the directory
/Developer/SDKs/MacOSX10.6.sdk/usr/local
once the libboost_system.dylib
does appear in the Groups and Files part of the GUI, it should work
How do I compile boost for OS X 64b platforms with stdlibc++?
Downloaded Boost 1.55, bootstrapped using:
./bootstrap.sh --prefix=/usr/local/boost155 cxxflags="-arch i386 -arch x86_64" \
address-model=32_64 threading=multi macos-version=10.8 stage
Built using:
./b2 threading=multi link=static runtime-link=static \
cxxflags="-stdlib=libstdc++" linkflags="-stdlib=libstdc++"
Yields in libboost_chrono.a
:
U std::string::_Rep::_M_destroy(std::allocator<char> const&)
U std::string::_Rep::_S_empty_rep_storage
U std::string::append(char const*, unsigned long)
U std::string::append(std::string const&)
U std::string::assign(char const*, unsigned long)
U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)
Which implies that the library was built with the option -stdlib=libstdc++
- i.e. it's linked against the gnu version of the C++ runtime.
We purge the build using:
find . -name \*.o -print0 | xargs -0 rm
find . -name \*.a -print0 | xargs -0 rm
If we don't do that then it doesn't rebuild, and you end up with the same code as before. Next we build using:
./b2 threading=multi link=static runtime-link=static \
cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
Yields in libboost_chrono.a
:
U std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*)
U std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*, unsigned long)
U std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*)
U std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
U std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()
Which implies that it's built against libc++
.
This can be verified by using a simple test c++ program (to indicate the linking):
#include <string>
int
main(int argc, char **argv)
{
std::string s("Hello World");
return 0;
}
$ make test
c++ test.cpp -o test
$ nm ./test | c++filt
U std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)
U std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()
$ rm test
$ make test CXXFLAGS=-stdlib=libstdc++
c++ -stdlib=libstdc++ test.cpp -o test
$ nm ./test | c++filt
U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()
so yes, it's compiling with the relevant flag. What it does indicate that you have to pass the -stdlib=libstdc++
to everything you're compiling if you're using XCode 5 as it now defaults to using -stdlib=libc++
. This means that any C++ based libraries that depend on c++
stdlib that you depend on also have to be compiled with the same flag.
Be careful with an incremental build of boost - if you don't purge the .o
and .a
files, they don't get recompiled based on the changed flags, which keeps the files as compiled, so if they were miscompiled then you encounter the problem.
How do I build simple boost program on Mac OS (Lion)
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.
linking Boost library to Xcode project
Adding the path is correct but you also need to specify the libraries you need. On the commandline you would use -l for that in Xcode you can add them to Other Linker Flags
.
The libraries you need are boost_filesystem
and boost_system
.
Related Topics
Adding Quotes to Argument in C++ Preprocessor
Are There in X86 Any Instructions to Accelerate Sha (Sha1/2/256/512) Encoding
C++ Regular Expressions with Boost Regex
Why Default Return Value of Main Is 0 and Not Exit_Success
How to Embed Node.Js Interpreter into C/C++
Std::Istream_Iterator<> with Copy_N() and Friends
Static Initialization and Destruction of a Static Library's Globals Not Happening with G++
Why Does This Work: Returning C String Literal from Std::String Function and Calling C_Str()
Why Can't Operator () of Stateless Functor Be Static
Template Assignment Operator Overloading Mystery
Read Qprocess Output to String
Floating Point to Binary Value(C++)
Why Is It Not Possible to Overload the Ternary Operator
How to Define Thread-Local Local Static Variables
Cost of Using Std::Map with Std::String Keys VS Int Keys