In a static library VC++ project, I've noticed a .lib file from another static library is listed in "Additional Dependencies".
I can't see why you would want to explicitly link one .lib into another, surely the whole point is you add libraries in the project which does all the linking into a DLL/EXE. In my case out of the dozens of libs we use, it's just this one that's added in this way. What is the reason for this functionality and when is it needed?
Related
I am creating a static library project in visual studio for personal use, and I'd like to include another existing static library into my own static library.
Usually (for executible projects) I can set up extra include and lib directories in the project's properties, but this time the menues are different and I don't know which settings to use. How would I do that?
You can include a static library inside a static library, but it generally leads to bloat and other problems.
The best approach is usually to add the link library to your 'public header' using a #pragma so it's automatically linked:
#pragma comment(lib,"nameoflibIneed.lib")
I figured out a sort of hacky way to make it work.
I just included the library normally as I would in a normal project, and only after that I changed the project type to .lib.
Apparently the additional dependencies get saved after changing the type of the project even though the respective menus in the project configuration pages disappear.
I am developing a static library, which is added to my main project that tests the static library's functions. The static library inside is using some 3rd party components, and this third party components needs to add some additional libraries (e.g.: libz.dylib, SystemConfiguration.Framework). It's fine, but when I try to build my main project that contains my static library, I got bunch of linker errors. I figured out, if I add the same frameworks and libraries to the main projects what I needed to add to my static library, the linker errors disappear and the project is built succesfully. The question is do I really need to add all of those resources to the main Project? I find it crazy that if I give my static library to someone else to use, I need to include a bunch of frameworks and libraries in the documentation that has to be added also in the integrator project? Or am I missing something important?
It's because a static library is not linked, unlike an executable or dynamic library.
A static library is just an archive of object files, and object files contain external references to symbols they use. Those references are not resolved until the executable/dynamic library is linked.
Therefore when you link-in a static library you are responsible for providing any dependant libraries to the linker, which can themselves be either static or dynamic.
I am wondering how to link third party libraries in visual studio?
the third party I mean they gave you *.dll, *.lib and *.pdb.
for example, zmq:
lib/
libzmq-v100-mt-gd-3_2_4.lib (static library)
libzmq-v100-mt-gd-3_2_4.pdb (debug file)
bin/
libzmq-v100-mt-gd-3_2_4.dll (dynamic library)
my vs project need libzmq, and I want to link zmq statically. however, I looked
at project property pages. there is no option to allow us force the program linked statically or dynamically. (perhaps, I missed something)
I set linker/general, linker/input, c_c++/general (include) to the corresponding zmq path. But, it does not work.
libzmq-v100-mt-gd-3_2_4.lib in this case is the import library rather than the full static library. Linking against libzmq-v100-mt-gd-3_2_4.lib will result in your application requiring libzmq-v100-mt-gd-3_2_4.dll.
You'll need to either build a static library from source if they don't provide one, or use it as a DLL.
I need to compile an existing C++ library both as a lib and a dll, and then use the static and dynamic libraries in different applications. I use VS2010.
What I can't do is to edit all the header files in order to add __declspec(dllexport) instructions to export, as the library must be kept as it is.
Under Mac I was able to compile and use a dylib without problems, but I know that VS is lacking in this regard.
In VS is it feasible to compile a static lib first and then a dll in order to have functions "exported" (i.e. linkable from an application at compilation time)? In other words, can I use the static lib as if was the export lib generated with __declspec(dllexport)?
Are there better workarounds?
I need to compile an existing C++ library both as a lib and a dll, and
then use the static and dynamic libraries in different applications. I
use VS2010.
Create configurations for that. For example Release LIB, Release DLL, etc.
What I can't do is to edit all the header files in order to add
__declspec(dllexport) instructions to export, as the library must be
kept as it is.
Simply add module definition file (*.def) with a list of exported functions.
In other words, can I use the static lib as if was the export lib
generated with __declspec(dllexport)?
No, those libs are different. When you build a DLL you get a binary and a lib files.
I'm devdeloping a DLL in VS2008. When I examine the DLL in Dependency Walker, I can see a dependency on zlib1.dll. How can I find out where this comes from? My DLL is (statically) linked against HDF5.lib, HDF5_CPP.lib, and GSL.lib. I'm not including any zlib headers, so I'm a bit clueless about this. I know HDF5 depends on zlib, but I tried with the precompiled HDF5 as well as self-compiled HDF5, both to no avail.
The thing is I want to make distribution as easy as possible; that's why I link statically against all libraries I use. Funny thing is, I do link against zlib1.lib; no clue why zlib1.dll is then still a dependency.
Any ideas? Thanks!
Follow the tree within the depends tools.
The right hand tree show the "tree" of module dependency.
Click zlib1.dll in that tree and in the top right hand you will have a list of functions that are being used by the module that links to it. Search in your project to see where you are using them.
zlib1.lib is the dll lib, not the static lib for zlib. You need to obtain the and build the static lib part of the zlib distribution. I havn't built zlib... but some other projects have a xxx.lib and an xxxlib.lib, with the second form being the 'proper' static lib.
On /MT: /MT only effects the c-runtime selection: /MT adds a linker dependency to libc.lib - which statically links the c-runtime into your binary. conversely /MD adds a linker dependency to msvcrt.lib (a lib file) that contains references to msvcr90.dll