Undefined reference to Boost Thread - c++

I am trying to compile and use the Boost 1.54 libraries and have run into a deadend.
I compiled and installed the libraries like mentioned in the documentation:
./bootstrap.sh
./b2 install
I even tried a complete reinstall using:
./bootstrap.sh
./b2 threading=multi install
I have linked using -lboost_thread and -L*path to boost*/bin.v2/libs
I am still getting the following linker errors:
undefined reference to boost::thread::start_thread_noexcept()
undefined reference to boost::thread::join_noexcept()
I am using gcc 4.6.3 on Ubuntu 12.04 in Eclipse.
Does anyone know how I can fix this?

After quite a bit of pain with the default boost on ubuntu repositories, I installed boost 1.54.0 (from the official webpage) with the default options, and the following worked for me:
g++ test.cpp -o test -L/usr/local/lib/ -lboost_thread
P.S: On Ubuntu 12.04, gcc 4.63.
P.S2: Included in my test.cpp are:
#include "boost/thread/thread.hpp"
#include "boost/bind.hpp"

Related

Unable to statically link boost-locale due to libicu linking errors on Ubuntu 18.04

The following code:
#include <boost/locale.hpp>
int main()
{
using namespace boost::locale;
generator gen;
}
Built with the following flags:
g++ -static -static-libstdc++ -pthread main.cpp -lboost_locale -lboost_system -licuuc -licudata -licui18n
Fails to link with the following errors:
(.text+0x16b8): undefined reference to `icu_60::CacheKeyBase::~CacheKeyBase()'
(.text+0x1c8d): undefined reference to `icu_60::UVector64::~UVector64()'
(.text+0x7dc): undefined reference to `icu_60::UCharsTrie::Iterator::~Iterator()'
...hundreds of other undefined symbols
...(the sample code also has boost linking errors, but let's ignore them, as they only appear in my attempt of reproduction; the real code I have issues with has only icu-related link errors)
I'm using Ubuntu 18.04, with both libboost-all-dev and libicu-dev installed from the Ubuntu repositories.
I'm probably missing some trivial component/flag/library needed to make it link together, but am unable to find it.

Difficulty linking Boost 1.60 on OS X after installing via Homebrew

I have a fresh install of OS X 10.11.4 that I immediately installed the Xcode toolchain on, then Homebrew, then Boost 1.60. In order to test that everything had gone well, I wrote the following code on my Desktop.
#include <iostream>
#include <boost/filesystem.hpp>
int main() {
boost::filesystem::path new_directory("hello");
boost::filesystem::create_directory(new_directory);
}
I then attempted to compile it as I usually have done with the following command.
$ clang++ test.cpp -o test -lboost_system -lboost_filesystem
I received the following error.
test.cpp:3:10: fatal error: 'boost/filesystem.hpp' file not found
#include <boost/filesystem.hpp>
This is how I have always compiled projects that link Boost in the past. I'm assuming that I have probably forgotten a step along the way that allows clang to search a specific path to dynamically link the libraries. What should I change in order for this compilation command to work?
For me, boost has been compiled and installed into a subdirectory of my home directory, so you'll need to modify the paths as appropriate for your homebrew installation:
flags="-std=c++1z -I/${HOME}/local/include -L${HOME}/local/lib -lboost_filesystem -lboost_system"
c++ ${flags} -o jared jared.cpp
First get the location of boost by doing the following:
brew info boost
From the image above, you can see that my location is
/usr/local/Cellar/boost/1.66.0
Then, to compile, use the following:
c++ -I /usr/local/Cellar/boost/1.66.0 main.cpp -o boost

how to force compilation of Boost to use -fPIC

The team on which I work produces a shared library for use in Python. This library is entirely C++ and we use Boost to expose to python. Because we cannot guarantee that our clients have the Boost libraries installed, we pull in the functionality needed from Boost to the shared object file statically. The final stage in compilation will look familiar to many
g++ -o <output> <objects> -Wl,-Bstatic -lboost_python -lboost_regex ... -Wl,-Bdynamic -shared <other_opts>
We've traditionally used our own build of Boost: 1.47. This version is now quite old and so we wish to update. However, oddly, when I install the necessary objects using yum on my CentOS 7 system, I get the following error from gcc:
relocation R_X86_64_32 against '.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
Well, I thought I'd simply download the latest boost (CentOS 7 installs Boost 1.53) and do my own build. This, after all, has always worked for us. I follow the instructions here but I got the same error. How do I force the use of -fPIC for even the static libraries that it builds?
I believe boost automatically uses -fPIC when compiling a shared library (.so file), but the below command uses -fPIC when compiling a static library (.a file) too.
This worked for me on boost 1.46.1:
sudo ./bjam cxxflags=-fPIC cflags=-fPIC -a ... install
The ... is where you add additional flags like threading=multi or --layout=tagged, and optionally the list of projects to build (for example: --with-regex).
Note: using both cflags and cxxflags is unnecessary, only one is needed. See comments below.
Reference links:
https://cmake.org/Wiki/TubeTK/Build_Instructions#Boost_.28optional.29
http://lists.boost.org/boost-users/2010/07/60682.php
Just for convenience, I combined previous answer and comments to it:
sudo ./bjam cxxflags=-fPIC -a --with-system install
--with-system is not necessary, but it's a place where you can add other boost compile options
It works for me at CentOS 7 with boost 1.67
Another solution:
./bootstrap.sh
./b2 cxxflags=-fPIC cflags=-fPIC

Compiling Boost example projects with Cygwin + gcc

While trying to compile the boost asio example project
async_tcp_echo_server.cpp
I get errors like the following:
__MSABI_LONG was not declared in this file scope
BOOST_ASIO_NATIVE_ERROR(ERROR_BROKEN_PIPE)
__MSABI_LONG was not declared in this file scope
BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION ABORTED)
This is with Boost 1.55.0 and gcc version 4.8.3
boost was compiled with gcc and the following commands
./bootstrap.sh
./b2 cxxflags="-D__USE_W32_SOCKETS -D_WIN32_WINNT=0x0501
./b2 install
I attempted to compile the sample project with
gcc -std=C++11 -D__USE_W32_SOCKETS -D_WIN32_WINNT=0x0501 -I C:\boost_1_55_0 C:\boost_1_55_0\boost\asio.hpp async_tcp_echo_server.cpp
I know this is kind of old thread.
I managed to fix it by reinstalling the boost lib via Cygwin setup_x86.exe.
The version I installed is 1.57. And you don't have to put -D option in the command line.
Hope this may help.
1_57 version from cygwin setup doesn't help for me, it gives me fd_set errors.
This is what I tried to make the boost example code work:
add #define __MSABI_LONG(x) x at the top. - chilly, I know :)
add these flags to g++:-D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -std=c++11 -lboost_system -lws2_32
Voila!

Compiling boost_asio/example/ssl/server.cpp on macosx works on linux

server.cpp - http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/server.cpp
I am trying to build this on my mac. Using the following. (builds fine on my ubuntu system)
g++ -I /usr/local/boost/ sslserver.cpp -o sslserver -lboost_system -lssl -lpthread
My libs are located in /usr/local/lib so I tried adding -L /usr/local/lib after the includes. However, I have built other projects before using -lboost_system -lpthread without any issues or specifying the libs.
The error is huge > https://dl.dropbox.com/u/15586644/error.txt
Its mainly lots of deprecated methods warnings - I doubt anything is deprecated.
followed by Undefined symbols for architecture x86_64.
How should I go about building server.cpp on MacOSX?
See
- Why is Apple Deprecating OpenSSL in MacOS 10.7 (Lion)?
Apple is migrating from OpenSSL to Common Crypto, hence depreciated warnings