taocpp / taopq

C++ client library for PostgreSQL
Boost Software License 1.0
265 stars 40 forks source link

fatal error: unresolved external symbol during connection create #59

Closed LSG8 closed 2 years ago

LSG8 commented 2 years ago

I am new to c++ recently downloaded taopq for database connection to an existing cpp code I am using windows and vs2019 so, I have built taopq using cmakelist in vs2019 then included the tao/pq.hpp in my code from the introduction part of github page (https://github.com/taocpp/taopq), I tried to make a connection in my code const auto conn = tao::pq::connection::create("host=, port=, dbname=, user:"); whenever I try to build this, get the following error error LNK2001: unresolved external symbol "public: static class std::shared_ptr __cdecl tao::pq::connection::create(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)" (?create@connection@pq@tao@@SA?AV?$shared_ptr@Vconnection@pq@tao@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@5@@Z) 1>D:\Lahari\work\EQ\EQ C++ db\x64\Release\EQ.exe : fatal error LNK1120: 1 unresolved externals 1>Done building project "EQ.vcxproj" -- FAILED. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== any help??

ColinH commented 2 years ago

Are you linking taopq to your application? This library is not header-only.

LSG8 commented 2 years ago

In the project properties section of visual studio, I have put the include directory of taopq under the 'Additional Include Directories' section. Then in the Linker properties, I have put the lib directory of taopq under the 'Additional Library Directories' section. Is anything else needed?

emmenlau commented 2 years ago

Yes, you need to actually link the library, so add the library to the list of linked libraries. I only know how to do that in cmake. but with google you should find out how its done.

d-frey commented 2 years ago

@LSG8 Is your issue resolved?

LSG8 commented 2 years ago

I am now directly using libpqxx instead of this. Though I think for this error, the suggestion from @emmenlau is important as well as checking the cmake build type for all third party library is also important. This way, I removed all errors from libpqxx. Anyway, you can close this issue.