Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static linking is not working, C++20, libpq REL_16_2, #822

Closed
adastreamer opened this issue Apr 23, 2024 · 11 comments
Closed

Static linking is not working, C++20, libpq REL_16_2, #822

adastreamer opened this issue Apr 23, 2024 · 11 comments

Comments

@adastreamer
Copy link

adastreamer commented Apr 23, 2024

Hello, here is what I'm getting linking the static library.

System: Debian
Docker image gcc:13.2 (pre-installed libpq is uninstalled to process build from scratch)

/app/vendor/libpqxx/include/pqxx/strconv.hxx:80: undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/ld: /app/vendor/libpqxx/include/pqxx/strconv.hxx:80: undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/ld: /app/vendor/libpqxx/include/pqxx/strconv.hxx:80: undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/ld: /app/vendor/libpqxx/include/pqxx/strconv.hxx:80: undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/ld: /app/vendor/libpqxx/include/pqxx/strconv.hxx:80: undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/ld: CMakeFiles/server.dir/src/cmd/server.cpp.o:/app/vendor/libpqxx/include/pqxx/strconv.hxx:80: more undefined references to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)' follow
/usr/bin/ld: CMakeFiles/server.dir/src/cmd/server.cpp.o: in function `pqxx::field::view() const &':
/app/vendor/libpqxx/include/pqxx/field.hxx:113: undefined reference to `pqxx::field::c_str() const &'
/usr/bin/ld: /app/vendor/libpqxx/include/pqxx/field.hxx:113: undefined reference to `pqxx::field::size() const'
...
(and much more errors)

Build command I use: ./configure --disable-documentation CXXFLAGS="-std=c++20 -fPIC -O3 -I/app/vendor/postgres/src/interfaces/libpq" --with-postgres-lib=/app/vendor/postgres/src/interfaces/libpq --with-postgres-include=/app/vendor/postgres/src/include --disable-shared --enable-static && make

Then trying to link using CMake with my program:

...
add_library(pqxx OBJECT IMPORTED)
set_target_properties(pqxx PROPERTIES IMPORTED_LOCATION /app/vendor/libpqxx/src/.libs/libpqxx.a)

add_library(pq OBJECT IMPORTED)
set_target_properties(pq PROPERTIES IMPORTED_LOCATION /app/vendor/postgres/src/interfaces/libpq/libpq.a)
...

add_executable(...

target_link_libraries(server pq)
target_link_libraries(server pqxx)

Building and linking via CMake's add_subdirectory produces the same result.

Tried to rebuild using different flags and not using fPIC - the same result.

Does anyone have ideas what is this problem about?

@tt4g
Copy link
Contributor

tt4g commented Apr 23, 2024

A very similar issue was reported, but the cause could not be determined: #820

Does the same problem occur when compiling with other versions of GCC or with Clang?

@jtv
Copy link
Owner

jtv commented Apr 23, 2024

@adastreamer you're using libpqxx straight from its build directory, without installing it... Did you add the include/ directory from the libpqxx build tree to your app's include path?

Without that, the app build won't be able to find libpqxx's configuration header.

@adastreamer
Copy link
Author

A very similar issue was reported, but the cause could not be determined: #820

Does the same problem occur when compiling with other versions of GCC or with Clang?

Yes, tried different versions and standards

@adastreamer
Copy link
Author

@adastreamer you're using libpqxx straight from its build directory, without installing it... Did you add the include/ directory from the libpqxx build tree to your app's include path?

Without that, the app build won't be able to find libpqxx's configuration header.

I do a static build, could you please list the .a/.so libs which describe the missing symbols? And yes, of course, cmake includes directories automatically, but I also tried to pick manually the following directories:

     PUBLIC vendor/libpqxx/include
     PUBLIC vendor/libpqxx/build/include
     PUBLIC vendor/libpqxx/build/include/pqxx

@adastreamer
Copy link
Author

@adastreamer you're using libpqxx straight from its build directory, without installing it... Did you add the include/ directory from the libpqxx build tree to your app's include path?
Without that, the app build won't be able to find libpqxx's configuration header.

I do a static build, could you please list the .a/.so libs which describe the missing symbols? And yes, of course, cmake includes directories automatically, but I also tried to pick manually the following directories:

     PUBLIC vendor/libpqxx/include
     PUBLIC vendor/libpqxx/build/include
     PUBLIC vendor/libpqxx/build/include/pqxx

Anyway, I will double check one more time and provide results if I do not missing anything

@jtv
Copy link
Owner

jtv commented Apr 23, 2024

Note these two details though:

  1. Do not add include/pqxx to your include path. The pqxx part should always be explicit in the #include directive.
  2. Put the build directory's include before the source directory's.

@adastreamer
Copy link
Author

Note these two details though:

  1. Do not add include/pqxx to your include path. The pqxx part should always be explicit in the #include directive.
  2. Put the build directory's include before the source directory's.

I will check and let you know.

@jtv
Copy link
Owner

jtv commented Apr 24, 2024

Thanks.

@adastreamer
Copy link
Author

Thanks.

The issue was related to cmake configuration, especially in regards to the linking stage. Seems like it's not been automatically set in the right order if app consists of multiple libraries. I wrote a simple Makefile and recompiled everything step by step, linked manually, everything seems working.

Sorry for disturbing you.

@jtv
Copy link
Owner

jtv commented Apr 29, 2024

Glad it's resolved @adastreamer .

@jtv
Copy link
Owner

jtv commented May 13, 2024

In #828 we found that the real problem was a bad command line: in that case the compilation was done with g++ -lpqxx -lpq app.cxx. Changing it to g++ app.cxx -lpqxx -lpq solved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants