LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using C++ library with labWindows/CVI 2020

Hello,

I am very new to labWindows environment. I have created a C++ static library(.lib) using QtCreator using Microsoft Visual C++ Compiler. The library uses the winsock2.h and wsock32 library. I am able to create a test project with Qt and test the library.

I need to use the same library inside a labWindows application. I was able to link the library without problems when the wsock32 library was not being used, but now I have the following errors:

error: Undefined symbol '__imp_sendto' referenced in "c:\Workspace\{....}\myLibrary.lib".

error: Undefined symbol '__imp_setsockopt' referenced in "c:\Workspace\{...}\myLibrary.lib".

and many more related to the wsock32 library.

I tried to add "#include <winsock2.h> but then I got conflict errors with <windows.h> and <winsock2.h>.

As far as I understand, I need to link the ws_32.dll but if I include the library file in the project the problem stills the same.

Thank you.

0 Kudos
Message 1 of 5
(2,509 Views)

Adding a header does absolutely nothing to resolve link errors. You need to add the according winsock library Ws2_32.lib to your linker settings. This is the import library that resolves the imports to Ws2_32.dll. Under Windows you do not link to DLLs, you either link to import libraries or load the DLL dynamically in your code with LoadLibrary() and GetProcAddress().

Rolf Kalbermatter
My Blog
Message 2 of 5
(2,495 Views)

Hello @rolfk,

 

Thanks for your response, I have searched in my computer files for the WS2_32.lib file and then added to the project settings, now I dont have any issue regarding the winsock2 library. Thank you.

 

I have linked with QtCore and QtNetwork libraries in the project because I use Qt classes inside my library.

 

Now I have another issue, when I compile the application I have errors in all the constructors of my library classes and also from QtClasses, like QThread.

 

error: Undefined symbol '??_EQThread@@UEAAPEAXI@Z' referenced in "c:\{...}\myLibrary.lib".

 

Also I have some errors that I dont understand at all like:

 

error: Undefined symbol '??2@YAPEAX_K@Z' referenced in "c:\{...}\myLibrary.lib".

error: Undefined symbol '__std_terminate' referenced in "c:\{...}\myLibrary.lib".

error: Undefined symbol '__RTDynamicCast' referenced in "c:\{...}\myLibrary.lib".

 

Are these errors related to the C++ and C compatibility?

 

Thank you

0 Kudos
Message 3 of 5
(2,456 Views)

@ebernal_ wrote:

 

Are these errors related to the C++ and C compatibility?


Absolutely! And to make matters worse, even if you had a C++ compiler IDE, which LabWindows/CVI isn't and never will be, if it is not the same C++ compiler you still will run into these problems.

 

Basically in the 80ies of last century you had these issues between C compilers as each had its own ideas about what libraries and functions to implement in what way. In the 90ies they converged towards each other, leaving eventually only two big competing standards (aside from embedded hardware compilers), Visual Studio because it was omnipotent on the Windows PC, and GCC which was for all the rest.

 

Then came C++ and everything started from scratch and still hasn't settled down.

 

Since your library was compiled with Visual Studio and LabWindows/CVI is MSC compatible, you may get away by linking also the according MSC C++ runtime library with your project such as msvcurt.lib or vcruntime.lib, depending on your Visual Studio version.

 

The various unreferenced external symbols come from various C++ features you use, such as dynamic_cast() causes the __RTDynamicCast import. But there is no guarantee, that msvcurt.lib may not pull in other external functions that might require other link libraries or even MSC++ specific startup thunks that might not be compatible with the LabWindows/CVI generated startup thunks.

 

And even if it all links eventually, there is still no guarantee that the msvcurt.lib doesn't want to do things that will upset the LabWindows/CVI created process environment. LabWindows/CVI only has as one of their promises that they are compatible with MSC generated standard C libraries, but nothing is guaranteed about C++ libraries.

Rolf Kalbermatter
My Blog
Message 4 of 5
(2,453 Views)

Hello rolfk

Thanks for your time and response, now its all clear.

 

0 Kudos
Message 5 of 5
(2,398 Views)