Undefined references when linking boost python - c++

I am fairly new to using Linux. But I believe I have done the correct steps to get set up:
wget for Python 3.8.5, did the make for it.
wget for boost 1.74, bootstrap, ./b2
And boost installed and setup everything except for Python which it did not auto-detect. After many hours of frustration, I can get it to find python with:
./bootstrap.sh --with-python=python3.8
running ./b2 --debug-configuration --with-python
shows that it has found it here:
notice: [python-cfg] Details of this Python configuration: notice:
[python-cfg] interpreter command: "/usr/local/bin/python3.8" notice:
[python-cfg] include path: "/usr/local/include/python3.8" notice:
[python-cfg] library path: "/usr/local/lib/python3.8/config"
"/usr/local/lib"
So to this end I am compiling my program successfully with the boost include and python include folder mentioned from b2's debug output above. I am linking similarly with -lpython3.8 -lboost_python38 -lboost_system
All 3 are being found evidently as it does not complain about missing libraries.
Parser.o: In function `_Py_DECREF':
Parser.cpp:(.text+0x5b): undefined reference to `_Py_Dealloc'
Parser.o: In function `sections_to_html(std::__cxx11::list<DivSection, std::allocator<DivSection> > const&)':
Parser.cpp:(.text+0x1eb3): undefined reference to `PyUnicode_FromString'
Parser.cpp:(.text+0x1edf): undefined reference to `PyUnicode_FromString'
Parser.o: In function `PyInit_Parser':
Parser.cpp:(.text+0x245b): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
Parser.o: In function `boost::python::type_info::name() const':
Parser.cpp:(.text._ZNK5boost6python9type_info4nameEv[_ZNK5boost6python9type_info4nameEv]+0x1f): undefined reference to `boost::python::detail::gcc_demangle(char const*)'
Parser.o: In function `boost::python::api::object::object()':
Parser.cpp:(.text._ZN5boost6python3api6objectC2Ev[_ZN5boost6python3api6objectC5Ev]+0x14): undefined reference to `_Py_NoneStruct'
Parser.o: In function `_object* boost::python::expect_non_null<_object>(_object*)':
Parser.cpp:(.text._ZN5boost6python15expect_non_nullI7_objectEEPT_S4_[_ZN5boost6python15expect_non_nullI7_objectEEPT_S4_]+0x14): undefined reference to `boost::python::throw_error_already_set()'
Parser.o: In function `boost::python::tuple boost::python::make_tuple<boost::python::handle<_object>, boost::python::handle<_object> >(boost::python::handle<_object> const&, boost::python::handle<_object> const&)':
Parser.cpp:(.text._ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_[_ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_]+0x2c): undefined reference to `PyTuple_New'
Parser.cpp:(.text._ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_[_ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_]+0x51): undefined reference to `boost::python::api::object::object(boost::python::handle<_object> const&)'
Parser.cpp:(.text._ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_[_ZN5boost6python10make_tupleINS0_6handleI7_objectEES4_EENS0_5tupleERKT_RKT0_]+0xda): undefined reference to `boost::python::api::object::object(boost::python::handle<_object> const&)'
Parser.o: In function `void boost::python::def<boost::python::tuple (*)(char const*)>(char const*, boost::python::tuple (*)(char const*))':
Parser.cpp:(.text._ZN5boost6python3defIPFNS0_5tupleEPKcEEEvS4_T_[_ZN5boost6python3defIPFNS0_5tupleEPKcEEEvS4_T_]+0x50): undefined reference to `boost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)'
Parser.o: In function `boost::python::api::object boost::python::detail::make_function_aux<boost::python::tuple (*)(char const*), boost::python::default_call_policies, boost::mpl::vector2<boost::python::tuple, char const*> >(boost::python::tuple (*)(char const*), boost::python::default_call_policies const&, boost::mpl::vector2<boost::python::tuple, char const*> const&)':
Parser.cpp:(.text._ZN5boost6python6detail17make_function_auxIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS3_S5_EEEENS0_3api6objectET_RKT0_RKT1_ [_ZN5boost6python6detail17make_function_auxIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS3_S5_EEEENS0_3api6objectET_RKT0_RKT1_]+0x67): undefined reference to `boost::python::objects::function_object(boost::python::objects::py_function const&)'
Parser.o: In function `boost::python::objects::py_function_impl_base::py_function_impl_base()':
Parser.cpp:(.text._ZN5boost6python7objects21py_function_impl_baseC2Ev[_ZN5boost6python7objects21py_function_impl_baseC5Ev]+0xb): undefined reference to `vtable for boost::python::objects::py_function_impl_base'
Parser.o:(.data.rel.ro._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE [_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
Parser.o: In function `boost::python::objects::caller_py_function_impl<boost::python::detail::caller<boost::python::tuple (*)(char const*), boost::python::default_call_policies, boost::mpl::vector2<boost::python::tuple, char const*> > >::~caller_py_function_impl()':
Parser.cpp:(.text._ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEED2Ev [_ZN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEED5Ev]+0x22): undefined reference to `boost::python::objects::py_function_impl_base::~py_function_impl_base()'
Parser.o:(.data.rel.ro._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE [_ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFNS0_5tupleEPKcENS0_21default_call_policiesENS_3mpl7vector2IS5_S7_EEEEEE]+0x10): undefined reference to `typeinfo for boost::python::objects::py_function_impl_base'
Parser.o: In function `boost::python::converter::pointer_arg_from_python<char const*>::pointer_arg_from_python(_object*)':
Parser.cpp:(.text._ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC2EP7_object[_ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC5EP7_object]+0x18): undefined reference to `_Py_NoneStruct'
Parser.cpp:(.text._ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC2EP7_object[_ZN5boost6python9converter23pointer_arg_from_pythonIPKcEC5EP7_object]+0x34): undefined reference to `boost::python::converter::get_lvalue_from_python(_object*, boost::python::converter::registration const&)'
Parser.o: In function `boost::python::converter::pointer_arg_from_python<char const*>::operator()() const':
Parser.cpp:(.text._ZNK5boost6python9converter23pointer_arg_from_pythonIPKcEclEv[_ZNK5boost6python9converter23pointer_arg_from_pythonIPKcEclEv]+0x1e): undefined reference to `_Py_NoneStruct'
Parser.o: In function `boost::python::converter::expected_pytype_for_arg<boost::python::tuple>::get_pytype()':
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv]+0x1b): undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argINS0_5tupleEE10get_pytypeEv]+0x32): undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
Parser.o: In function `boost::python::converter::expected_pytype_for_arg<char const*>::get_pytype()':
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x1b): undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
Parser.cpp:(.text._ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv[_ZN5boost6python9converter23expected_pytype_for_argIPKcE10get_pytypeEv]+0x32): undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
Parser.o: In function `boost::python::converter::registration const& boost::python::converter::detail::registry_lookup2<char const volatile>(char const volatile& (*)())':
Parser.cpp:(.text._ZN5boost6python9converter6detail16registry_lookup2IVKcEERKNS1_12registrationEPFRT_vE[_ZN5boost6python9converter6detail16registry_lookup2IVKcEERKNS1_12registrationEPFRT_vE]+0x1f): undefined reference to `boost::python::converter::registry::lookup(boost::python::type_info)'
Parser.o: In function `boost::python::converter::pyobject_type<boost::python::tuple, &PyTuple_Type>::get_pytype()':
Parser.cpp:(.text._ZN5boost6python9converter13pyobject_typeINS0_5tupleEXadL_Z12PyTuple_TypeEEE10get_pytypeEv[_ZN5boost6python9converter13pyobject_typeINS0_5tupleEXadL_Z12PyTuple_TypeEEE10get_pytypeEv]+0x7): undefined reference to `PyTuple_Type'
collect2: error: ld returned 1 exit status
makefile:8: recipe for target 'Parser' failed
make: *** [Parser] Error 1
I see a bunch of boost namespace stuff coming up.
So this leads me to believe that either there is a change in the name mangling between what I've compiled and what is being linked in, or there is a difference with defines which is causing either namespace or other differences.
But I am unsure how to find out the cause, assuming I am correct with my previous assumptions.
EDIT: I had cut the dump short and said that 'most' of it seems to be from boost, but JaMiT called me on it. So theres the full dump.
EDIT 2: I checked my python config and the results are:
user#vm:/usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu$ python python-config.py --cflags
-I/usr/local/include/python3.8 -I/usr/local/include/python3.8 -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall
user#vm:/usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu$ python python-config.py --ldflags
-L/usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu -lcrypt -lpthread -ldl -lutil -lm -lm
EDIT 3:
I used nm on libpython3.8.a from my /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu and found that PyUnicode_FromString and some others do appear correctly as type 'T' function-with-param.
So they are there.

Thanks to a comment by 'sehe' mentioning ordering of libs, I did some Google searching and found the problem - my linking step in the makefile was:
$(CC) $(COMMONFLAGS) $(LDFLAGS) $(LIBS) -o Parser Parser.o grammar.o words.o
The additional libraries I use should come at the end eg:
$(CC) $(COMMONFLAGS) $(LDFLAGS) -o Parser Parser.o grammar.o words.o $(LIBS)
But after fixing the aforementioned ordering of arguments on the linker invocation, I had additional undefined references crop up from within Python which had not been reported before.
This turned out not to be an issue as building an executable was just step one - making sure the code compiles and I can link.
In the end to get a makefile building a module I can import into Python, I needed to compile all cpp files with -fPIC and then link with -shared -export-dynamic
Python's lib was not needed and so my final libs are -lboost_python38 -lboost_system
After setting my LD_LIBRARY_PATH to point to the boost /stage/lib folder, I was able to import my Parser.so module and it worked correctly.

Related

Undefined reference to boost::system::generic_category() although libs are given to g++

What are the linker flags I'm missing here?
I try to compile this on an Ubuntu 18.04 LTS and it fails, it works inside a Debian 9 docker image:
#include <boost/dll.hpp>
// Trying to compile it with:
// g++ -o program -lboost_filesystem -ldl -lboost_system program.cpp
int main() {
boost::dll::program_location();
return 0;
}
The error I get is:
/tmp/ccKlWUUd.o: In function `__static_initialization_and_destruction_0(int, int)':
program.cpp:(.text+0x68): undefined reference to `boost::system::generic_category()'
program.cpp:(.text+0x74): undefined reference to `boost::system::generic_category()'
program.cpp:(.text+0x80): undefined reference to `boost::system::system_category()'
/tmp/ccKlWUUd.o: In function `boost::system::error_code::error_code()':
program.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/ccKlWUUd.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xb8): undefined reference to `boost::system::generic_category()'
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xf3): undefined reference to `boost::system::generic_category()'
/tmp/ccKlWUUd.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xb8): undefined reference to `boost::system::generic_category()'
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xf3): undefined reference to `boost::system::generic_category()'
program.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x1d2): undefined reference to `boost::system::generic_category()'
/tmp/ccKlWUUd.o: In function `boost::dll::detail::report_error(boost::system::error_code const&, char const*)':
program.cpp:(.text._ZN5boost3dll6detail12report_errorERKNS_6system10error_codeEPKc[_ZN5boost3dll6detail12report_errorERKNS_6system10error_codeEPKc]+0x2a): undefined reference to `dlerror'
/tmp/ccKlWUUd.o: In function `boost::filesystem::read_symlink(boost::filesystem::path const&, boost::system::error_code&)':
program.cpp:(.text._ZN5boost10filesystem12read_symlinkERKNS0_4pathERNS_6system10error_codeE[_ZN5boost10filesystem12read_symlinkERKNS0_4pathERNS_6system10error_codeE]+0x36): undefined reference to `boost::filesystem::detail::read_symlink(boost::filesystem::path const&, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
The system here is:
gcc: 7.0.3
boost: 1.65.1
libc6: 2.73
Your build command is in the wrong order, and order matters.
GCC reads left-to-right, taking symbols from libraries when it already knows it needs them. As you put program.cpp last, you don't make that known until all listed libraries have already been identified and discarded.
Put program.cpp first, then the libraries it needs.
g++ -o program program.cpp -lboost_filesystem -ldl -lboost_system
Yes, it's kind of weird. (Even weirder that it worked on Debian! Though apparently only some "recent" Linuxy distributions default --as-needed on, which is what causes the behaviour you see, showing that the behaviour isn't necessarily guaranteed. Perhaps Debian 9 just outright does not do that.)
More info:
Why does the order in which libraries are linked sometimes cause errors in GCC?

"undefined reference to *" Error while compiling file that uses the Open Dynamics Engine v0.13.1

I am a beginner to organizing C++ projects and I have been trying to start an Open Dynamics Engine project for a week now but I keep getting several errors. First, what I have done:
Installed ode-0.13.1 with automake as directed in the manual.
Created a file test.cpp with the code from the bouncing ball HOWTO.
Wrote a makefile to compile.
But when I run my makefile, I get the following errors:
gcc -Wall -g -DdDOUBLE -o test test.o -L/home/username/ode-0.13.1/ode/src/libode.la -L/home/username/ode-0.13.1/drawstuff/src/libdrawstuff.la -L/usr/X11R6/lib -L/usr/lib -L/usr/local/lib -I. -I/home/username/ode-0.13.1/include/ -I/usr/X11R6/include -I/usr/include -lm -lode -lGL -lGLU
/usr/local/lib/libode.a(collision_trimesh_box.o): In function dCalcVectorLength3':
/home/username/ode-0.13.1/ode/src/../../include/ode/odemath.h:148: undefined reference tosqrt'
/home/username/ode-0.13.1/ode/src/../../include/ode/odemath.h:148: undefined reference to sqrt'
/home/username/ode-0.13.1/ode/src/../../include/ode/odemath.h:148: undefined reference tosqrt'
/usr/local/lib/libode.a(util.o): In function dxStepBody(dxBody*, double)':
/home/username/ode-0.13.1/ode/src/util.cpp:618: undefined reference tosincos'
/home/username/ode-0.13.1/ode/src/util.cpp:630: undefined reference to sincos'
/home/username/ode-0.13.1/ode/src/util.cpp:628: undefined reference tosqrt'
/home/username/ode-0.13.1/ode/src/util.cpp:590: undefined reference to `sqrt'
... (and this keeps going for pages)
/usr/local/lib/libode.a(OPC_AABBTree.o): In function Opcode::AABBTree::Build(Opcode::AABBTreeBuilder*)':
/home/username/ode-0.13.1/OPCODE/OPC_AABBTree.cpp:413: undefined reference tooperator new[](unsigned long)'
/home/username/ode-0.13.1/OPCODE/OPC_AABBTree.cpp:427: undefined reference to operator new[](unsigned long)'
/usr/local/lib/libode.a(OPC_AABBTree.o): In functionOpcode::AABBTreeNode::~AABBTreeNode()':
/home/username/ode-0.13.1/OPCODE/OPC_AABBTree.cpp:83: undefined reference to operator delete[](void*, unsigned long)'
/usr/local/lib/libode.a(OPC_Collider.o): In functionOpcode::Collider::~Collider()':
/home/username/ode-0.13.1/OPCODE/OPC_Collider.cpp:54: undefined reference to operator delete(void*, unsigned long)'
/usr/local/lib/libode.a(OPC_Collider.o):(.data.rel.ro._ZTIN6Opcode8ColliderE[_ZTIN6Opcode8ColliderE]+0x0): undefined reference tovtable for __cxxabiv1::__class_type_info'
/usr/local/lib/libode.a(OPC_Collider.o):(.data.rel.ro._ZTVN6Opcode8ColliderE[_ZTVN6Opcode8ColliderE]+0x20): undefined reference to `__cxa_pure_virtual'
collect2: error: ld returned 1 exit status
makefile:14: recipe for target 'test' failed
make: *** [test] Error 1
These errors seem like the library has not been set up correctly, but I'm pretty sure I've properly installed and my -L's are set to the correct paths.
Note 1: the demos included with the ode library work.
Note 2: I've tried (and failed) to install other versions of ode previously. I did my best with make uninstall and make clean to clean these failed installs, but I think they may be affecting new installs because when I run sudo make install for the first time there is an awful lot of Nothing to do here... messages.

How to recompile ntl and gmp libraries with "-fPIC" flag & make HELib as a shared library & undefined reference to func(std::ostream&) error

a C++ code built into a shared library for HELib is using NTL and GMP static library. But it gets following error:
/usr/bin/ld: /usr/local/lib/libntl.a(FFT.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libntl.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
It was suggested int the post Click here
to recompile NTL and GMP with "-fPIC " flags.
I'am not able to find how I should do that.
Edit:
I'm able to build the shared library now after :
recompiling GMP and NTL by:
./configure --enable-shared
for gmp and
./configure SHARED=on
After make Install of HELib. I get error when I run the example codes.
The link to the Makefile : click to see makefile
Error:
g++ -g -O2 -std=c++11 -pthread -DFHE_THREADS -DFHE_BOOT_THREADS -DFHE_DCRT_THREADS -o Test_General_x Test_General.cpp -L/usr/local/lib -lntl -lgmp -lm -lfhe
/usr/local/lib/libfhe.so: undefined reference to write_raw_int(std::ostream&, long, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_ZZ(std::istream&, NTL::ZZ&)'
/usr/local/lib/libfhe.so: undefined reference to void write_raw_vector<long>(std::ostream&, std::vector<long, std::allocator<long> > const&)'
/usr/local/lib/libfhe.so: undefined reference towriteEyeCatcher(std::ostream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_xdouble(std::ostream&, NTL::xdouble)'
/usr/local/lib/libfhe.so: undefined reference toread_ntl_vec_long(std::istream&, NTL::Vec&)'
/usr/local/lib/libfhe.so: undefined reference to void read_raw_vector<long>(std::istream&, std::vector<long, std::allocator<long> >&)'
/usr/local/lib/libfhe.so: undefined reference toreadEyeCatcher(std::istream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to read_raw_int(std::istream&, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_xdouble(std::istream&)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_ZZ(std::ostream&, NTL::ZZ const&)'
/usr/local/lib/libfhe.so: undefined reference towrite_ntl_vec_long(std::ostream&, NTL::Vec const&, long)'
collect2: error: ld returned 1 exit status
Makefile:179: recipe for target 'Test_General_x' failed
make: *** [Test_General_x] Error 1
For NTL v11.5.1 atleast, doing ./configure --help | grep -i pic (as suggested in one of the comments for GMP) did not help at all - it found no matches. However, making a one line change in the file ntl-11.5.1/src/DoConfig (on line 17) from:
'CXXFLAGS' => '-g -O2'
to:
'CXXFLAGS' => '-g -O2 -fPIC',
solved the problem for me.
Marc Glisse provided the answer for the first two parts of the question.For the third part "Undefined Reference error" the answer is I'd not compiled and linked a x.cpp containing the functions that caused the undefined reference into my shared library. hence check : nm -CD /usr/local/lib/libfhe.so to see if these functions are listed with a linking address or not. If not then check which code provides this functionality. Link that code to the shared library.

gnuplot-iostream not linking to boost

Hi I'm trying to use gnuplot-iostream, at the minute I'm just trying to get the code here working. When I try to combile I get errors in the linker saying:
In function `stream<int, boost::iostreams::file_descriptor_flags>':
/usr/include/boost/iostreams/stream.hpp:130: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(int, boost::iostreams::file_descriptor_flags)'
In function `boost::iostreams::file_descriptor_sink boost::iostreams::detail::wrap<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink const&, boost::disable_if<boost::iostreams::is_std_io<boost::iostreams::file_descriptor_sink>, void>::type*)':
/usr/include/boost/iostreams/detail/wrap_unwrap.hpp:53: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `concept_adapter':
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:67: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:38: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `long boost::iostreams::detail::write_device_impl<boost::iostreams::output>::write<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, boost::iostreams::char_type_of<boost::iostreams::file_descriptor_sink>::type const*, long)':
/usr/include/boost/iostreams/write.hpp:121: undefined reference to `boost::iostreams::file_descriptor::write(char const*, long)'
In function `void boost::iostreams::detail::close_impl<boost::iostreams::closable_tag>::close<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, std::_Ios_Openmode)':
/usr/include/boost/iostreams/close.hpp:224: undefined reference to `boost::iostreams::file_descriptor::close()'
In function `std::fpos<__mbstate_t> boost::iostreams::detail::seek_device_impl<boost::iostreams::any_tag>::seek<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, long, std::_Ios_Seekdir, std::_Ios_Openmode)':
/usr/include/boost/iostreams/seek.hpp:137: undefined reference to `boost::iostreams::file_descriptor::seek(long, std::_Ios_Seekdir)'
collect2: ld returned 1 exit status
Note I have boost installed and have previously compiled programs that use iostream.
Any help massively appreciated. Thanks
Ruling out the obvious... are you compiling with g++ -lboost_iostreams? If you can share some information about how the compiler and linker are being invoked it will make it easier to answer your question.
Run into exact problem when tried to use g++ with gnuplot-iostream library.
g++ prog.cpp -L/usr/lib -lboost_filesystem -lboost_system -lboost_iostreams
Resolved the issue for me - the code were compiled successfully with no errors.

Why simple mysql++ code compiles standalone, but not in project?

At first, small program:
#include <mysql++.h>
using namespace mysqlpp;
void mainuu ()
{ Connection conn("mysql", "localhost", "root", "pwd");}
If I compile it as one file in CodeLite or in such way:
g++ -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -o Test mysql_api.cpp
it's ok
but, when I try to build whole project with this file I get this:
g++ -o ./Debug/server ./Debug/main.o ./Debug/log.o ./Debug/packet.o ./Debug/mysql_api.o -L.
./Debug/mysql_api.o: In function `mainuu()':
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::Connection(char const*, char const*, char const*, char const*, unsigned int)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:12: undefined reference to `mysqlpp::Connection::query(char const*)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(char const*, bool)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:13: undefined reference to `mysqlpp::operator<<(mysqlpp::quote_type1, mysqlpp::SQLTypeAdapter const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:19: undefined reference to `mysqlpp::operator<<(std::basic_ostream<char, std::char_traits<char> >&, mysqlpp::String const&)'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
/home/asyler/.codelite/workspace/test/server/mysql_api.cpp:10: undefined reference to `mysqlpp::Connection::~Connection()'
./Debug/mysql_api.o: In function `mysqlpp::Row::operator[](int) const':
/usr/include/mysql++/row.h:328: undefined reference to `mysqlpp::Row::at(unsigned int) const'
./Debug/mysql_api.o: In function `mysqlpp::Query::store()':
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::str(mysqlpp::SQLQueryParms&)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::SQLTypeAdapter::SQLTypeAdapter(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/usr/include/mysql++/query.h:467: undefined reference to `mysqlpp::Query::store(mysqlpp::SQLTypeAdapter const&)'
collect2: ld returned 1 exit status
make[1]: *** [Debug/server] Error 1
make[1]: Leaving directory `/home/asyler/.codelite/workspace/test/server'
make: *** [All] Error 2
Here is CodeLite g++ compiler settings:
-g -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlclient -lmysqlpp -L/usr/lib/mysql -L/usr/lib/mysql++ -lmysql++
Looks like you need to edit CodeLite project settings and add these settings -lmysqlclient -lmysqlpp that you pass in command line. Fill Library Path and Libraries fields on Linker tab.
Those are linker errors.
When you create your final executable, you still must provide references to all library functions, just as you did when you compiled the single translation unit.
So, pass -lmysqlclient -lmysqlpp to g++ this time, too.
If you are using an Integrated Development Environment, configure your project's build settings accordingly. In particular, I see that CodeLite has both "Compiler" and "Linker" build settings. It's "Linker" settings that you're after.
For more information on the build process (i.e. compiling, linking and the difference), read a good C++ book.