User1
User1

Reputation: 41193

Can't link libpqxx in MinGW

Using MSYS, I compiled libpq (from compiling postgres). I then compiled libpqxx. Now, I want to create a client that will use libpqxx. libpq seemed to work fine. And, I can compile code with libpqxx. However, linking the libpq client application fails.

Here's my code:


#include <pqxx/pqxx>
#include <iostream>
using namespace std;
using namespace pqxx;

int main() {
    connection Conn("dbname=test");
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

I added a bunch of libs to the link in a vain hope it would suddenly work. Here's what I have so far:

g++ -IC:\msys\1.0\local\pgsql\include -IC:\msys\1.0\local\include -O0 -g3 -Wall -c -fmessage-length=0 -osrc\Controller.o ..\src\Controller.cpp
g++ -LC:\MinGW\lib -LC:\msys\1.0\local\pgsql\lib -LC:\msys\1.0\local\lib -oController.exe src\Controller.o -lws2_32 -lole32 -lpqxx -lpq -loleaut32 -luuid
C:\msys\1.0\local\lib/libpqxx.a(connection_base.o): In function `ZN45_GLOBAL__N__ZN4pqxx16encrypt_passwordERKSsS1_7wait_fdEibP7timeval':
C:/msys/1.0/home/rsolomon/libpqxx/libpqxx-3.0.2/src/connection_base.cxx:1434: undefined reference to `select@20'
C:\msys\1.0\local\lib/libpqxx.a(connection_base.o): In function `ZN4pqxx15connection_base12check_resultERKNS_6resultE':
C:/msys/1.0/home/rsolomon/libpqxx/libpqxx-3.0.2/src/connection_base.cxx:420: undefined reference to `select@20'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1770  ms.  

I'm thinking the -lws2_32 should've gave me the "select@20". Why is the linker so uppity?

Upvotes: 0

Views: 1369

Answers (1)

Martin v. L&#246;wis
Martin v. L&#246;wis

Reputation: 127457

The Unix linker traditionally processes libraries from left to right. So it first considers ws2_32, finds that it has not much use, then goes on to pqxx, and sees that select is undefined and doesn't get defined by any of the later libraries. IOW, try moving ws2_32 to the end of the command line.

Upvotes: 3

Related Questions