MacOS 12.2.2, clang 13.0.0, XCode developer tools are installed. libpqxx was installed with the homebrew and can be found with include, but the linker cannot find the library.
> g++ main.cpp -lpq -lpqxx -I/opt/homebrew/include -std=c++2a
ld: library not found for -lpq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is main.cpp
#include <iostream>
#include <pqxx/pqxx>
using namespace std;
using namespace pqxx;
int main(int argc, char* argv[]) {
try {
connection C("dbname = testdb user = pgtest password = pgtest \
hostaddr = 127.0.0.1 port = 5432");
if (C.is_open()) {
cout << "Opened database successfully: " << C.dbname() << endl;
} else {
cout << "Can't open database" << endl;
return 1;
}
C.close ();
} catch (const std::exception &e) {
cerr << e.what() << std::endl;
return 1;
}
}