XCode unable to compile Poco project, undefined symbols - c++

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++.

Related

undefined symbols " __Unwind_Resume" while linking own dylib with libtool on OSX10.15

Trying to compile code on OSX 10.15. which perfectly works on OSX 10.12 and got stuck. Quite familiar with general concept of linking and problem solving with undefined symbols as very well described here. Using command line tools only, libtool and clang++ are provided by Xcode. Seems to be a problem with my local OSX CLT chain. Tried reinstallation of full Xcode.
Compiling files with:
clang++ -g -Wall -arch x86_64 -o ./Permutation.o Permutation.cpp
clang++ -g -Wall -arch x86_64 -o ./MarchingCubes.o MarchingCubes.cpp
Then linking into shared library with:
libtool -install_name #rpath/libmodelling.dylib -dynamic -L../../../release/lib/ -lstdc++ -lpthread -lz -lm Permutation.o MarchingCubes.o -o ../../../release/lib//libmodelling.dylib
Resulting in
Undefined symbols for architecture x86_64:
"__Unwind_Resume", referenced from:
__ZN13MarchingCubesD2Ev in MarchingCubes.o
Tried several hints from similar questions on stackoverflow such as:
Setting -mmacosx-version-min=10.9, changing -lstdc++ against -lc++, trying g++ face of clang++
libunwind.dylib providing the "undefined symbol" lives in /usr/lib/system on my system which should be found via the umbrella framework System which again the compiler should figure out by himself if correctly understood.
thankful for any suggestion

Compiling error with MPFR package on mac

When I try to compile the newly installed package MPFR I get the following error:
Undefined symbols for architecture x86_64:
"_mpfr_init2", referenced from:
_main 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)
I use Codelite on a macbook pro and I think I successfully installed the package using the instruction on the website.
Any ideas on how to solve it?
From the limited information given, I suspect that you are not linking the MPFR library during the linking phase of main.cpp. What is the exact command you are using?
Make sure that -lmpfr is passed at the end of the clang++ command, like so:
clang++ main.cpp -lmpfr
or:
clang++ main.cpp -c
clang++ main.o -lmpfr
If libmpfr.so is installed in a nonstandard place, then you need to tell the compiler where, using the -L option:
clang++ main.cpp -L"$MPFR_PATH" -lmpfr
or:
clang++ main.cpp -c
clang++ main.o -L"$MPFR_PATH" -lmpfr
If not, then please provide more information.

Trouble building and using Lua for 32-bit on 64-bit OS X

I'm having difficulties using my built Lua.
To build my small project, I'm using:
gcc -m32 -arch i386 -I ~/Documents/lua-5.1.4/include -L ~/Documents/lua-5.1.4/lib -llua -mconsole -sectcreate __TEXT __info_plist ./Info.plist -o LuaProject -masm=intel LuaProject.cpp
I built Lua with "make macosx test". To try to make it build 32-bit, I modified the src/Makefile so that the top became:
CC= gcc
CFLAGS= -m32 -arch i386 -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS= -lm $(MYLIBS)
MYCFLAGS=
MYLDFLAGS= -m32 -arch i386
MYLIBS=
That seemed to make it for 32-bit. All I did was add -m32 -arch i386 to CFLAGS (MYCFLAGS wasn't affecting anything) and -m32 -archi386 to MYLDFLAGS. After it worked for neither -m32 nor -arch i386 individually I added both (perhaps not the best logic) which changed nothing. The build works, so then I "sudo make install local", which creates the nice folders I used to try to compile my project.
The output from gcc ends up being:
Undefined symbols for architecture i386:
"luaL_newstate()", referenced from:
_main in LuaProject-15f700.o
"luaL_openlibs(lua_State*)", referenced from:
_main in LuaProject-15f700.o
"luaL_loadbuffer(lua_State*, char const*, unsigned long, char const*)", referenced from:
_main in LuaProject-15f700.o
"lua_pcall(lua_State*, int, int, int)", referenced from:
_main in LuaProject-15f700.o
ld: symbol(s) not found for architecture i386
I am hopefully including all I need to (lua.h, lauxlib.h, lualib.h) and no errors are thrown about the -llua itself, so I am confused as to why this isn't working.
I didn't want to clutter the question with the full Lua makefile but I can upload it if needed.

Linking c++ libraries (for Wt) in Xcode

I'm sorry to ask a question that resurfaces all over the place in different forms, but this has me tearing my hair out and I've tried every suggestion from all the dark corners of the internet.
I'm trying to use the Wt framework (for web based c++ applications) with Xcode. Its header files are at /usr/local/include and its library files (and boost's) are at /usr/local/lib. I can compile at the terminal with
gcc -o hello testWt.cpp -lstdc++ -lwt.3.3.0 -lwthttp.3.3.0 -lboost_random -lboost_regex -lboost_signals -lboost_system -lboost_thread -lboost_filesystem -lboost_program_options -lboost_date_time
but within Xcode I've had no luck. I've tried:
Adding -I/usr/local/include to the OTHER_C++_FLAGS option
Adding /usr/local/lib to the Library Search Paths option
Adding /usr/local/include to Header Search Paths
Dragging all the libraries (both the .dylib and/or the .a versions) into the "Link Binary with Libraries" section
All combinations of the above
Now, I'm bashing my head against this linker error:
Ld /Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug/Test normal x86_64
cd /Users/charles/tmp/Test
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/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.8.sdk -L/Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug -L/usr/local/lib -F/Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug -filelist /Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Intermediates/Test.build/Debug/Test.build/Objects-normal/x86_64/Test.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -lwt.3.3.0 -lwthttp.3.3.0 -lboost_atomic -lboost_chrono -lboost_context -lboost_date_time -lboost_exception -lboost_filesystem -lboost_graph -lboost_iostreams -lboost_locale -lboost_math_c99 -lboost_math_c99f -lboost_math_c99l -lboost_math_tr1 -lboost_math_tr1f -lboost_math_tr1l -lboost_prg_exec_monitor -lboost_program_options -lboost_python -lboost_random -lboost_regex -lboost_serialization -lboost_signals -lboost_system -lboost_test_exec_monitor -lboost_thread -lboost_timer -lboost_unit_test_framework -lboost_wave -lboost_wserialization -o /Users/charles/Library/Developer/Xcode/DerivedData/Test-dzrqjofmpnjowvcwtscacpwnhtqw/Build/Products/Debug/Test
Undefined symbols for architecture x86_64:
"Wt::WApplication::makeAbsoluteUrl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for HelloApplication in main.o
ld: symbol(s) not found for architecture x86_64
Further than this I cannot get. This is the first time I've used Xcode for development so I may be missing something obvious; I'd be incredibly grateful if someone could point it out!
OK I finally got it. It turns out that the problem was that my program is written using the libc++ libraries whereas the Wt library was built using the older libstdc++.
To fix this, I recompiled boost and Wt using libc++ instead by changing their CMakeLists.txt file, adding the line set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++"). This produced a tonne of warnings, but seemed to work.
After installing these new builds, I made sure that Xcode had -L/usr/local/lib -I/usr/local/include in its Other C++ Flags options and /usr/local/include & /usr/local/lib in 'Header Search Paths' and 'Library Search Paths' respectively. Then, I added the libraries into the "Link Binaries with Library" section. This solved my problem.

library not found for -lboost_system

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