LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to import a shared library that uses QT headers

I got following PM about this problem and since I find it not useful to respond through PM for such support questions since nobody else will be able to profit from the answer I decided to post it here in lieu of the original requester.

 


 

i am using a header file in labview import dll wizard and require to use QT compiler paths and preprocessors. I could not make a thread in discussion forum so the private message. i have added few incude paths but that causes new missing header file. Image is added below. if you help that will be great thanks in advance

qt.PNG


 

 

This is my answer:

 

I don't have any experience in importing a DLL with QT dependencies but this is my educated guess why it won't work and the possible solutions to it.

 

QT is completely C++ based and it's headers therefore contain many C++ syntax elements. I doubt that the headers are written in such a way that they would allow compilation with a standard C compiler at all. The Call Library Node however only supports import of standard C functions and the import library wizard accordingly only supports the standard C syntax. C++ syntax is several magnitudes more complex to parse correctly and it would make absolutely no sense to invest the resources in making the import library wizard support that, since the Call Library Node never even could support importing C++ classes (C++ ABI is notorously non standardized among the different C++ compilers and consequently you can usually not match binary compiled object modules between C++ compilers at all, and not just because they use different object file formats but also because the binary structure of classes in memory differs between them and sometimes even between versions of the same compiler.

 

This leaves you only 2 choices (well 3 if you consider abandoning this project as a choice)

 

1) write your own header that defines all the datatypes and other necessary defines for your header file in terms of standard C datatypes. Then import that header in your header file you try to import instead of the QT header mess.

 

2) let the import library wizard do the functions it can do, if any, and do the rest by hand. This is the solution I normally consider the best. You need to review anyhow every function that the import library wizard has created very carefully, to make sure it does the right thing. The C syntax simply isn't powerful enough to describe an API fully enough to let an automated tool create always correct bindings for another environment. Many things about how to prepare parameters and how they might or might not be related to each other (for instance the buffer size of a string or array parameter that is passed in another parameter) are simply not possible to recognize by an automated tool. A seasoned programmer will usually guess that quickly from the naming convention of the parameter names (and preferably extract it from the prosa text in the documentation for the library), but computers are pretty bad both in guessing correctly and in understanding prosa text and there are about zillion different naming conventions out there. If you u can't create the VI wrappers yourself because you lack the understanding of the C programming to do this, you basically also can't review and verify the import library created VIs and really are just creating a big timebomb by using the import library wizard and trusting it to do everything alright.

 

Rolf Kalbermatter
My Blog
Message 1 of 3
(4,125 Views)

i faced with such problem and unfortunately i cant fixed it yet?!

now i'm wondering is it possible to use dll file that is created with Qt creator at all?!

0 Kudos
Message 2 of 3
(2,792 Views)

In addititon to what I already have written before there are a few things you need to consider.

 

1) If the DLL is exporting C++ objects you can't acces them with the Call Library Node. The Call Library Node only can access exported functions. You will in that case have to write a C wrapper similar to this example: https://labviewwiki.org/wiki/DLL/shared_library

 

2) If your DLL is exporting functions but with C++ object pointers you can treat them in LabVIEW as pointer sized integers but you can't do anything with them unless your DLL also exports functions that can operate on those objects in some way. But you do not want to use the Import Library Wizard for this as it would require you to let it parse the QT headers and that won't work as it can't parse C++ declarations. You will have to create the VIs manually and configure all the Call Library Nodes by hand.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 3
(2,776 Views)