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.0
I downloaded and built libpqxx 8.0.1 like so:
./configure
make
sudo make install
There were no errors that I could see.
I wrote a very simple test program:
#include
#include
#include
using namespace std;
int main (int argc, char *argv [])
{
try
{
pqxx::connection c ("postgresql://user:pw@127.0.0.1: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.cpp
But 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::allocator >, std::initializer_list > >(std::__cxx11::basic_string, std::allocator > const&, std::initializer_list >&&, 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 >)'
/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 > const&, std::vector > 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 1
I 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.la
What could be causing these linker errors? And more importantly, how can I fix it?