Linking a DLL in Visual Studio - c++

I'm using Visual Studio C++ 2005 on Windows XP.
I have created a DLL shared library using Visual Studio C++ 2005.
However, I am not sure how to link it. Normally I have just created the static libraries (*.lib).
Do I link the same way I would when linking a library. By using the properties C/C++ and linker general properties and selecting the path for the headers and library paths?
Many thanks for any advice.

When you create the DLL there should be a .lib file created for the purpose of dynamic linking. You can use these just as you would static .lib files.

This article explains Windows dlls well.
The .LIB file associated with a DLL
describes what (exported) symbols are
present in the DLL, together with
their locations.

To put it simply:
When you link: you Need Lib, not DLL
When you run it: you need dll, not lib (Put the DLL with your executable)

Related

How to import .lib into .dll?

I'm trying to code a dll as a plugin for some system using C++. This plugin will make use of another library which is a .lib file and should output only one .dll file as a result. So I want this other .lib file included in my dll. There should be only one dll file and lib file should be included in it, so that I could include this dll file into the system as a one-file plugin. Is this possible and how?
I'm using Visual C++ 2010 Express.
Thank you.
Unfortunately, the VS linker doesn't have an option equivalent to ld's --whole-archive which can be used to include an entire library.
Your best bet is to unpack the library and link in the resulting object files. You can use the librarian (lib tool) for that. To list all members of the library, use lib /LIST. Object files have to be extracted one by one, using lib /EXTRACT:member.

C++ Symbols not found

I'm trying to compile 3 projects:
A static library (.lib)
A dynamic library (.dll) that uses the .lib of the static library.
An application (.exe) that uses the .dll of the dynamic libaray
However, when trying to compile the .exe and setting a breakpoint, I get the warning "The breakpoint will not currently be hit. No symbols have been loaded for this document."
Well, I know that Visual Studio is missing the .pdb files somehow. However, I don't get why Visual Studio doesn't find it.
The .pdb file of the static library is being generated and is in the same folder than the .lib.
The dynamic library references the folder where the .lib and the .pdb of the static library are inside. A .pdb file is created in the same folder where the .dll is created for the dynamic libary.
The application copies the .dll and the .pdb of the dynamic library before compiling to the folder where the .exe is generated.
Still, Visual Studio is complaining that it doesn't have loaded any symbols. In the output console, it also tells me that it has loaded the symbols of the .exe and the .dll, but not of the .lib. Am I missing somewhat?
When you compile the .exe, you should still link to the .lib file that has been generated when compiling the .dll (so I am speaking about the .lib that comes with the dynamic library, not the one that comes with the static one).
Depending on your visual studio version you might configure that here:
Project->Properties->Configuration Properties->Linker>Input->Additional Dependencies
What version of Visual Studio? Are all the projects in the same solution? If so, Just add the library as a reference to the DLL, and the DLL as a reference to the EXE. Then Visual Studio handles linking everything up, and the .exe, .dll, and .pdb files should all be in the solution output directory.
Also, if you use LoadLibrary to load the DLL the debugger won't load the debug info and won't know where to set the breakpoints in the DLL until after it is loaded, which can cause the error you are seeing as well.

Bundle a static library(.lib file) into dll

I am building a dll project. I am using openssl and quickfix libraries. I don't want users to separately copy the libraries when they use dll. I want to bundle these .lib files into my dll as well.
I am using visual studio. How can I bundle these libraries(.lib static libraries) into my dll so that the user can just copy my dll into their projects and start working right away.
Thanks,
by default it'll be bunded in. you program, just call it MyProgram.DLL, can
call other programs, as a DLL file, e.g. C Runtime Library provides
MSVCRT.DLL for MyProgram.DLL to call; or
include other program's Static Library file, i.e. the .LIB files, inside your binary, i.e. MyProgram.DLL, e.g. C Runtime Library provides LIBCMT.LIB for MyProgram.DLL to include inside and call.
It seems you want option 2), but actually, since what provided are .LIB files, option 1) is not possible for you.

Visual Studio: Static Link to Static Library

I've created a Static Library (no mfc is used in it) in Visual Studio and want to link with it in statically linked mfc project (com-dll actually).
When linking mfc-lib I get a bunch of messages symbol is already defined. This is because I linked standard C++ library twice (once in static library, and other in mfc project).
How do I fix it?
There is a workaround with /FORCE:MULTIPLE, but I think this is a bad decision.
When linking static libraries to a DLL or EXE project, you need to take care, that all projects have been compiled to use the same runtime library. So please set all projects to the same "Use of MFC" and also to the same "Runtime library". If you do not do so, then one project might have been compiled to take the fopen function from the standard CRT while another project might have been compiled to take the fopen function from the MFC. Mixing these is a problem for the linker because he does not know which runtime (and in the example: which fopen) to use.
When linking your DLL or EXE project against another DLL project, this is not a problem. You can have a DLL without MFC usage and link your MFC EXE against that DLL.
If you have a util library that you use very often in different projects, then you might consider setting up different build settings so you can build your library in DEBUG and RELEASE and with and without MFC. Then in your EXE project you can pick the library binary that matches your project settings.

How to specify lib.a in Visual C++

I'm trying to use GLC library in Visual C++. I download already built version. The library(libGLC_lib2.a) is in ar format. I tried to add libGLC_lib2 or libGLC or libGLC_lib2.a in Visual C++ project properties, but linker gives unresolved external symbols: can't find the library. So is it possible to specify libraries with ar format in Visual Studio?
P.S. The examples within library are Qt based and the library specified with the option -lGLC_lib2
Visual C++ doesn't use .a files for providing the definitions of DLLs, typically it uses .lib files. The library linking convention you referenced (-lGLC_lib2) is more consistent with GCC command-line arguments, which would explain why the pre-built binaries you downloaded had a .a file instead of a .lib.
In order to use this library with Visual Studio, you'll likely need to rebuild it from source.
Alternatively, you may be able to produce a .lib file from the pre-built binaries. see the following article for more information on how this can be done: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
Did you set the 'Additional Library Directories' in the linker settings as well as adding the library.