Ailef
Ailef

Reputation: 7906

Visual studio: question about linking functions between two projects

I guess this is a newbie question, but anyway. I've got a solution composed of two projects (1 DLL and 1 console app). The console app includes some headers from the DLL project and of course, when building it all, the linker tells me that there are some unresolved symbols. I've already added a Reference from the app to the DLL projects (Project Properties->References->Add new Reference) but this is still not working.

The only solution I found is to duplicate the .cpp files corresponding to the headers in the second project but I guess this isn't the best way to do it but I guess there has to be a better way to do this?

Upvotes: 1

Views: 518

Answers (2)

StevieG
StevieG

Reputation: 8709

Make sure that the dll project is a dependency for the console app (right-click on the console project in the solution explorer and select project dependencies)..

Then, in the console project properties under configuration properties->linker->general, ensure that 'Link Library Dependencies' is set to yes.

Upvotes: 0

dascandy
dascandy

Reputation: 7292

I'm going to guess you use Visual Studio and don't know about dllexport.

Visual Studio by default does not export the names of your functions on the outside of your DLL. To do so you need to tell it that explicitly:

__declspec(dllexport) void f() {...}

and on the side of the one using the DLL:

__declspec(dllimport) void f();

That way the second one will use the imported function and the first will export it.

Upvotes: 2

Related Questions