taocpp / taopq

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

Error: undefined reference to 'WSAPoll', '__imp_WSAGetLastError' #64

Closed s111tend closed 1 year ago

s111tend commented 1 year ago

Hello everyone! I've got a problem while using this library. It may not even be related to it, but i hope, you can help me. While trying to connect to the database I get an error.

in functiontao::pq::connection::wait(bool, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long long, std::ratio<1ll, 1000000000ll> > >)': .../connection.cpp:271: undefined reference to 'WSAPoll' .../connection.cpp:293: undefined reference to '__imp_WSAGetLastError' collect2.exe: error: ld returned 1 exit status`

(connection.cpp is a file of this library after building. Route: cmake-build-debug/_deps/taocpp-taopq-src/src/lib/pq/connection.cpp)

A part of my test code that interacts with db is only dbConnect() function yet. It has no try-catch blocks but i think it doesn't matter. This part of code i took from the docs of this library.

void dbConnect () { const auto conn = tao::pq::connection::create(DB_URL); // DB_URL is a const of a std::string type that contains a url of real database that i have access to const auto users = conn->execute( "SELECT * FROM users"); for( const auto& row : users ) { std::cout << row[ "username" ].as< std::string >() << " is " << row[ "name" ].as< std::string >() << "\n"; } }

I've also tried to insert into a connection string something like "host=... db=... ....", but I always catch the same error(

I googled what is the problem, but i cant find answers. Maybe you know how to solve it. I hope, you can help me. Thanks!

d-frey commented 1 year ago

I'm not a Windows user, so I can't help much. I think that your build system might be missing linking with some system library here or you are using the wrong version of Windows. At least that what it means when the linker ("ld" in your error message) doesn't find a symbol ("WSAPoll") anywhere.

uilianries commented 1 year ago

Interesting error, WSAGetLastError is implemented by Ws2_32 library on Windows. Need to add it to target_link_libraries.

https://github.com/taocpp/taopq/blob/4f05505e83630088d049039a499a591f66f1a56e/src/lib/pq/connection.cpp#L293

uilianries commented 1 year ago

Just provided a hotfix here: https://github.com/taocpp/taopq/pull/65

@s111tend Meanwhile, please, add Ws2_32 to your libraries list to be linked.

s111tend commented 1 year ago

@uilianries, thank you so much! It works! I have some deadlines for this work and you are very timely with your answer! Thanks a lot! Should i close this issue if there is already a solution?

d-frey commented 1 year ago

@uilianries Thank you!