LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Compiling a project with import libratries to a static library

Hi,
I have a project containing source and header files and also .lib files that i have created in previous projects. I am trying to compile this project to a static library but i get the following message: "Static libraries cannot contain import libraries. Remove or exclude any import library from the project".
I don't understand what is wrong since i did it before and it worked fine. I need to compile it into a library in order for some one else to include it in his project and use the functions i wrote.
Need your urgent help,
Thanks,
Moshik
 
0 Kudos
Message 1 of 4
(4,222 Views)

Hi Moshik,

As you discovered, LabWindows/CVI reports an error if you attempt to build a static library when you have a DLL import library in your project.  This is expected behavior as static libraries are "self-contained" libraries.  If you need to make DLL calls in your static library, you will need to use the Windows SDK function
LoadLibrary and GetProcAddress rather than use your import library.  

Check out the FAQ: Using Dynamic Link Libraries with LabWindows/CVI tutorial (specifically the static linking and dynamic linking section) as well as the How Can I Access DLL Functions in a LabWindows/CVI Program Without Including the Import Library in t... KnowledgeBase.

Understanding the concepts linked above about static linking and dynamic linking are really helpful.  Essentially, dynamic linking provides a way for a process to call a function that is not part of its executable code.  The executable code for the function is located in the DLL verse the executable you built.  These libraries are "dynamically-linked" because they are linked to an application when its loaded and executed rather than when its created.  In the case of static linking, the linker gets all the referenced functions from the static link library and places it with your code in your executable file.

Hope this helps!

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 2 of 4
(4,215 Views)
Hi,
I get this message when I include a static library file not a DLL.
I have 3 static library files in my project - 2 of them were created by me over CVI. The third one is part of a device API probably was not created over CVI.
When i try to build a static library file with all 3 mentioned files i get the error. When i exclude the static library file that was not build over CVI everything is O.K.
It seems like the problem is the origin of the file - only files created by CVI are accepted.
Thanks,
Moshik
0 Kudos
Message 3 of 4
(4,209 Views)
Hi Moshik,
 
Was the static library that causes problems created in Visual C++? Libraries created in a C++ compiler mangle function names and thus cause problems when they are trying to be used in a C environment.  In order to use the library, you will need to go back to the developer and have them use extern "C" statements to indicate that the code will be used in a C environment.  Also, see the LabWindows/CVI Help topic "Creating Object and Library Files in External Compilers for Use in LabWindows/CVI". This section describes the include directories you need to use. 
 
Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 4 of 4
(4,201 Views)