dWeld
dWeld

Reputation: 105

Linking DLL to DLL

I'm adding code to a Visual Studio 2010 solution with multiple DLLs. Some of the DLLs are dependent on others.

I'm wondering how to specify that the lib file of one (existing) DLL should be input to another (new) DLL.

First, how do I specify that a lib file in the existing DLL project should be created?

Second, how do I indicate that the new DLL project should be dependent on the lib file of the existing one?

The code compiles fine. I'm getting unresolved externals.

Upvotes: 1

Views: 4965

Answers (2)

dWeld
dWeld

Reputation: 105

It turns out I was omitting the "export symbols" setting on the source DLL project (which is specified in the project-creation wizard). This creates a header file with the declspec defines as follows:

#ifdef TESTFILTERS_EXPORTS
#define TESTFILTERS_API __declspec(dllexport)
#else
#define TESTFILTERS_API __declspec(dllimport)
#endif

This is for a DLL project entitled "TestFilters".

For a class definition intended to be exported, the TESTFILTERS_API definition must be used in the class's header file as follows:

class TESTFILTERS_API CTestFilters {...};

The presence of declspec(dllexport) in at least one class definition causes the lib file (i.e. TestFilters.lib) to be automagically created.

Upvotes: 1

  1. In the project properties: You have to add the library references in the properties of each project -- including the projects that generate the DLLs.

    Suppose that project DLL_B uses DLL_A. Select DLL_B in the Solution Explorer, press Alt-Enter, go to Configuration Properties -> Linker -> Input, add DLL_A.lib to Additional Dependencies. Also add ..\Release to General -> Additional Library Dependencies (similarly, add ..\Debug in the debug mode). Make sure you modify it for both Debug and Release builds.

  2. In the solution: You need to make the users dependent on the libraries they use.

    Select your solution in the Solution Explorer, press Alt-Enter, go to Common Properties -> Project Dependencies. For the DLL_B project, check the DLL_A in the 'Depends On' pane.

This is based on VS2008, but I believe it should be similar in VS2010.

Upvotes: 5

Related Questions