2

I've downloaded boost and built it, and not for the first time, but then things started to seem weird.

At first I got these errors while compiling my project (which uses boost):

/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/thread/exceptions.hpp:51: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/thread/exceptions.hpp:84: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/thread/pthread/thread_data.hpp:152: undefined reference to `vtable for boost::detail::thread_data_base'
/usr/local/include/boost/thread/pthread/thread_data.hpp:195: undefined reference to `boost::detail::get_current_thread_data()'
/usr/local/include/boost/thread/detail/thread.hpp:179: undefined reference to `boost::thread::start_thread_noexcept()'
/usr/local/include/boost/thread/detail/thread.hpp:741: undefined reference to `boost::thread::native_handle()'
/usr/local/include/boost/thread/detail/thread.hpp:767: undefined reference to `boost::thread::join_noexcept()'
/usr/local/include/boost/thread/detail/thread.hpp:779: undefined reference to `boost::thread::do_try_join_until_noexcept(timespec const&, bool&)'
/usr/local/include/boost/thread/pthread/condition_variable.hpp:84: undefined reference to `boost::this_thread::interruption_point()'
/usr/local/include/boost/thread/detail/thread.hpp:90: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'

So I went to check if everything is in place and found out that the boost lib files I have don't have the usual library naming, that is they just look like: libboost_thread.a, libboost_system.a, libboost_date_time.a, instead of the -mt, -d and so on.

I don't remember how exactly I built it, but if I try to run:
boost_src_dir > ./b2 threading=multi link=static variant=debug,release
I get:

error: Name clash for '<pstage/lib>libboost_atomic.a'
error: 
error: Tried to build the target twice, with property sets having 
error: these incompatible properties:
error: 
error:     -  <debug-symbols>on <inlining>off <optimization>off <runtime-debugging>on <variant>debug
error:     -  <debug-symbols>off <define>NDEBUG <inlining>full <optimization>speed <runtime-debugging>off <variant>release
error: 
error: Please make sure to have consistent requirements for these 
error: properties everywhere in your project, especially for install
error: targets.

Not quite sure what's going on, the previous times I've done this it went pretty smooth..
Any ideas?

I'm using linux mint (17.2 x64), boost 1.59 and use it with cmake like so:

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.36.0 COMPONENTS system thread shared_ptr)
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
else()
    message("can not find boost")
endif()

Thanks.

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299

2 Answers2

1

In your boost repo, make sure you've run ./bootstrap.sh with --prefix=<install directory> if you want it in a non default location. You don't need this argument though.

You can run run the ./b2 command from the same directory after this to install boost once again with the --prefix=<install directory> option if required. You may have to remove all previous build files from your build/install directory before trying to do this.

Also, make sure you have the correct version for your machine. I used http://downloads.sourceforge.net/boost/boost_1_58_0.tar.bz2 for mine (OpenSUSE 13.1 64 bit)

Samidamaru
  • 1,061
  • 7
  • 18
  • I've ran `./bootstrap.sh` without the `--prefix` (as the default location is good enough for me), and I downloaded http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz which should be ok for mint. Removing all `*.a` files from `stage/lib` changes nothing. It seems it doesn't like me asking for both debug and release – Nitzan Tomer Oct 07 '15 at 12:19
  • Ah yes, didnt' spot that! I don't think you can ask it to compile it as both debug AND release simultaneously. If you want to do that, I would suggest building boost twice and installing to two different directories so you can choose which one you'd like as and when you need it. It's bad practice to mix debug and release code. – Samidamaru Oct 07 '15 at 12:43
  • But that's the point of the [library naming](http://www.boost.org/doc/libs/1_59_0/more/getting_started/unix-variants.html#library-naming) no? So I'll be able to have different lib versions – Nitzan Tomer Oct 07 '15 at 12:45
  • Try passing --build-type=complete. That should build both libraries :) – Samidamaru Oct 07 '15 at 13:03
  • 1
    I manged to build all using: `./b2 --build-type=complete --layout=versioned` but unfortunately it does not solve my compile errors. – Nitzan Tomer Oct 07 '15 at 14:20
  • Are you building with gcc? What compilation command are you issuing? Make sure you're linking to the libraries too with -lboost_system ? – Samidamaru Oct 07 '15 at 14:31
  • You can find a very similar post on this issue here: http://stackoverflow.com/questions/13467072/c-boost-undefined-reference-to-boostsystemgeneric-category – Samidamaru Oct 07 '15 at 14:32
  • Turns out that cmake wasn't able to find the boost libs, I fixed that and now it works. Thanks – Nitzan Tomer Oct 08 '15 at 07:55
  • @NitzanTomer I'm having similar issues with compiler not finding the boost libs. What did you do to fix it? – OJ7 May 10 '18 at 14:43
  • @OJ7 I really don't remember, it was about 3 years ago – Nitzan Tomer May 10 '18 at 14:56
1

Regarding the reported error: Name clash for '<pstage/lib>libboost_atomic.a':

I'm just summarizing here the explanation and solution (which @Nitzan Tomer gave briefly above, and for which, @Samidamaru 's answer did not provide a resolution).

The problem was about --layout specification. See b2 --help for the --layout option.

On Linux the default layout is system, which means that for all kind of builds, the libraries are created with the schema: libboost_<library-name>.a (or .lib on Windows). It means that the same file would be created both for debug and release variant. Since Nitzan requested both variants by passing variant=debug,release the created files would overwrite each other. b2 reported this as an error.

Summary of various layouts and their effect

+-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+
|                       |                                                                  --layout                                                                        |
+-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+
|                       | versioned                                                                     | tagged                                 | system                  |
+-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+
| Library file name:    | libboost_{lib name}-{toolset}[-mt]-{ABI tag}-{ARCH tag}-{boost ver tag}.lib   | libboost_{lib name}[-mt]-{ABI tag}.lib | libboost_{lib name}.lib |
+-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+
| Header file directory:| include/boost_{boost ver tag}                                                 | include                                | include                 |
+-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+
| Notes:                | Default on Windows.                                                           | Different toolsets (eg. different      | Default on Linux.       |
|                       | All variations can be created in the same folder.                             | compiler versions), architecture and   | All variations must be  |
|                       | See "Library naming" at                                                       | address-model CANNOT be generated in   | created in separate     |
|                       | https://www.boost.org/doc/libs/1_68_0/more/getting_started/unix-variants.html | the same folder. But relase/debug and  | folders.                |
|                       | The corresponding b2 options are also indicated on this page.                 | single/multi-threaded can be.          |                         |
+-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+

Of course on Linux the .a and .so post-fixes are used vs. .lib and .dll on Windows. The lib prefix is omitted from DLL names on Windows. On Windows the single-threaded versions can be created only if the runtime-link=static option was set.

For headers, the "usual" boost directory is still created under the indicated folder.
It means that if you passed e.g. --prefix=/tools/boost to b2, then the following directory structure is created for the versioned layout:

/tools/boost
         |
         +--- lib
         |
         +--- include
                  +--- boost_{boost version tag}
                                    |
                                    +--- boost
                                           +--- accumulators
                                           +--- algorithm
                                           etc.

The boost_{boost version tag} (e.g. boost_1_68) intermediate directory is not created for other layouts.

Leslie N
  • 115
  • 11