Skip to content

Problems with creating a library for PLCNext Engineer

Hello,

I am trying to creating a library for my project. The library is created with C++ and I am using the additional library pqxx for PostgreSQL communication with C++ inside my project. I followed the instructions how to build a C++ library in Eclipse. I am using Windows 11. And i get this kind of error:


[cmake]: PostgresDBLibrary.cpp:(.text._ZN10PostgresDB19PostgresDBComponentD2Ev[_ZN10PostgresDB19PostgresDBComponentD5Ev]+0x118): undefined reference to `pqxx::connection::close()'

[cmake]: c:/sdks/axcf2152/2024.0/sysroots/x86_64-w64-mingw32/usr/bin/arm-pxc-linux-gnueabi/../../libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/11.4.0/ld.exe: CMakeFiles/PostgresDB.dir/intermediate/code/PostgresDBLibrary.cpp.o: in function `_GLOBAL__sub_I_PostgresDBLibrary.cpp':

[cmake]: PostgresDBLibrary.cpp:(.text.startup+0x5a): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'

[cmake]: c:/sdks/axcf2152/2024.0/sysroots/x86_64-w64-mingw32/usr/bin/arm-pxc-linux-gnueabi/../../libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/11.4.0/ld.exe: PostgresDBLibrary.cpp:(.text.startup+0x74): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'

[cmake]: c:/sdks/axcf2152/2024.0/sysroots/x86_64-w64-mingw32/usr/bin/arm-pxc-linux-gnueabi/../../libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/11.4.0/ld.exe: PostgresDBLibrary.cpp:(.text.startup+0xa0): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'

[cmake]: c:/sdks/axcf2152/2024.0/sysroots/x86_64-w64-mingw32/usr/bin/arm-pxc-linux-gnueabi/../../libexec/arm-pxc-linux-gnueabi/gcc/arm-pxc-linux-gnueabi/11.4.0/ld.exe: PostgresDBLibrary.cpp:(.text.startup+0xb4): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'

[cmake]: collect2.exe: error: ld returned 1 exit status

[cmake]: make[2]: *** [CMakeFiles/PostgresDB.dir/build.make:174: libPostgresDB.so] Error 1

[cmake]: make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/PostgresDB.dir/all] Error 2

[cmake]: make: *** [Makefile:136: all] Error 2

Comments

  • Hello fuadh,

    it seems that the compilation of the project "PostgreSQL" with PLCnext SDK fails. I'm not familiar with "PostgreSQL" C++ project but maybe there are members here who can help you. Please note the PLCnext FW provides the SQLite-DB by default, you can simply configure it in PLCnext Engineer Project. Please find the introduction in PLCnext Info Center: DataLogger concept (plcnext.help)

    I hope it helps you.

    BR Eduard

  • i want to communicate the plc device with my database i created on my local machine, thats why im using postgresql. The problem happened when i need to import a library in my code. Is there any way how to solve this problem?

  • Hello fuadh,

    to solve the problems, you need SW-Developer knowledge, you can try to contact the development of PostgreSQL and ask for Support/Compilation: PostgreSQL: Support

    BR Eduard

  • Is there any good tutorial how to create a simple library for PLCnext using additional c++ libraries ?

  • edited June 2024

    Hello fuadh,

    please find the example under following Link:

    CppExamples/Examples/IncludeOpenSourceLibrary/README.md at master · PLCnext/CppExamples · GitHub

    BR Eduard

  • I tried this example you sent me, but it has errors: error C2370: 'ne10_float32_t': redefinition; different storage class and similar errors. I didnt change anything from the library Ne10 and i followed the instructions for Eclipse. Is there anybody who can help with this ?

  • I cross-compiled the Ne10 library on a Debian machine using the SDK for AXCF2152 FW 2024.0, and the instructions in the building.md file. Here are the basic commands that build a static Ne10 library for that platform:

    git clone https://github.com/projectNe10/Ne10.git
    cd Ne10
    mkdir build && cd build
    source /opt/pxc/sdk/AXCF2152/2024.0/environment-setup-*  # your path will be different
    export NE10_LINUX_TARGET_ARCH=armv7
    cmake -DGNULINUX_PLATFORM=ON ..
    make
    

    You should be able to build a shared library (and not the static library) using the NE10_BUILD_STATIC and NE10_BUILD_SHARED cmake flags.

  • I want to cross compile the libpqxx library, but i get this error :

    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\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\test\runner.vcxproj]

    libpqxx-7.9.a(wait.obj) : error LNK2001: unresolved external symbol __imp_WSAGetLastError [C:\Libraries\libpqxx\build\t

    est\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\test\runner.vcxproj]

    C:\Libraries\libpqxx\build\test\Release\runner. : fatal error LNK1120: 3 unresolved externals [C:\Libraries\libpqxx\bui

    ld\test\runner.vcxproj]


    interesting when i use this command for normal compiling :  g++ -o main main.cpp -I"C:\Libraries\libpqxx\include" -I"C:\Program Files\PostgreSQL\16\include" -L"C:\Libraries\libpqxx\lib" -L"C:\Program Files\PostgreSQL\16\lib" -lpqxx -lpq -lws2_32 -std=c++17, it works, but when i use this toolchain i get the error above ?

  • It seems like one if the issues with the libpqxx cross-compilation process will be this:


    These prerequisites would be required for the target platform (i.e. the PLCnext Control device) rather than for the host platform. That would explain why you can build it without cross-compiling - you've probably fulfilled this prerequisite on the host, and in that case you're not cross-compiling for another platform.

    I don't have any ideas on how to make either the libpq library or the full ProgresSQL development package available during the cross-compilation process. You might be able to cross-compile libpq from source, and somehow link to that library during cross-compilation. That is a general cross-compilation issue, not related to PLCnext Technology, so perhaps someone on a ProgresSQL forum can help with that.

Sign In or Register to comment.