library not found for -lboost_system - c++

I installed boost using macports. The files appear to be in /opt/local/include/boost/
My makefile is no longer working and I get the following error
Undefined symbols:
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in client.o
__static_initialization_and_destruction_0(int, int)in client.o
"boost::system::system_category()", referenced from:
boost::asio::error::get_system_category() in client.o
boost::system::error_code::error_code()in client.o
__static_initialization_and_destruction_0(int, int)in client.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [client] Error 1
at school the solution was to use -lboost_system as an argument to g++, but now that I've taken the project home to my mac, this does not work. I think this is mostly due to the fact that at school the boost files were at usr/local/lib (or somewhere similar).
When I add the -lboost_system argument i get the following message
g++ -I/opt/local/include -lboost_system -o client client.o Packet.o
ld: library not found for -lboost_system
collect2: ld returned 1 exit status
make: *** [client] Error 1
I've tried a few variations using -L and -l, but I can't seem to find a combo that works. At school I also do not have to use -L. I've read a few other posts here about similar problems, but they fixed it by adding -l flags which arent working for me.
Help! thanks!

You're missing a -L/opt/local/lib. You should be able to set the LDFLAGS in your Makefile:
LDFLAGS=-L/opt/local/lib
This assumes that the Boost libraries are in /opt/local/lib of course.
If you're not using the usual CXXFLAGS and LDFLAGS variables in your Makefile, then add the -L/opt/local/lib directly in your final rule:
client: client.o Packet.o
g++ -L/opt/local/lib -o client client.o Packet.o -lboost_system
The -I only tells the compiler where header files are, the linker needs libraries and you use -L for that.

You could try to look for it in your system like this :
/sbin/ldconfig -p | grep boost_system | cut -d\> -f2
if the library is installed, then it should show something like this:
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
or it will show just a blank line
In your case it seems that boost is installed in another place, hence the need for additional linker information, hence the need for the -L switch, if however you have it in /usr/lib, as I have then no need for additional info in makefile

Related

cpp - make with lboost_system - how to make it work

In my cpp project, I have header file with #include <boost/asio.hpp>.
i also got a makefile attached to the project:
CFLAGS:=-c -Wall -Weffc++ -g -std=c++11 -Iinclude
LDFLAGS:=-L/Users/user/Downloads/boost_1_61_0
all: EchoClient
g++ -o bin/echoExample bin/connectionHandler.o bin/echoClient.o $(LDFLAGS)
EchoClient: bin/connectionHandler.o bin/echoClient.o
bin/connectionHandler.o: src/connectionHandler.cpp
g++ $(CFLAGS) -o bin/connectionHandler.o src/connectionHandler.cpp
bin/echoClient.o: src/echoClient.cpp
g++ $(CFLAGS) -o bin/echoClient.o src/echoClient.cpp
.PHONY: clean
clean:
rm -f bin/*
What I need to to in order to make the program compile and run?
Do i need to download boost and put it in some folder?
Do i need to change the value LDFLAGS that inside the makefile to the download boost destination?
This is what i did so far, but it seems wrong because when I run make I get this error:
g++ -o bin/echoExample bin/connectionHandler.o bin/echoClient.o -L/Users/user/Downloads/boost_1_61_0
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
boost::asio::error::get_system_category() in connectionHandler.o
boost::system::error_code::error_code() in connectionHandler.o
___cxx_global_var_init.2 in connectionHandler.o
boost::asio::error::get_system_category() in echoClient.o
___cxx_global_var_init.2 in echoClient.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in connectionHandler.o
___cxx_global_var_init.1 in connectionHandler.o
___cxx_global_var_init in echoClient.o
___cxx_global_var_init.1 in echoClient.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
Am i doing it OK?
I'm tring to run it both in mac and in windows
The folder boost_1_61_0 contains folders: boosts, libs, status, more, tools and more

XCode unable to compile Poco project, undefined symbols

I've been looking for a proper HTTP parser in C++ and today I found that Poco has support for both parsing HTTP requests, setting up a server and also setting up a HTTPS server along with other cool features and I'm eager to start using it.
I've got a problem with compiling a small example though, the project is setup as a stdc++11 project, I've set the header and library search path to /usr/local/include and /usr/local/lib and have linked the libraries themselves in the Other Linker Flags in this order "-lPocoNet -lPocoUtil -lPocoFoundation -lPocoXML -lPocoJSON" the order of which doesn't seem to matter.
The code itself doesn't throw any errors within XCode, it's just when I try to compile it I get these reference errors, I've fixed 38 others of them by adding the libraries to the Other Linker Flags option but these two errors won't go away.
The error I'm getting is the following
Ld /Users/zezioen/Library/Developer/Xcode/DerivedData/NitroServer-gpnzdaqmezqcauegsmrabobsxotk/Build/Products/Debug/NitroServer normal x86_64
cd /Users/zezioen/stack/Projecten/CPP/NitroServer
export MACOSX_DEPLOYMENT_TARGET=10.11
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/zezioen/Library/Developer/Xcode/DerivedData/NitroServer-gpnzdaqmezqcauegsmrabobsxotk/Build/Products/Debug -L/Users/zezioen/stack/Projecten/CPP/NitroServer/lib -L/usr/local/lib -F/Users/zezioen/Library/Developer/Xcode/DerivedData/NitroServer-gpnzdaqmezqcauegsmrabobsxotk/Build/Products/Debug -F/Users/zezioen/stack/Projecten/CPP/NitroServer/lib -filelist /Users/zezioen/Library/Developer/Xcode/DerivedData/NitroServer-gpnzdaqmezqcauegsmrabobsxotk/Build/Intermediates/NitroServer.build/Debug/NitroServer.build/Objects-normal/x86_64/NitroServer.LinkFileList -mmacosx-version-min=10.11 -Xlinker -no_deduplicate -lPocoNet -lPocoUtil -lPocoFoundation -lPocoXML -lPocoJSON -stdlib=libstdc++ -Xlinker -dependency_info -Xlinker /Users/zezioen/Library/Developer/Xcode/DerivedData/NitroServer-gpnzdaqmezqcauegsmrabobsxotk/Build/Intermediates/NitroServer.build/Debug/NitroServer.build/Objects-normal/x86_64/NitroServer_dependency_info.dat -o /Users/zezioen/Library/Developer/Xcode/DerivedData/NitroServer-gpnzdaqmezqcauegsmrabobsxotk/Build/Products/Debug/NitroServer
Undefined symbols for architecture x86_64:
"Poco::Net::HTTPMessage::setContentType(std::string const&)", referenced from:
MyRequestHandler::handleRequest(Poco::Net::HTTPServerRequest&, Poco::Net::HTTPServerResponse&) in main.o
"Poco::Util::Application::handleOption(std::string const&, std::string const&)", referenced from:
vtable for MyServerApp in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What do I have to do in order to get the project to build?
Resolved here - POCO is linked with libc++, application was linking with libstdc++.

/usr/bin/ld: cannot find -lboost_thread-mt

I am trying to link a project with the following command:
g++ build/test.o -o bin/test -pthread -L lib -L /home/alexander/opt/lib -lboost_thread-mt
which results in the following errors:
/usr/bin/ld: cannot find -lboost_thread-mt
collect2: error: ld returned 1 exit status
However, the boost libraries are installed in the directory /home/alexander/opt/lib. Why does the linker do not find the boost libraries? I also tried to link with -I instead if -L with the same outcome...
Content of /home/alexander/opt/lib is /home/alexander/opt/lib/boost_1_57_0.
change libboost_thread-mt to libboost_thread, first find the address of libboost_thread.so and libboost_thread.a then make softlinks to these files in the same address,
so it should be:
ln -s /...libboostSourceFiles.../libboost_thread.so /..RequestTOmtFiles.../libboost_thread-mt.so
it works for other libboost -mt files too, like serialization , iostreams, programoptions

link to boost library

I am trying to build a project using Boost's Asio , but I am getting linking error:
g++ -o homework main.o -L/usr/lib64/qt-3.3/lib -L/usr/X11R6/lib64 -L/home/student/boost_1_46_1/libs -lboost_system -lqt-mt -lXext -lX11 -lm
/usr/bin/ld: cannot find -lboost_system
collect2: ld returned 1 exit status
make: *** [homework] Error 1
How can I resolve the problem?
I think it's a typo. You said -l boost_system in command line, while it should be -lboost_system.
Update:
Nope! I get my answer back. Just found that it's OK to pass -l <libname>. In fact it's equal to -l<libname>. As others said, double-check paths.

unresolved names linking against library but passing obj files directly works fine?

Consider the following g++ invocation (Apple GCC 4.2.1, running on OSX 10.6.5) which works just fine:
g++ -c util/warthog_cfg.cpp -o util/obj/warthog_cfg.o -DOS_MAC -O0 -Wall -Wno-sign-compare -ansi -fmessage-length=0 -m32
g++ main.cpp -o main -I./util util/obj/warthog_cfg.o -m32
Observe that I passed warthog_cfg.o (a required object file) as an argument in the second line. Now I want to put warthog_cfg.o into a library file and link against that. I run the following:
g++ -c util/warthog_cfg.cpp -o util/obj/warthog_cfg.o -DOS_MAC -O0 -Wall -Wno-sign-compare -ansi -fmessage-length=0 -m32
ar -crs lib/libutil.a util/obj/warthog_cfg.o
g++ main.cpp -o ./bin/main -DOS_MAC -O0 -Wall -Wno-sign-compare -ansi -fmessage-length=0 -m32 -L./lib -framework CoreServices -I./TransitC -I./cpd2012/ -I./util -lutil -lutil
Undefined symbols:
"warthog::util::warthog_cfg::print(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in ccI5ycWY.o
"warthog::util::warthog_cfg::warthog_cfg()", referenced from:
_main in ccI5ycWY.o
"warthog::util::warthog_cfg::parse_args(int, char**)", referenced from:
_main in ccI5ycWY.o
"warthog::util::warthog_cfg::~warthog_cfg()", referenced from:
_main in ccI5ycWY.o
_main in ccI5ycWY.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [main] Error 1
The calls appear identical. I thought perhaps the problem is with ar not adding the .o file to the archive. However, otool seems to indicate otherwise. File sizes seem about right too.
otool -I lib/libutil.a
Archive : lib/libutil.a
lib/libutil.a(warthog_cfg.o):
-rw-r--r-- 1 foo staff 5908 10 Sep 18:39 warthog_cfg.o
-rw-r--r-- 1 foo staff 6800 10 Sep 18:35 lib/libutil.a
What's going on here?
I'm not actually seeing you linking the library to the main program.
I don't generally use -L for this (this sets a search path, but I know where the library is). Just add your lib/libutil.a on the linker invocation just like you would another object file. If you want to keep the "search my lib" scheme, add -lutil and hope there's no other util library getting in the way.