03-05-2012 06:56 AM
i have a general question about compiling lib and dll in cvi
here is the scenario:
lib A has a function in it called a-func
lib B has a function in it called b-func - b-func calls a-func.
dll C has lib B and A in it and calls b-func.
the questions:
1. what needs to be added to C dll prj files: A, B, or both (i tried without A and got error linking)?
2. how come when compiling B lib it doesnt ask for A lib but only needs its h. file? (in fact it throws an error when trying to compile with another lib)
3. baring in mind that B and A lives on their own (dont need each other at compilation) which is logical since the lib files only contains symbols for the functions which are foreign to the lib+the code of the lib itself (in our case a-func is replaced by a symbol)- so it stand within reason that if i change a-func the only thing that i have to do is recompile A and afterwards C.
i found out that it is not the case i changed a-func and recompiled A and C and upon calling b-func the old a-func was called- how is that so?
03-05-2012 06:01 PM
Are you using static libraries or dynamic link libraries for lib A and lib B? If you are using the lib from the dynamic link libraries, then you will still need to keep the DLLs around when running your main application. The libs in the case only contain linking info for load-time dynamic linking. If however, you are using static libraries, you can include those libs in the project, and then you only need them at compile time. In that case, the libs contain botht he linking info and the binary for the functions.
If you are chaining static libraries, and lib B calls into lib A, then you must compile lib B with lib A in the project, but you do not need to include lib A in the project of the main app if it does not directly call into any of the lib A functions.The same applies for dynamic-link library libs except you must also have the DLL nearby when you run the main app.
In all cases, you must include the header for a function whenever you call it.
03-06-2012 01:23 AM
thanks for the reply
A and B are static lib. However i still dont understand why upon changing A i need to recompile B? each should be independent? no? In fact you cant compile a static lib prj with another lib. included in it, it will result in an error./
it is clear why i need to recompile C as it is the dll.
03-06-2012 11:30 AM
The note in the CVI Help for Creating Static Libraries in LabWindows/CVI topic may clear this up a bit.
Note If you include a .lib file in a static library project, LabWindows/CVI includes all object modules from the .lib in the static library it creates. When you create an executable or DLL, LabWindows/CVI uses only the necessary modules from the .lib file.
03-07-2012 04:44 PM
The main difference between static libraries and DLLs/EXEs are that static libraries are not linked. A static library is essentially just a bundle of compiled .obj files. The static lib may have dangling references to functions and/or variables that reside in other, outside C source files, static libraries, or DLLs. These references are only resolved when the static lib is included in a DLL or EXE project, and that project is built.
If you change static lib A, you should not have to recompile static lib B (that uses A). You would only need to recompile B if you had added A to the project tree of B. In this case, B would directly include A, and even if you rebuild A, your built B would still contain the old, stale version of A. (Static libs do not work like DLLs!)
If you have rebuilt A, and then C, and you're somehow seeing the old implementation of your a-func, then something unexpected is going on. Perhaps the lib A that's included in your DLL C project is old -- that is, it's a different filepath than the new A you rebuilt.
Mert A.
National Instruments