cppdb link errors

I have been trying to use cppdb (http://cppcms.com/sql/cppdb/index.html), but I can't get past linking. As an experiment, I tried compiling and running the sample program given in the documentation found here: http://cppcms.com/sql/cppdb/intro.html

I am getting the following error when I try to compile and link:


/bin/ld: /tmp/ccQzoZ2P.o: in function `main':
test.cpp:(.text+0x52): undefined reference to `cppdb::session::session(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/bin/ld: /tmp/ccQzoZ2P.o: in function `cppdb::result& cppdb::result::operator>><std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
test.cpp:(.text._ZN5cppdb6resultrsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERS0_RT_[_ZN5cppdb6resultrsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEERS0_RT_]+0x1f): undefined reference to `cppdb::result::fetch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
/bin/ld: /tmp/ccQzoZ2P.o: in function `int cppdb::result::get<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
test.cpp:(.text._ZN5cppdb6result3getIiEET_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN5cppdb6result3getIiEET_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x3c): undefined reference to `cppdb::result::fetch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&)'
collect2: error: ld returned 1 exit status


This is the command I am using to compile and link:
g++ test.cpp -o test -lcppdb -lcppcms

There is nothing in the cppdb documentation that I could find that indicated what libraries to link against, so I just assumed it was -lcppdb.

Last edited on
Not sure if I can help, but what compiler + version? (what does g++ -v print?)
And what steps did you follow to build the libraries?

This is a complete guess, but if the library was built with C++11, but you're not compiling in C++11 (or vice-versa), there could be some linker errors there.
Last edited on
Output of g++ -v:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /builddir/gcc-9.3.0/configure --build=x86_64-unknown-linux-gnu --enable-fast-character --enable-vtable-verify --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --libexecdir=/usr/lib --libdir=/usr/lib --enable-threads=posix --enable-__cxa_atexit --disable-multilib --with-system-zlib --enable-shared --enable-lto --enable-plugins --enable-linker-build-id --disable-werror --disable-nls --enable-default-pie --enable-default-ssp --enable-checking=release --disable-libstdcxx-pch --with-isl --with-linker-hash-style=gnu --disable-libunwind-exceptions --disable-target-libiberty --enable-serial-configure --enable-languages=c,c++,objc,obj-c++,fortran,lto,go,ada
Thread model: posix
gcc version 9.3.0 (GCC) 


I installed the development package for cppdb from my distro's package manager (xbps)
I actually tried using different standards of C++ (C++0x, C++11, C++14, and C++17) using the -std= argument to g++ to no avail.
I figured it out. Something is up with the package in the repository, so I just built it myself from source and it worked. Thanks!
Glad you got it working. In general, there's really no guarantee that a library made with someone else's compiler will be link successfully with your compiler. There's too many variables at play. I always compile it from source myself when in doubt.
Last edited on
Topic archived. No new replies allowed.