I use Debian Jessie on amd64. I can't build the program, which uses Boost threads. Makefile http://pastebin.com/83h8MeUP returns http://pastebin.com/qffPLnCi . ld can't find -lboost_thread-mt (But g++ can). How can I make ld to see this lib?
Related
I am trying to compile a simple c++ program using g++ which contains boost includes but i am getting the following error. I installed it from the tar file found in the boost site. I get the following error only with the asio library.
$ g++ -std=c++03 -Wall -pedantic -g -O2 tcp.cpp -lboost_system -lboost_date_time -lboost_thread -lboost_asio
/usr/bin/ld: cannot find -lboost_asio
collect2: error: ld returned 1 exit status
Boost Asio is header only.
Drop -lboost_asio
ASIO doesn't have a library built for it, so indicating -lboost_asio as an option doesn't really make sense.
However, ASIO does have a dependency on boost.system, which does require a library be built for it.
Make sure you've properly built the boost library in the first place (correct optimization flags, correct Runtime-Library linking, correct architecture, and so on), and that the generated library files (the .so files, in your case) are accessible to the executable.
I just want to use the boost library to create a shared memory on an ARM system. It work fine if you want to compile it only under ubuntu. However, when I want to cross compile it with TI's CCSv6 and angstrom toolchain, it keep pushing errors.
Because I do not know how to write a makefile for cross compile, I think using TI their own IDE might be a good choice to avoid further problems.
Here is my code and print out of build console.
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <iostream>
using namespace boost::interprocess;
int main()
{
shared_memory_object shdmem{open_or_create, "Boost1", read_write};
shdmem.truncate(1024);
mapped_region region{shdmem, read_write};
}
g++ -std=c++0x -I/usr/include -O0 -g3 -Wall -c -fmessage-length=0 -L /lib -lrt -lpthread -fPIC
The IDE called Code Composer Studio has cross compile settings as below:
Prefix: arm-angstrom-linux-gnueabi-
Path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/armv5te-angstrom-linux-gnueabi
Build Console:
/usr/include/boost/interprocess/shared_memory_object.hpp:309: undefined reference to shm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:315: undefined reference toshm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:327: undefined reference to shm_open'
/usr/include/boost/interprocess/shared_memory_object.hpp:334: undefined reference toshm_open'
collect2: ld returned 1 exit status
make: *** [test] Error 1
undefined reference to shm_open' means it cannot find -lrt for ARM.
In your build command line you need to specify include and library paths to ARM built libraries, not to Ubuntu ones. So -I/usr/include and -L /lib is wrong.
Also you need boost built for ARM, although if you just want to use interprocess library then boost headers should be enough. But you need to copy them into different location because including them from /usr/include includes also other headers specific to Ubuntu.
You can use the cross compiler IDE you mentioned or arm g++ cross compiler which you can install by:
sudo apt-get install g++-arm-linux-gnueabihf. Some headers and libraries for ARM will be installed too.
I'm new to g++ compiler and also trying to start coding with boost.asio libraries, but have some difficulties compiling the code using g++.
I have installed boost libraries usingsudo apt-get install libboost-all-dev and boost folder is located in /usr/include directory, and whole scenario:
geek#ubuntu:~/workspace/HelloBoost/src$ g++ -I /usr/include/ -l boost_asio HelloBoost.cpp
/usr/bin/ld: cannot find -lboost_asio
collect2: ld returned 1 exit status
Thanks for your answers.
Did you read about using boost.asio ? Apparently, it looks like a headers only library, and you only need to link -lboost_system -lboost_regex -lopenssl
I'm using OSX Mountain Lion. I just downloaded, unpacked, and built boost 1.52.0 using the instructions supplied from the boost website: http://www.boost.org/doc/libs/1_52_0/more/getting_started/unix-variants.html. I left the default installation prefix at /usr/local, meaning that the libraries are installed in /usr/local/lib and the header files are in /usr/local/include. I have verified that the libraries and headers are present there and recently modified.
I'm attempting to compile the boost asynchronous I/O example found here: http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/tutorial/tuttimer5/src.html (source).
Here is my compilation command:
g++ -Wall -c -g -I/usr/local/include src/test1.cpp -o src/test1.o
where src/test1.cpp is the example source file. Here is my linking command (and error):
g++ -Wall -L/usr/local/lib -lboost_thread -lboost_system src/test1.o -o bin/test1
Undefined symbols for architecture x86_64:
"boost::thread::~thread()", referenced from:
_main in test1.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I have tried using both Apple's clang++ 4.0 and g++ 4.6.0. I get the same undefined symbol error from both programs.
Other people seem to have had trouble compiling this code sample as well. I am aware of this question: C++ / Boost: Undefined Symbols in example? and this one: Linker error when compiling boost.asio example. However, each of these problems seems to have been fixed by adding the appropriate switches (-lboost_thread and -lboost_system) to the command line. I already have those. I have also tried adding -lpthread without luck.
Thank you for taking time to look at my question! Any help is appreciated. :)
Just ran into this same problem, and I found that reverting to Boost 1.49 fixes the problem. Download links for Boost 1.49 are here:
http://www.boost.org/users/history/version_1_49_0.html
Before installing 1.49, I removed 1.52 by deleting /usr/local/include/boost and /usr/local/lib/*boost*. Not sure what changed between 1.49 and 1.52 to cause this problem, or whether Boost 1.50 or 1.51 will work.
Put the libraries you link with last on the command line.
The GNU linker uses kind of reverse lookup of dependencies, so if file A depends on library B, B should come after A on the command line.
It looks like g++/gcc-mingw is installed but I can't tell how to use it.
I am building a C source file with a windows main proc and I get this error:
g++-3 -mwindows -L/usr/lib/gcc/i686-pc-mingw32 -lmingw32 winmain.c
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld:
cannot find -lmingw32 collect2: ld returned 1 exit status
Or
$ g++-3 -mwindows -L/usr/lib/gcc/i686-pc-mingw32 winmain.c
/tmp/ccyLGxkn.o:winmain.c:(.text+0x21): undefined reference to
`MainWndProc(HWND__*, unsigned int, unsigned int, long)#16' collect2:
ld returned 1 exit status
If I do a list directory on the installed libraries I see this:
$ ls /usr/lib/gcc/ i686-pc-cygwin/ i686-pc-mingw32/
Note: 'i686-pc-mingw32' How do I compile using the mingw32 libraries?
Also, I installed the package: 'gcc-mingw-g++' through the cygwin setup.exe utility, I just don't know how to use it?
Note: I am mostly working with 'cygwin', I would prefer NOT to install the full ming install?
There are actually two sets of projects, the libraries and the actually toolchain. I installed the libraries and not the toolchain.
The libraries are: gcc-mingw-g++
mingw64-i686-gcc is the toolchain
I ran with this command and it worked correctly:
i686-pc-mingw32-g++
i686-w64-mingw32-g++
Or:
i686-w64-mingw32-g++ -mwindows -static -I/opt/jdk/include
-I/opt/jdk/include/win32 -Wl,--add-stdcall-alias -shared -o Hello.dll Hello.cpp