Linking c++ libraries (for Wt) in Xcode - c++

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.

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

linking failed with undefined reference to libboost_thread

I am compiling an opensource project to run on my machine which is this project. It requires boost library so I installed the Boost_1_55 library on my ubuntu machine but the compiling process was not successfully finished by printing out some error messages as follows.
libtool: link: g++ -g -O3 -Wall -DKENLM_MAX_ORDER=6 -W -Wall -Wno-sign-compare -I./.. -pthread -I/usr/include -g -O2 -o .libs/query query_main.o ./.libs/libklm.so ../util/.libs/libklm_util.so -lz -L/usr/lib/x86_64-linux-gnu -lboost_program_options -lboost_thread -lboost_system -lpthread -lrt -pthread
../util/.libs/libklm_util.so: undefined reference to `boost::thread::join()'
../util/.libs/libklm_util.so: undefined reference to `boost::thread::~thread()'
./.libs/libklm.so: undefined reference to `boost::thread::start_thread()'
collect2: ld returned 1 exit status
This answer seems the solution for my problem but the result of ls -al /usr/local/lib | grep thread showed me like below.
libboost_thread.a
libboost_thread.so -> libboost_thread.so.1.55.0
libboost_thread.so.1.49.0
libboost_thread.so.1.55.0
I don't know what else to check more. Thank you in advance for your help.
You can try to add /usr/local/lib to LD_LIBRARY_PATH like this
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
You have the static Boost library object (libboost_thread.so) but do you have the Boost development files installed? Check to see if the /usr/include/boost/thread directory exists and has *.hpp files in it. If not you may need to install the libboost-thread-dev package for your distribution or download the header files directly from Boost.org.

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

FLTK not working with Stroustrup headers

I'm currently learning c++ with the book Programming: Principles and Practice Using C++ from Stroustrup and am in chapter 12. I'm now trying since days to get FLTK with the specific headers working.
I have installed FLTK with MacPorts. When i'm trying to compile the code including Simple_window.h, i get the following errors:
bash-3.2# fltk-config --compile main.cpp
/usr/bin/g++-4.2 -arch i386 -I/opt/local/include -pipe -arch i386 -arch i386
-D_THREAD_SAFE -D_REENTRANT -o main main.cpp -arch i386 -arch i386
/opt/local/lib/libfltk.a -lpthread -framework Carbon -framework
ApplicationServices
Undefined symbols:
"vtable for Graph_lib::Window", referenced from:
__ZTVN9Graph_lib6WindowE$non_lazy_ptr in cc1oxcSA.o
(maybe you meant: __ZTVN9Graph_lib6WindowE$non_lazy_ptr)
"vtable for Graph_lib::Button", referenced from:
__ZTVN9Graph_lib6ButtonE$non_lazy_ptr in cc1oxcSA.o
(maybe you meant: __ZTVN9Graph_lib6ButtonE$non_lazy_ptr)
"Simple_window::Simple_window(Point, int, int, String const&)", referenced from:
_main in cc1oxcSA.o
"Graph_lib::Window::draw()", referenced from:
vtable for Simple_windowin cc1oxcSA.o
"typeinfo for Graph_lib::Window", referenced from:
typeinfo for Simple_windowin cc1oxcSA.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I have no idea what this means. I read the answers here (SO). I created the .o files. I'm trying to compile this on Mac OS with fltk-config.
It seems to me that there should be a -l (dash ell) in front of /opt/local/lib/libfltk.a when you invoke the compiler. Or you could replace /opt/local/lib/libfltk.a with -L/opt/local/lib -lfltk which might be more conventional.
I got the FLTK program '12.3 A first example' working on Linux using the following steps:
Download Programming-code.zip from the author's website
then unzip it and go to the Programming-code/GUI folder.
In that folder, add #include <cstdlib> to the file std_lib_facilities.h to avoid an atoi not declared error in the next step
Run make at the command line in the Programming-code/GUI folder. This should create the file libbookgui.a.
Assuming the program is named Example.cpp, run the following command:
gcc `fltk-config --use-forms --use-gl --use-images --ldflags`Example.cpp libbookgui.a
Run the a.out executable
Using a sample program from source code found in a PDF FLTK-Tutorial.pdf
I had to add the following lines to get a clean compile in my Ubuntu Linux.
// 3 includes just below are not in the example but are required
// for a clean compile
#include <Fl/x.H>
#include <stdlib.h>
#include <stdio.h>
You must configure your compile line correctly. FLTK has fltk-config tool to help with the configuration.
fltk-config
to get the help message for fltk-config. Read the output to determine what you need to put in for the compile, the link, and any of the compatibility (gl, glut, forms, etc.) for packages you are using.
Copy this information into your compile command.
You can also use the --compile prgrname.cxx switch to compile directly. Include -g because you will want gdb support.
For example:
fltk-config --cxxflags --ldflags
Gives (for me):
-I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk
Add an output name and the input programs:
gcc -I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk mousedrawtest.cpp mousedraw.cpp -o b.out
While there is less to learn for FLTK, it is not for the faint of heart. Erco's (Greg Ercolano) tutorials are excellent and sample code for many common challenges. http://seriss.com/people/erco/fltk/
http://www.fltk.org/documentation.php/doc-1.1/basics.html
There are a number of other good ones search: FLTK tutorial
When converting from simple sample programs to a real object oriented model, keep in mind scope, particularly for the top level window and its contents.
Today, Wednesday, I know much more about gdb, scope, and namespace than I did on Monday.

Problem linking my code with ARPACK on OSX (using MacPorts for ARPACK)

I am trying to compile a C++ program which invokes the ARPACK library.
My problem is that when everything is linked, some of the symbols in the ARPACK library do not get resolved. They are
__gfortran_transfer_integer
__gfortran_transfer_character
__gfortran_transfer_complex
__gfortran_compare_string
__gfortran_st_write_done
__gfortran_st_write
__gfortran_transfer_real
__gfortran_transfer_array
I did a brute force search on my lib directory, and found no library which provided all of these symbols. A couple of them are provided by libf77blas, and it looks like g95 has some similar symbols (with gfortran replaced by g95), but I am at a complete loss as to what else I might need to install. I am compiling my code with
g++-mp-4.5 -O3 -Wall -Wl,-search_paths_first -headerpad_max_install_names my.o -o my.out -L/opt/local/lib -larpack -lm -L/opt/local/lib -lgsl -lgslcblas -lm -lf77blas -llapack -larpack -lqblas -lsquack
and /opt/local/lib actually has all the libraries I reference.
Has anyone run into this problem, or can point to the solution?
add to linker -lgfortran .................