Thread: Libpq linker error
I compiled PostgreSQL 7.3.4 libpq for Win 32 using VC++ 7 compiler. Compiler generates a libpq.lib file. Build a simple C program which opens and closes a database connection. When try to link object program and libpq library, following error occurs: ibpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__strdup referenced in function _PQconnectStart libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp__strdup referenced in function _PQfn OLDNAMES.lib(strdup.obi) : error LNK2001: unresolved external symbol __imp__strdup libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__getenv referenced in function _PQsetdbLogin libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol __imp__getenv libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _closesocket@4 referenced in function _connectDBStart libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol _closesocket@4 libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _connect@12 referenced in function _connectDBStart libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _WSAGetLastError@0 referenced in function _connectDBStart libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol _WSAGetLastError@0 libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _socket@12 referenced in function _connectDBStart libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _htons@4 referenced in function _connectDBStart libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol _htons@4 libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function _connectDBStart libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _inet_addr@4 referenced in function _inet_aton libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _ioctlsocket@12 referenced in function _connectMakeNonblocking libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _setsockopt@20 referenced in function _connectNoDelay libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__time referenced in function _connectDBComplete libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol __imp__time libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _htonl@4 referenced in function _PQconnectPoll libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol _htonl@4 libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _getsockname@12 referenced in function _PQconnectPoll libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _getsockopt@20 referenced in function _PQconnectPoll libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__sprintf referenced in function _PQsetenvPoll libpq.lib(fe-exec.obj) : error LNK2001: unresolved external symbol __imp__sprintf libpq.lib(win32.obj) : error LNK2001: unresolved external symbol __imp__sprintf libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__stricmp referenced in function _PQsetenvPoll OLDNAMES.lib(stricmp.obi) : error LNK2001: unresolved external symbol __imp__stricmp libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _send@16 referenced in function _PQrequestCancel libpq.lib(fe-secure.obj) : error LNK2001: unresolved external symbol _send@16 libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol _WSASetLastError@4 referenced in function _PQrequestCancel libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__isspace referenced in function _conninfo_parse libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__strtok referenced in function _parseServiceInfo libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__strncmp referenced in function _parseServiceInfo libpq.lib(fe-exec.obj) : error LNK2001: unresolved external symbol __imp__strncmp libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__fgets referenced in function _parseServiceInfo libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__fopen referenced in function _parseServiceInfo libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _defaultNoticeProcessor libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol __imp__fprintf libpq.lib(encnames.obj) : error LNK2001: unresolved external symbol __imp__fprintf libpq.lib(dllist.obj) : error LNK2001: unresolved external symbol __imp__fprintf libpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol __imp__stat referenced in function _PasswordFromFile OLDNAMES.lib(stat.obi) : error LNK2001: unresolved external symbol __imp__stat libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp__sscanf referenced in function _PQunescapeBytea libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp__isdigit referenced in function _PQunescapeBytea libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp___snprintf referenced in function _parseInput libpq.lib(fe-auth.obj) : error LNK2001: unresolved external symbol __imp___snprintf libpq.lib(fe-misc.obj) : error LNK2001: unresolved external symbol __imp___snprintf libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp__tolower referenced in function _PQfnumber libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp__isupper referenced in function _PQfnumber libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp__strspn referenced in function _PQoidStatus libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp___errno referenced in function _PQoidValue libpq.lib(fe-exec.obj) : error LNK2019: unresolved external symbol __imp__strtoul referenced in function _PQoidValue libpq.lib(pqexpbuffer.obj) : error LNK2019: unresolved external symbol __imp___vsnprintf referenced in function _printfPQExpBuffer libpq.lib(fe-auth.obj) : error LNK2019: unresolved external symbol __imp__perror referenced in function _pg_password_sendauth libpq.lib(fe-auth.obj) : error LNK2019: unresolved external symbol __imp__GetUserNameA@8 referenced in function _fe_getauthname libpq.lib(fe-secure.obj) : error LNK2019: unresolved external symbol _recv@16 referenced in function _pqsecure_read libpq.lib(fe-misc.obj) : error LNK2019: unresolved external symbol _ntohl@4 referenced in function _pqGetInt libpq.lib(fe-misc.obj) : error LNK2019: unresolved external symbol _ntohs@4 referenced in function _pqGetInt libpq.lib(fe-misc.obj) : error LNK2019: unresolved external symbol ___WSAFDIsSet@8 referenced in function _pqReadReady libpq.lib(fe-misc.obj) : error LNK2019: unresolved external symbol _select@20 referenced in function _pqReadReady libpq.lib(encnames.obj) : error LNK2019: unresolved external symbol __imp__isalnum referenced in function _clean_encoding_name OLDNAMES.lib(strdup.obi) : error LNK2001: unresolved external symbol __imp___strdup OLDNAMES.lib(stricmp.obi) : error LNK2001: unresolved external symbol __imp___stricmp OLDNAMES.lib(stat.obi) : error LNK2001: unresolved external symbol __imp___stat example.exe : fatal error LNK1120: 46 unresolved externals I don't know if additional postgre libraries are missing. I appreciate some help. Best Regards. __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html
On Wed, Feb 11, 2004 at 07:46:04AM -0800, Daniel Gerardo Lucero Baylon wrote: > I compiled PostgreSQL 7.3.4 libpq for Win 32 using VC++ 7 compiler. > > Compiler generates a libpq.lib file. Build a simple C program which opens and > closes a database connection. > > When try to link object program and libpq library, following error occurs: > > ibpq.lib(fe-connect.obj) : error LNK2019: unresolved external symbol > __imp__strdup referenced in function _PQconnectStart Looks like you may not be linking your program against the standard system libraries. In this example, PQconnectStart is who's complaining about a missing function--it's not the function being complained about. Jeroen
I noticed that when compile a C program that uses libpq static library, linker need following libraries: libpq.lib msvcrt.lib advapi32.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib uuid.lib If somebody gets same problem, maybe this could be helpful. Regards. __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html
I solved my problem. Regards __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html
> I noticed that when compile a C program that uses libpq > static library, linker need following libraries: > > libpq.lib > msvcrt.lib > advapi32.lib > wsock32.lib > kernel32.lib > user32.lib > gdi32.lib > winspool.lib > uuid.lib > > If somebody gets same problem, maybe this could be helpful. These are all the standard libraries used by almost all windows programs. The only "non windows" library is msvcrt which is the MS Visual C runtime, used by all programs made with MSVC. Just link with them, and your program should work fine, no? What specifically is your problem? //Magnus