jtv / libpqxx

The official C++ client API for PostgreSQL.
http://pqxx.org/pqxx/
BSD 3-Clause "New" or "Revised" License
988 stars 233 forks source link

Cross compile of the pqxx in c++ for arm7 #865

Open fuadsmed opened 3 weeks ago

fuadsmed commented 3 weeks ago

I want to use the library libpqxx in my plc next project, and i used the toolchain of the plc next and after i followed the instructions how to build my library:

$env:ARP_TOOLCHAIN_ROOT = "C:/SDKs/AXCF2152/2024.0"

cd C:\Libraries\libpqxx\build_arm cmake -DCMAKE_TOOLCHAIN_FILE=C:/SDKs/AXCF2152/2024.0/toolchain.cmake -DCMAKE_INSTALL_PREFIX=C:/Libraries/libpqxx_arm -DPostgreSQL_INCLUDE_DIR="C:/Program Files/PostgreSQL/16/include" -DPostgreSQL_LIBRARY="C:/Program Files/PostgreSQL/16/lib/libpq.lib" ..

cmake --build . --config Release

After the last command i got this at the end:

libpqxx-7.9.a(connection.obj) : error LNK2019: unresolved external symbol imp_ioctlsocket referenced in function "pub lic: void cdecl pqxx::connection::set_blocking(bool)& " (?set_blocking@connection@pqxx@@QEGAAX_N@Z) [C:\Libraries\lib pqxx\build_arm\test\runner.vcxproj] libpqxx-7.9.a(connection.obj) : error LNK2019: unresolved external symbol imp_WSAGetLastError referenced in function "public: void cdecl pqxx::connection::set_blocking(bool)& " (?set_blocking@connection@pqxx@@QEGAAX_N@Z) [C:\Libraries \libpqxx\build_arm\test\runner.vcxproj] libpqxx-7.9.a(wait.obj) : error LNK2001: unresolved external symbol imp_WSAGetLastError [C:\Libraries\libpqxx\build_a rm\test\runner.vcxproj] libpqxx-7.9.a(wait.obj) : error LNK2019: unresolved external symbol imp_WSAPoll referenced in function "void __cdecl pqxx::internal::wait_fd(int,bool,bool,unsigned int,unsigned int)" (?wait_fd@internal@pqxx@@YAXH_N0II@Z) [C:\Libraries\l ibpqxx\build_arm\test\runner.vcxproj] C:\Libraries\libpqxx\build_arm\test\Release\runner. : fatal error LNK1120: 3 unresolved externals [C:\Libraries\libpqxx \build_arm\test\runner.vcxproj]

i tried to change the CMakeLists and everything, but nothing happened.

i tried the instructions so i can include the library into my plc next project, because i cant build my project without the proper library.

tt4g commented 3 weeks ago

When cross-compiling, it is necessary to prepare and build the environment according to the compile target host.

It was not clear to me what was missing in your procedure, there was no mention of cross-compilation of PLC Next in the official CMake documentation: https://cmake.org/cmake/help/v3.30/manual/cmake-toolchains.7.html

I recommend asking the PLC Next community how to solve this problem. Because there are no experts here on PLC Next, and I don't think anyone here knows why the cross-compilation is not succeeding.

jtv commented 3 weeks ago

The errors make it look as if this is a build for a Windows ARM system. Is that correct? For some reason the Windows networking library does not seem to be present.

I don't know too much about this kind of situation, but a few things may be worth checking: Perhaps one or more of the Windows socket libraries is actually for a different architecture. Could be a subtle architecture difference, such as between different ARM versions. Or one of those system library files is missing or truncated. And of course it's important that the the libraries in the build are either all debug builds, or all release builds. Mixing those binaries won't work.

jtv commented 2 weeks ago

Oh @fuadsmed another thing to make really sure of: make sure you're not just using your cross-compiler, but also that you're using the cross-compiler's linker.