LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to build a Dynamic Link library which the c code includes an external library like libxml2?

Solved!
Go to solution

i compiled the c code file in visual studio code. i even used __declspec(dllexport) in my code. but i'm also facing an issue in labview that is  unresolved external symbols error.

my os is windows

 

the process  followed:

Compile the source file into object code:

gcc -Wall -Werror -fpic -I./Include -I/msys64/ucrt64/include/libxml2 -c xml_handling.c -o xml_handling.o

 

Create a DLL from the object file:

gcc -shared -o xml_handling2.dll xml_handling.o -lxml2 -lz -LC:\msys64\ucrt64\lib

 

Compile the test program and link it against the DLL:

gcc -Wall xml_handling.c -o xml_handling.exe -I./Include -I/msys64/ucrt64/include/libxml2 -L.-lxml_handling -L/msys64/ucrt64/lib -lxml2


here the .exe file is working during compile time. but when i use the .dll in labview i'm facing the external symbol error. how can i solve these issue.

is there any way to generate and use the .dll without any dependencies in labview? if not then how can i generate .dll and how to use that in labview with dependencies

0 Kudos
Message 1 of 6
(218 Views)

sorry for interfering in the middle of these. i'm also facing the same issue in labview unresolved external symbols error. but my os is windows: i compiled the c code file in visual studio code
i even used __declspec(dllexport) in my code.
Compile the source file into object code:

gcc -Wall -Werror -fpic -I./Include -I/msys64/ucrt64/include/libxml2 -c xml_handling.c -o xml_handling.o

Create a DLL from the object file:

gcc -shared -o xml_handling2.dll xml_handling.o -lxml2 -lz -LC:\msys64\ucrt64\lib

Compile the test program and link it against the DLL:

gcc -Wall xml_handling.c -o xml_handling.exe -I./Include -I/msys64/ucrt64/include/libxml2 -L.-lxml_handling -L/msys64/ucrt64/lib -lxml2


here the .exe file is working during compile time. but when i use the .dll in labview i'm facing the external symbol error. how can i solve these issue.

is there any way to generate and use the .dll without any dependencies in labview? if not then how can i generate .dll and how to use that in labview with dependencies

0 Kudos
Message 2 of 6
(210 Views)
Solution
Accepted by topic author Maneeha

The only dependencies I see are the following:

 

image-20250613114153651.png

So, these four files shall be suffcient:

 

17.12.2024  20:10         1.135.869 libiconv-2.dll
11.04.2025  14:19           189.434 liblzma-5.dll
18.02.2025  21:51         1.309.996 libxml2-2.dll
23.01.2024  09:51           100.279 zlib1.dll

 

 

C Source for minimal DLL:

 

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>
#include <stdio.h>

// Function to parse XML and print root element name
__declspec(dllexport) int parseXML(const char *filename, char* lv_root, char* lv_content) {
    xmlDoc *document = xmlReadFile(filename, NULL, 0);
    if (document == NULL) return -1;

    xmlNode *root = xmlDocGetRootElement(document);
    strcpy(lv_root, root->name);

    // Get content of the root element
    xmlChar *content = xmlNodeGetContent(root);
    if (content) {
        strcpy(lv_content, content);
        xmlFree(content);
    }


    xmlFreeDoc(document);
    xmlCleanupParser();

	return 0;
}

 

 

Test XML File

 

 

<?xml version="1.0" encoding="UTF-8"?>
<MyRoot>
    <MyChild>MyContent</MyChild>
</MyRoot>

 

 

Snippet and works:

snippet.png

 

Test project (including dependent DLLs) is in the attachment.

Update: Sorry, I didn't realize you're using Linux. I don't have access to a Linux system at the moment, but it should work similarly in general. I can prepare a version for Linux as well, just not right now.

 

Message 3 of 6
(173 Views)

In general, I'm not sure how Linux is applicable here (maybe the initial question was AI-generated), but anyway, I've checked this and, in general, it's almost the same.

C source:

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>
#include <stdio.h>

#if defined(_WIN32) || defined(__CYGWIN__)
#  define EXPORT __declspec(dllexport)
#else
#  define EXPORT __attribute__ ((visibility ("default")))
#endif

// Function to parse XML and print root element name
EXPORT int parseXML(const char *filename, char* lv_root, char* lv_content) {
    xmlDoc *document = xmlReadFile(filename, NULL, 0);
    if (document == NULL) return -1;

    xmlNode *root = xmlDocGetRootElement(document);
    strcpy(lv_root, root->name);

    // Get content of the root element
    xmlChar *content = xmlNodeGetContent(root);
    if (content) {
        strcpy(lv_content, content);
        xmlFree(content);
    }

    xmlFreeDoc(document);
    xmlCleanupParser();

	return 0;
}

Compiled as

gcc -shared -o xml_parser.so xml_parser.c -I/usr/include/libxml2 -lxml2 -fPIC

Dependencies:

ldd ./xml_parser.so

linux-vdso.so.1
libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2
libc.so.6 => /usr/lib/x86_64-linux-gnu/libc.so.6
libicuuc.so.70 => /usr/lib/x86_64-linux-gnu/libicuuc.so.70
libz.so.1 => /usr/lib/x86_64-linux-gnu/libz.so.1
liblzma.so.5 => /usr/lib/x86_64-linux-gnu/liblzma.so.5
libm.so.6 => /usr/lib/x86_64-linux-gnu/libm.so.6
/lib64/ld-linux-x86-64.so.2
libicudata.so.70 => /usr/lib/x86_64-linux-gnu/libicudata.so.70
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
libgcc_s.so.1 => /usr/lib/x86_64-linux-gnu/libgcc_s.so.1

and works exactly same:

Bildschirmfoto vom 2025-06-14 06-04-05.png

 

Message 4 of 6
(114 Views)

Thank You 

Andrey_Dmitriev
I solved it.
0 Kudos
Message 5 of 6
(61 Views)

@Maneeha wrote:

Thank You 

Andrey_Dmitriev
I solved it.

You're welcome, glad to see it was helpful for you! And sorry about my wrong suggestion that it was AI-generated question.

0 Kudos
Message 6 of 6
(57 Views)