-
July 16th, 2012, 06:08 PM
#1
Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Hi,
Code I using:
Code:
#include <iostream>
#include <string>
#include <pqxx/pqxx>
using namespace std;
int main(){
try
{
pqxx::connection c ("user=postgres password=postgres dbname=myDB hostaddr=192.168.1.121 port=5432");
}
catch(exception e)
{
}
}
Error Generated:
Code:
1>------ Build started: Project: db64practice, Configuration: Release x64 ------
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __cdecl pqxx::connect_direct::do_startconnect(struct pg_conn *)" (?do_startconnect@connect_direct@pqxx@@UEAAPEAUpg_conn@@PEAU3@@Z)
1>dbConnect.obj : error LNK2001: unresolved external symbol "protected: void __cdecl pqxx::connection_base::close(void)" (?close@connection_base@pqxx@@IEAAXXZ)
1>dbConnect.obj : error LNK2001: unresolved external symbol "protected: void __cdecl pqxx::connection_base::init(void)" (?init@connection_base@pqxx@@IEAAXXZ)
1>dbConnect.obj : error LNK2001: unresolved external symbol "protected: __cdecl pqxx::connection_base::connection_base(class pqxx::connectionpolicy &)" (??0connection_base@pqxx@@IEAA@AEAVconnectionpolicy@1@@Z)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl pqxx::connectionpolicy::is_ready(struct pg_conn *)const " (?is_ready@connectionpolicy@pqxx@@UEBA_NPEAUpg_conn@@@Z)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __cdecl pqxx::connectionpolicy::do_disconnect(struct pg_conn *)" (?do_disconnect@connectionpolicy@pqxx@@UEAAPEAUpg_conn@@PEAU3@@Z)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __cdecl pqxx::connectionpolicy::do_dropconnect(struct pg_conn *)" (?do_dropconnect@connectionpolicy@pqxx@@UEAAPEAUpg_conn@@PEAU3@@Z)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __cdecl pqxx::connectionpolicy::do_completeconnect(struct pg_conn *)" (?do_completeconnect@connectionpolicy@pqxx@@UEAAPEAUpg_conn@@PEAU3@@Z)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl pqxx::connectionpolicy::~connectionpolicy(void)" (??1connectionpolicy@pqxx@@UEAA@XZ)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: __cdecl pqxx::connectionpolicy::connectionpolicy(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0connectionpolicy@pqxx@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl pqxx::errorhandler::~errorhandler(void)" (??1errorhandler@pqxx@@UEAA@XZ)
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: __cdecl pqxx::errorhandler::errorhandler(class pqxx::connection_base &)" (??0errorhandler@pqxx@@QEAA@AEAVconnection_base@1@@Z)
1>f:\visual studio 2010\Projects\db64practice\x64\Release\db64practice.exe : fatal error LNK1120: 12 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Visual Studio Configurations:
Code:
<Release>
C/C++ -> General: G:\libpqxx-4.0\include\pqxx
G:\libpqxx-4.0\config\sample-headers\compiler\VisualStudio2010\pqxx
LINKER -> General: G:\libpqxx-4.0\lib
C:|\PostgreSQL\9.1\lib
LINKER -> General -> input -> Additional Dependacies: libpqxx.lib
libpqxx_static.lib
libpq.lib
----------------------------------------------------------------------------------------
<Debug>
C/C++ -> General: G:\libpqxx-4.0\include\pqxx
G:\libpqxx-4.0\config\sample-headers\compiler\VisualStudio2010\pqxx
LINKER -> General: G:\libpqxx-4.0\lib
C:|\PostgreSQL\9.1\lib
LINKER -> General -> input -> Additional Dependacies: libpqxxD.lib
I copied the pqxx folder into the VS include folder.
I copied some of the lib files into the project folder's release and debug folders
Also, I installed postgresql for 32bit and 64bit OS. The visual studio version is 32bit. I tried to connect to both versions of postgresql, same error
Any suggestions would be appreciated, thanks
-
July 16th, 2012, 10:04 PM
#2
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Originally Posted by Momentum
I copied the pqxx folder into the VS include folder.
Why do you need to copy anything to the Visual Studio folders? Those files can live by themselves where they are -- there is no need to pollute your Visual C++ directories with third-party files.
The visual studio version is 32bit.
Not relevant. There is only one version of Visual Studio, and that is 32-bit.
I tried to connect to both versions of postgresql, same error
Not relevant. A "connection" only makes sense when the program is actually running.
Any suggestions would be appreciated, thanks
Those are linker errors, not compiler errors, and it has nothing to do with "connecting".
Supply the proper library that has those functions implemented to the linker, as obviously you did not do this (either the linker doesn't find those lib files, or those lib files are not 64-bit library files, or those lib files do not have those functions, or those library files are not meant for Visual C++ but for some other compiler). That is the only answer that fixes the problem.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; July 16th, 2012 at 10:07 PM.
-
July 17th, 2012, 05:45 PM
#3
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Thanks for the reply.
I supplied the linker with the proper library files, what else is there to do?
The x64 reference in the error output is due to me changing the platform between win32 and x64 in VS while troubleshooting. Both options makes the same error
Code:
<Release>
C/C++ -> General: G:\libpqxx-4.0\include\pqxx
G:\libpqxx-4.0\config\sample-headers\compiler\VisualStudio2010\pqxx
LINKER -> General: G:\libpqxx-4.0\lib
C:|\PostgreSQL\9.1\lib
LINKER -> General -> input -> Additional Dependacies: libpqxx.lib
libpqxx_static.lib
libpq.lib
----------------------------------------------------------------------------------------
<Debug>
C/C++ -> General: G:\libpqxx-4.0\include\pqxx
G:\libpqxx-4.0\config\sample-headers\compiler\VisualStudio2010\pqxx
LINKER -> General: G:\libpqxx-4.0\lib
C:|\PostgreSQL\9.1\lib
LINKER -> General -> input -> Additional Dependacies: libpqxxD.lib
-
July 17th, 2012, 07:39 PM
#4
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Originally Posted by Momentum
Thanks for the reply.
I supplied the linker with the proper library files,
No you didn't. If you did, there would be no error.
Regards,
Paul McKenzie
-
July 17th, 2012, 07:47 PM
#5
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Originally Posted by Momentum
The x64 reference in the error output is due to me changing the platform between win32 and x64 in VS while troubleshooting. Both options makes the same error
First, are these library files import libraries or static libraries? If they are static libraries, then they must be built using the same compiler, compiler version, etc. that you're using to build your application. If they are import libraries, then they must be compatible with Visual Studio.
Second, you cannot mix 32-bit libraries with 64-bit code and vice-versa.
Third, why does the release version uses 3 libraries, but the debug version only uses 1 library?
Regards,
Paul McKenzie
-
July 17th, 2012, 08:23 PM
#6
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
These files are import files. There's one version of the library for windows.
The release version should only have libpqxx.lib & libpq.lib, not static versions. But since I've been having problems, I tried troubleshooting the problem by placing/removing some of the extra libs. There is a static version of debug file, but since I'm not using the static setup, I removed it
-
July 18th, 2012, 01:13 AM
#7
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Originally Posted by Momentum
These files are import files. There's one version of the library for windows.
Then it is either a 32-bit or x64, not any mixture of them.
So I guess you just don't have appropriate library to build x64 application.
Victor Nijegorodov
-
July 18th, 2012, 05:33 PM
#8
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
But I'm not building x64 application. That's the result of me troubleshooting, after win32 setup was not working.
The link2001 error occurs with win32 setup too. But the functions are somewhat different
Code:
1>------ Build started: Project: db64practice, Configuration: Release Win32 ------
02
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __thiscall pqxx::connect_direct::do_startconnect(struct pg_conn *)" (?do_startconnect@connect_direct@pqxx@@UAEPAUpg_conn@@PAU3@@Z)
03
1>dbConnect.obj : error LNK2001: unresolved external symbol "protected: void __thiscall pqxx::connection_base::close(void)" (?close@connection_base@pqxx@@IAEXXZ)
04
1>dbConnect.obj : error LNK2001: unresolved external symbol "protected: void __thiscall pqxx::connection_base::init(void)" (?init@connection_base@pqxx@@IAEXXZ)
05
1>dbConnect.obj : error LNK2001: unresolved external symbol "protected: __thiscall pqxx::connection_base::connection_base(class pqxx::connectionpolicy &)" (??0connection_base@pqxx@@IAE@AAVconnectionpolicy@1@@Z)
06
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall pqxx::connectionpolicy::is_ready(struct pg_conn *)const " (?is_ready@connectionpolicy@pqxx@@UBE_NPAUpg_conn@@@Z)
07
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __thiscall pqxx::connectionpolicy::do_disconnect(struct pg_conn *)" (?do_disconnect@connectionpolicy@pqxx@@UAEPAUpg_conn@@PAU3@@Z)
08
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __thiscall pqxx::connectionpolicy::do_dropconnect(struct pg_conn *)" (?do_dropconnect@connectionpolicy@pqxx@@UAEPAUpg_conn@@PAU3@@Z)
09
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual struct pg_conn * __thiscall pqxx::connectionpolicy::do_completeconnect(struct pg_conn *)" (?do_completeconnect@connectionpolicy@pqxx@@UAEPAUpg_conn@@PAU3@@Z)
10
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall pqxx::connectionpolicy::~connectionpolicy(void)" (??1connectionpolicy@pqxx@@UAE@XZ)
11
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: __thiscall pqxx::connectionpolicy::connectionpolicy(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0connectionpolicy@pqxx@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
12
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall pqxx::errorhandler::~errorhandler(void)" (??1errorhandler@pqxx@@UAE@XZ)
13
1>dbConnect.obj : error LNK2001: unresolved external symbol "public: __thiscall pqxx::errorhandler::errorhandler(class pqxx::connection_base &)" (??0errorhandler@pqxx@@QAE@AAVconnection_base@1@@Z)
14
1>f:\visual studio 2010\Projects\db64practice\Release\db64practice.exe : fatal error LNK1120: 12 unresolved externals
-
July 18th, 2012, 11:44 PM
#9
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Originally Posted by Momentum
But I'm not building x64 application.
So why did you show us this:
Code:
1>------ Build started: Project: db64practice, Configuration: Release x64 ------
The bottom line is that the libraries you're using do not contain those functions that have the signatures that the linker is looking for or you're just not linking in those libraries. It's one or the other, there is no other reason for those errors. Those libraries are third-party libraries, so we have no idea even if they are valid, so all of this effort could all be for nothing.
Start from the beginning --
1) remove all of those libraries from the linker settings.
2) Go to the linker settings and set the "Show Progress" to show all the messages.
3) Rebuld and look at the linker errors and messages.
4) Add one library until you see the number of errors from the linker being changed or reduced.
5) Go to step 3) and repeat.
Then at least you know what is happening in the build process.
Regards,
Paul McKenzie
-
July 19th, 2012, 08:39 AM
#10
Re: Visual Studio LNK2001 Error When Compiling With Libpqxx Library
Solved it. Thanks for your efforts guys.
I did the whole thing over again
Before proceeding, I made sure of the following:
- installed 32bit - Postgresql
- make sure visual studio platform configuration is win32 and not x64 [Look in configuration manager in project properties]
The links below are the project property values I used
Copy all the files from the bin folder of the 32bit - Postgresql to the release folder of the visual studio project that you're using the libpqxx library on
[don't copy the .exe and .txt files] see below link to view what was included in the release folder
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|