gccsdkopc-uaopcopen62541

The OPC UA open62541 historical data reading client is not compiled


On the library's website, the documentation provides options for functions for accessing historical data reading. There is also an example of using historical data reading in the repository. I've simplified this example from the repository a bit, but I still can't compile it.

#include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>

#include <stdio.h>
#include <stdlib.h>

static UA_Boolean readHist(UA_Client *client, const UA_NodeId *nodeId, UA_Boolean moreDataAvailable, const UA_ExtensionObject *data, void *unused)
{
    printf("\nRead historical callback:\n");
    printf("\tHas more data:\t%d\n\n", moreDataAvailable);

    return true;
}

int main(int argc, char *argv[])
{
    UA_Client *client = UA_Client_new();
    UA_ClientConfig_setDefault(UA_Client_getConfig(client));

    UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:62544");
    if (retval != UA_STATUSCODE_GOOD)
    {
        UA_Client_delete(client);
        return EXIT_FAILURE;
    }

    UA_NodeId node = UA_NODEID_STRING(1, "MyTag");

    retval = UA_Client_HistoryRead_raw(client, &node, readHist, UA_DateTime_fromUnixTime(0), UA_DateTime_now(), UA_STRING_NULL, false, 10, UA_TIMESTAMPSTORETURN_BOTH, (void*) UA_FALSE);

    if (retval != UA_STATUSCODE_GOOD)
    {
        printf("Failed. %s\n", UA_StatusCode_name(retval));
    }

    UA_Client_disconnect(client);
    UA_Client_delete(client);
    return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}

Compilation result:

01:02:53 **** Incremental Build of configuration Debug for project open62541 ****
Info: Internal Builder is used for build
gcc -std=c99 -DUA_ARCHITECTURE_WIN32 -DUA_ENABLE_HISTORIZING -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "..\\main.c" 
In file included from C:/msys64/mingw64/include/open62541/client_config_default.h:12,
                 from ..\main.c:1:
C:/msys64/mingw64/include/open62541/client.h:389:18: error: unknown type name 'UA_HistoryReadResponse'
  389 | static UA_INLINE UA_HistoryReadResponse
      |                  ^~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h:390:56: error: unknown type name 'UA_HistoryReadRequest'
  390 | UA_Client_Service_historyRead(UA_Client *client, const UA_HistoryReadRequest request) {
      |                                                        ^~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h: In function 'UA_Client_Service_historyRead':
C:/msys64/mingw64/include/open62541/client.h:391:5: error: unknown type name 'UA_HistoryReadResponse'; did you mean 'UA_ReadResponse'?
  391 |     UA_HistoryReadResponse response;
      |     ^~~~~~~~~~~~~~~~~~~~~~
      |     UA_ReadResponse
C:/msys64/mingw64/include/open62541/client.h:392:53: error: 'UA_TYPES_HISTORYREADREQUEST' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYREADREQUEST'?
  392 |     __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_HISTORYREADREQUEST],
      |                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                     UA_NS0ID_HISTORYREADREQUEST
C:/msys64/mingw64/include/open62541/client.h:392:53: note: each undeclared identifier is reported only once for each function it appears in
C:/msys64/mingw64/include/open62541/client.h:393:30: error: 'UA_TYPES_HISTORYREADRESPONSE' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYREADRESPONSE'?
  393 |         &response, &UA_TYPES[UA_TYPES_HISTORYREADRESPONSE]);
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              UA_NS0ID_HISTORYREADRESPONSE
C:/msys64/mingw64/include/open62541/client.h: At top level:
C:/msys64/mingw64/include/open62541/client.h:397:18: error: unknown type name 'UA_HistoryUpdateResponse'
  397 | static UA_INLINE UA_HistoryUpdateResponse
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h:398:58: error: unknown type name 'UA_HistoryUpdateRequest'
  398 | UA_Client_Service_historyUpdate(UA_Client *client, const UA_HistoryUpdateRequest request) {
      |                                                          ^~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h: In function 'UA_Client_Service_historyUpdate':
C:/msys64/mingw64/include/open62541/client.h:399:5: error: unknown type name 'UA_HistoryUpdateResponse'
  399 |     UA_HistoryUpdateResponse response;
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h:400:53: error: 'UA_TYPES_HISTORYUPDATEREQUEST' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYUPDATEREQUEST'?
  400 |     __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_HISTORYUPDATEREQUEST],
      |                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                     UA_NS0ID_HISTORYUPDATEREQUEST
C:/msys64/mingw64/include/open62541/client.h:401:30: error: 'UA_TYPES_HISTORYUPDATERESPONSE' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYUPDATERESPONSE'?
  401 |         &response, &UA_TYPES[UA_TYPES_HISTORYUPDATERESPONSE]);
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              UA_NS0ID_HISTORYUPDATERESPONSE

01:02:56 Build Failed. 10 errors, 0 warnings. (took 2s.585ms)

When compiling, it outputs errors like these, which refer to the file "client.cpp" in which there are no type declarations.

enter image description here

I don't even have a clue what needs to be done. I'm trying to compile the example that the developers provided, but even it can't be compiled. Is this a mistake, a flaw, or am I doing something wrong? It is very necessary to implement a method of reading historical data through OPC UA. I ask for assistance in resolving this issue.

My Tools:

UPDATE

So, I rebuilt the branch library 1.2. The build was successful:

User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541
# git submodule update --init --recursive
Submodule path 'deps/ua-nodeset': checked out '393b633468a5d1d062dd253e1488d1d8ba335b6f'

User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541
# mkdir build && cd build

User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541/build
# cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_NAMESPACE_ZERO=FULL ..
-- Building for: Ninja
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: C:/msys64/mingw64/bin/python.exe (found version "3.9.7")
-- Found Git: C:/msys64/usr/bin/git.exe (found version "2.34.1")
-- open62541 Version: 1.2.3
-- The selected architecture is: win32
-- Test CC flag -std=c99
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -pipe
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wall
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wextra
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wpedantic
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Werror
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wno-static-in-inline
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wno-overlength-strings
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wno-unused-parameter
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wc++-compat
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wformat
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wformat-security
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wformat-nonliteral
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wmissing-prototypes
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wstrict-prototypes
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wredundant-decls
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wuninitialized
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Winit-self
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wcast-qual
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wstrict-overflow
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wnested-externs
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wmultichar
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wundef
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -fno-strict-aliasing
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -fexceptions
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
-- Could NOT find LATEX (missing: LATEX_COMPILER)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/msys64/home/User/open62541/build

User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541/build
# cmake --build .
[1/66] Generating src_generated/open62541/nodeids.h
[2/66] Generating src_generated/open62541/statuscodes.h, src_generated/open62541/statuscodes.c
[3/66] Generating src_generated/open62541/transport_generated.c, src_generated/open62541/transport_generated.h, src_generated/open62541/transport_generated_handling.h, src_generated/open62541/transport_generated_encoding_binary.h
[4/66] Generating src_generated/open62541/types_generated.c, src_generated/open62541/types_generated.h, src_generated/open62541/types_generated_handling.h, src_generated/open62541/types_generated_encoding_binary.h
[5/66] Generating src_generated/open62541/namespace0_generated.c, src_generated/open62541/namespace0_generated.h
INFO:__main__:Preprocessing C:/msys64/home/User/open62541/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
INFO:__main__:Generating Code for Backend: open62541
INFO:__main__:NodeSet generation code successfully printed
[6/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/statuscodes.c.obj
[7/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/transport_generated.c.obj
[8/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/types_generated.c.obj
[9/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types_print.c.obj
[10/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types.c.obj
[11/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types_encoding_binary.c.obj
[12/66] Building C object CMakeFiles/open62541-object.dir/src/ua_connection.c.obj
[13/66] Building C object CMakeFiles/open62541-object.dir/src/ua_timer.c.obj
[14/66] Building C object CMakeFiles/open62541-object.dir/src/ua_util.c.obj
[15/66] Building C object CMakeFiles/open62541-object.dir/src/ua_securechannel.c.obj
[16/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_session.c.obj
[17/66] Building C object CMakeFiles/open62541-object.dir/src/ua_securechannel_crypto.c.obj
[18/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_ns0.c.obj
[19/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server.c.obj
[20/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_nodes.c.obj
[21/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_utils.c.obj
[22/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_discovery.c.obj
[23/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_config.c.obj
[24/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_binary.c.obj
[25/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_networkmessage.c.obj
[26/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_writer.c.obj
[27/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_async.c.obj
[28/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_ns0.c.obj
[29/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_reader.c.obj
[30/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_method.c.obj
[31/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_manager.c.obj
[32/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_subscription.c.obj
[33/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_attribute.c.obj
[34/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_session.c.obj
[35/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_monitoreditem.c.obj
[36/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_view.c.obj
[37/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_discovery.c.obj
[38/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_discovery_multicast.c.obj
[39/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_discovery.c.obj
[40/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_nodemanagement.c.obj
[41/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client.c.obj
[42/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_securechannel.c.obj
[43/66] Building C object CMakeFiles/open62541-object.dir/deps/aa_tree.c.obj
[44/66] Building C object CMakeFiles/open62541-object.dir/deps/libc_time.c.obj
[45/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_connect.c.obj
[46/66] Building C object CMakeFiles/open62541-object.dir/deps/base64.c.obj
[47/66] Building C object CMakeFiles/open62541-object.dir/deps/pcg_basic.c.obj
[48/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_highlevel.c.obj
[49/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_subscriptions.c.obj
[50/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_config.c.obj
[51/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_subscription.c.obj
[52/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_subscription_monitoreditem.c.obj
[53/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_subscription_datachange.c.obj
[54/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_log_stdout.c.obj
[55/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types_lex.c.obj
[56/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_nodestore_ziptree.c.obj
[57/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_config_default.c.obj
[58/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_nodestore_hashmap.c.obj
[59/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_accesscontrol_default.c.obj
[60/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/crypto/ua_pki_none.c.obj
[61/66] Building C object CMakeFiles/open62541-plugins.dir/arch/win32/ua_clock.c.obj
[62/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/crypto/ua_securitypolicy_none.c.obj
[63/66] Building C object CMakeFiles/open62541-plugins.dir/arch/win32/ua_architecture_functions.c.obj
[64/66] Building C object CMakeFiles/open62541-plugins.dir/arch/network_tcp.c.obj
[65/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/namespace0_generated.c.obj
C:/msys64/home/User/open62541/build/src_generated/open62541/namespace0_generated.c: In function 'namespace0_generated':
C:/msys64/home/User/open62541/build/src_generated/open62541/namespace0_generated.c:117159:15: note: variable tracking size limit exceeded with '-fvar-tracking-assignments', retrying without
117159 | UA_StatusCode namespace0_generated(UA_Server *server) {
       |               ^~~~~~~~~~~~~~~~~~~~
[66/66] Linking C shared library bin\libopen62541.dll

After installing the library, I tried to build my code again. This time a completely different error popped up:

03:18:12 **** Rebuild of configuration Debug for project open62541 ****
Info: Internal Builder is used for build
gcc -std=c99 -DUA_ARCHITECTURE_WIN32 -DUA_ENABLE_HISTORIZING -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "..\\main.c" 
gcc -o open62541.exe main.o -lopen62541 -lws2_32 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o: in function `main':
C:\msys64\home\User\open62541\Debug/../main.c:78: undefined reference to `__imp_UA_Client_HistoryRead_raw'
collect2.exe: error: ld returned 1 exit status

03:18:14 Build Failed. 2 errors, 0 warnings. (took 2s.452ms)

Here is the code itself that I am trying to compile:

#include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>

#include <stdio.h>
#include <stdlib.h>

static UA_Boolean readHist(UA_Client *client, const UA_NodeId *nodeId, UA_Boolean moreDataAvailable, const UA_ExtensionObject *data, void *unused)
{
    printf("\nRead historical callback:\n");
    printf("\tHas more data:\t%d\n\n", moreDataAvailable);

    return true;
}

int main(int argc, char *argv[])
{
    UA_Client *client = UA_Client_new();
    UA_ClientConfig_setDefault(UA_Client_getConfig(client));

    UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:62544");
    if (retval != UA_STATUSCODE_GOOD)
    {
        UA_Client_delete(client);
        return EXIT_FAILURE;
    }

    UA_NodeId node = UA_NODEID_STRING(1, "TNPZ.P_NEFT.R1.M");

    retval = UA_Client_HistoryRead_raw(client, &node, readHist, UA_DateTime_fromUnixTime(0), UA_DateTime_now(), UA_STRING_NULL, false, 10, UA_TIMESTAMPSTORETURN_BOTH, (void*) UA_FALSE);

    if (retval != UA_STATUSCODE_GOOD)
    {
        printf("Failed. %s\n", UA_StatusCode_name(retval));
    }

    UA_Client_disconnect(client);
    UA_Client_delete(client);
    return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}

Solution

  • In order for the mechanism of reading historical data to work, it is necessary to enable the UA_ENABLE_HISTORIZING parameter WHEN BUILDING THE LIBRARY, which is not specified in the official documentation for the library.

    cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_ENABLE_HISTORIZING=ON -DUA_NAMESPACE_ZERO=FULL ..