Opened 3 years ago

Last modified 2 years ago

#337 new defect

Cannot link against clang/libc++ compiled libpqxx (missing symbols)

Reported by: archardlias@… Owned by: jtv
Priority: normal Component: other
Severity: Unusable Keywords:
Cc:

Description

When compiling libpqxx with clang; Debian clang version 3.5.0-9 (tags/RELEASE_350/final) (based on LLVM 3.5.0) Target: x86_64-pc-linux-gnu Thread model: posix Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.7 Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.7.4 Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.8 Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.8.3 Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.9 Found candidate GCC installation: /usr/bin/../lib/gcc/i586-linux-gnu/4.9.1 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.6 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.6.4 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7.4 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.3 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.1 Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.7 Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.7.4 Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.8 Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.8.3 Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/i586-linux-gnu/4.9.1 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.3 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.1 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9 Candidate multilib: .;@m64 Selected multilib: .;@m64

Configuring the libpqxx project with; CC="clang" CXX="clang++" CXXFLAGS="-fPIC -stdlib=libc++" ./configure --disable-documentation

It successfully builds libpqxx.a as it should. But when I link a library against it, it misses two symbols: build.main/libcns-inventory.so: undefined reference to `pqxx::internal::refcount::loseref()' build.main/libcns-inventory.so: undefined reference to `pqxx::internal::refcount::~refcount()'

Linking done as follows; clang++ -o build.tests/run_tests build.tests/main.o build.tests/TestConnection.o build.tests/TestInventory.o -Lbuild.main -Lextern/lib -lc++ -lcns-inventory

extern/lib is where the libpqxx.a is, and I can guarantee it is properly linking, just missing those two symbols which might have something to do with PQXX_HAVE_SHARED_PTR in util.hxx/cxx.

Any Ideas? Bug? Did I miss something?

The current version of libpqxx-dev (4.0.2) in debian (Jessie) blows up because of some weird deps of libboost (tr1/memory) and that one on (<utility>) point at which I gave up, gambling for the newer commit that removed all that.

Best Regards, ~Arlias

Change History (3)

comment:1 Changed 3 years ago by anonymous

Forgot to mention, that there is no way to get a hybrid GCC/Clang situation going, opens up more symbol errors than this variant; build.main/libcns-inventory.so: undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> > const&)' build.main/libcns-inventory.so: undefined reference to `pqxx::basic_transaction::basic_transaction(pqxx::connection_base&, std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> > const&, pqxx::readwrite_policy)' build.main/libcns-inventory.so: undefined reference to `pqxx::transaction_base::exec(std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> > const&, std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> > const&)' build.main/libcns-inventory.so: undefined reference to `pqxx::dbtransaction::fullname(std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> > const&, std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> > const&)'

The only way around this all is avoiding libc++ alltogether, which barrs it from my project, and sticking to the GNU stdlibc++.

Reduces the problem to libc++. Any chance to add support for it?

comment:2 Changed 3 years ago by jtv

These two symbols are hidden, so object files outside the library can't see them. The generation of hidden symbols was broken for a long time and I recently fixed it in trunk. Maybe they accidentally get called inline somewhere, in which case I'll fix that. But here, also on clang 3.5, I'm not getting the errors about missing refcount symbols.

Which leads me to another question: I don't see where you're linking to libpqxx and libpq!

Yes, you've added libpqxx's directory to your link path, but where do you actually link to the libraries? I'd expect to see "-lpqxx" on the command line, and the "-Lextern/lib" just adds a place where the compiler will look for that library. (Similar for libpq).

The tr1/memory include is not BOOST, although depending on your compiler, you may have BOOST's implementation. The tr1/* headers and the tr1 namespace went into the standard with C++11. So nowadays you'd just #include <memory>, as libpqxx's trunk version does.

As for the mixed-compilers scenario, this also looks like you may not be linking to libpqxx. Alternatively it could be the use of incompatible options, particularly if you enable debugging or C++11 support on one compiler but not the other.

comment:3 Changed 2 years ago by iwasz

Had the same linking problems (i.e. this undefined reference to pqxx::connectionpolicy::connectionpolicy). My solution was :

svn co svn://pqxx.org/libpqxx/trunk/ libpqxx-trunk2

export LDFLAGS="-L'/home/iwasz/local/share/llvm/lib/:/home/iwasz/local/lib'"
export LD_LIBRARY_PATH=/home/iwasz/local/lib/:/home/iwasz/local/share/llvm/lib/
export LIBS="-lc++abi"
export CXXFLAGS="-std=c++11 -stdlib=libc++"
export CC=/home/iwasz/local/share/llvm/bin/clang
export CXX=/home/iwasz/local/share/llvm/bin/clang++

./configure --prefix=/home/iwasz/local/ --enable-shared=yes  --with-std --disable-documentation
make clean
make uninstall
make -j8
make install

In my case the problem occured because libpqxx.so was linked against libstdc++ not libc++

I had llvm/clang/libc++ compiled by myself from trunk (3.8.0 now). I also pay attention that all libraries I link against are compiled with clang, and libc++ (Boost for example).

Note: See TracTickets for help on using tickets.