ARTICLE AD BOX
Here is my compiler version and operating system (running on a raspberry pi Compute Module 5):
$ g++ --version g++ (Debian 14.2.0-19) 14.2.0I downloaded and built libpqxx 8.0.1 like so:
./configure make sudo make installThere were no errors that I could see.
I wrote a very simple test program:
#include <iostream> #include <stdexcept> #include <pqxx/pqxx> using namespace std; int main (int argc, char *argv []) { try { pqxx::connection c ("postgresql://user:[email protected]:5432/db"s); } catch (exception *e) { cout << e->what () << "\n"; } }and a simple makefile:
process-articles : process-articles.o g++ -o process-articles process-articles.o -l pqxx -l pq process-articles.o : process-articles.cpp g++ -std=c++23 -c -o process-articles.o process-articles.cppBut it gave me a bunch of linker errors:
$ make g++ -std=c++23 -c -o process-articles.o process-articles.cpp g++ -o process-articles process-articles.o -l pqxx -l pq /usr/bin/ld: process-articles.o: in function `pqxx::connection::~connection()': process-articles.cpp:(.text._ZN4pqxx10connectionD2Ev[_ZN4pqxx10connectionD5Ev]+0x18): undefined reference to `pqxx::connection::close(std::source_location)' /usr/bin/ld: process-articles.o: in function `pqxx::connection::connection<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::initializer_list<std::pair<char const*, char const*> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::initializer_list<std::pair<char const*, char const*> >&&, std::source_location)': process-articles.cpp:(.text._ZN4pqxx10connectionC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location[_ZN4pqxx10connectionC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location]+0xcc): undefined reference to `pqxx::internal::check_libpqxx_version(int, int, int, std::basic_string_view<char, std::char_traits<char> >)' /usr/bin/ld: process-articles.cpp:(.text._ZN4pqxx10connectionC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location[_ZN4pqxx10connectionC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location]+0x100): undefined reference to `pqxx::internal::connection_string_parser::connection_string_parser(char const*, std::source_location)' /usr/bin/ld: process-articles.cpp:(.text._ZN4pqxx10connectionC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location[_ZN4pqxx10connectionC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location]+0x110): undefined reference to `pqxx::internal::connection_string_parser::parse() const' /usr/bin/ld: process-articles.cpp:(.text._ZN4pqxx10connectionC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location[_ZN4pqxx10connectionC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location]+0x2a4): undefined reference to `pqxx::connection::init(std::vector<char const*, std::allocator<char const*> > const&, std::vector<char const*, std::allocator<char const*> > const&, std::source_location)' /usr/bin/ld: process-articles.cpp:(.text._ZN4pqxx10connectionC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location[_ZN4pqxx10connectionC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location]+0x2b4): undefined reference to `pqxx::internal::connection_string_parser::~connection_string_parser()' /usr/bin/ld: process-articles.cpp:(.text._ZN4pqxx10connectionC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location[_ZN4pqxx10connectionC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt16initializer_listISt4pairIPKcSB_EEEERKT_OT0_St15source_location]+0x2f8): undefined reference to `pqxx::internal::connection_string_parser::~connection_string_parser()' collect2: error: ld returned 1 exit status make: *** [makefile:2: process-articles] Error 1I checked to see where the linker was looking for its files:
$ ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012 SEARCH_DIR("=/usr/local/lib/aarch64-linux-gnu") SEARCH_DIR("=/lib/aarch64-linux-gnu") SEARCH_DIR("=/usr/lib/aarch64-linux-gnu") SEARCH_DIR("=/usr/local/lib") SEARCH_DIR("=/lib") SEARCH_DIR("=/usr/lib") SEARCH_DIR("=/usr/aarch64-linux-gnu/lib")The libraries appear to be there:
$ ls -l /usr/local/lib/ -rw-r--r-- 1 root root 58387026 Apr 27 15:32 libpqxx.a -rwxr-xr-x 1 root root 890 Apr 27 15:32 libpqxx.laWhat could be causing these linker errors? And more importantly, how can I fix it?
