I use Mac OS X as my main development environment, and currently do a bit of C++ development using C++11 features as well as Boost. This post is to remind me of the steps I took to setup Eclipse to compile programmes correctly - only comments important to me are listed; as always read the individual README/INSTALL notes for details.
I use clang++ as it produces better error messages, and the llvm backend seems to be the right way forward.
C/C++ Build / Settings
linker and compiler set to clang++
linker ‘All options’ : -std=c++11 -stdlib=libc++
compiler / misc / other flags, add : -std=c++11 -stdlib=libc++
linker add all libraries used (currently and in order for the pq ones):
- pqxx, pq, boost_program_options, boost_log_setup boost_log, boost_date_time, boost_reges, boost_filesystem boost_system, boost_thread, ssl
Setup to build with pqxx
./configure CC=clang CXX=clang++ CXXFLAGS='-stdlib=libc++' make -j 8 sudo make install
Setup and build boost latest version
./bootstrap.sh --with-toolset=clang --prefix=/usr/local ./b2 clean ./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" --prefix=/usr/local -j 10 define=BOOST_SYSTEM_NO_DEPRECATED stage release sudo ./b2 install toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" --prefix=/usr/local
- The ‘j’ option makes the build take less time on most machines; use it as it is a lengthy build!
- I had to use BOOST_SYSTEM_NO_DEPRECATED as boost-log wouldn’t work properly.
- I did a release build.
Setup and build boost-log
I needed a solid way of logging quite a few messages from different sources across a programme, and it would be convenient to be able to steer these into different files according to severity etc. After a lot of searching I came across boost-log. It is not quite accepted by Boost yet but seems to be in active development, and most importantly, it fit all my requirements. Also, it looks like it could be accepted as part of the main package one day.
Boost-log is installed alongside Boost; i.e. expand and copy to where you build your Boost installation in the respective folders. There might be a more up-to-date revision in the SVN, and I will look out for that, but for now V1 works for my purpose.
I had to use BOOST_SYSTEM_NO_DEPRECATED as boost-log wouldn’t compile/work properly otherwise. This didn’t seem to affect any of the other components I have been using, and not using deprecated features seems like the right thing to begin with anyway.
boost-log.sourceforge.net (seems like a good choice as it is fairly current and well documented)
copy contents to boost and libs folder of boost dist (I have taken v1 from SVN)
adding parameters below might reduce binary size
- define=BOOST_LOG_USE_CHAR define=BOOST_LOG_NO_SETTINGS_PARSERS_SUPPORT
Do a b2 clean/release/install of Boost to make it available.
- Fiddling with something homegrown was not an option; you may start out KISS but quickly end up trying to develop something that is actually quite complicated if it is to work properly. Use one of the many log libraries available out there instead of hacking something - in the long run it will pay off.
Verify your binaries.
You will save a lot of time by verifying that your binary is linked with the right libraries.
Use otool (on Mac, linux uses ldd) to verify you are using the correct libraries after compilation. It is important to verify the correct use of libc++ as you will get weird error messages if you link the wrong libraries.
otool -L your-binary-here