Problem with __declspec(dllexport)/__declspec(dllimport) in mixed assembly

G

Gawel

Hajo,
I have two dlls, both of them are compiled with /clr switch.
In first dll project I have managed and unmanaged classes.
One of the unmanaged I would like to use outside therefore
I marked it as follows:
class __declspec(dllexport) Terrain
{
public:
void foo(){}
};

In sceond dll projcet I added refrenece to the first dll and
included header like this:
class __declspec(dllimport) Terrain
{
public:
void foo();
};

Then If I use object of Terrain class I get
LNK2001: unresolved external symbol "public: __thiscall
Terrain::Terrain(int,int)".

Any idea ?

thanks in advance

Gawel
 
V

Vinayak Raghuvamshi

Gawel said:
Hajo,
I have two dlls, both of them are compiled with /clr switch.
In first dll project I have managed and unmanaged classes.
One of the unmanaged I would like to use outside therefore
....
....
Then If I use object of Terrain class I get
LNK2001: unresolved external symbol "public: __thiscall
Terrain::Terrain(int,int)".

Any idea ?

when you built your first dll, visual studio linker would have
generated a .lib file as well.. you need to include this in your
second dll through the project-settings->linker->input->additional
dependencies

hth.
-Vinayak
 
G

Gawel

when you built your first dll, visual studio linker would have
generated a .lib file as well.. you need to include this in your
second dll through the project-settings->linker->input->additional
dependencies

Thanks, it works.
But I have two more questions.
If I add *.lib file to additonal dependencies then __declspec( dllimport )
in the second project
isn't needed any more. What's more If I have *.lib file I don't need *.dll
file of first project.
It seems that your solution bases on static library not on dynamic one.
I am glad that you solved my problem but I am still curious how to get
the same effect but with dlls.

Once again thanks

Gawel
 
V

Vinayak Raghuvamshi

Gawel said:
Thanks, it works.
But I have two more questions.
If I add *.lib file to additonal dependencies then __declspec( dllimport )
in the second project
isn't needed any more. What's more If I have *.lib file I don't need *.dll
file of first project.

That is not correct. Why don't you try deleting the .dll and then see
if your application still launches?
It seems that your solution bases on static library not on dynamic one.

Just because a file is a .lib does not mean you are using "static
linkage".

the .lib in this instance is just a skeleton that defines the entry
points that the loader will then load from the dll at runtime.

I would suggest that you read up on fundamentals of dlls, libs and how
they work. MSDN has a few good links that you can pursue....

-Vinayak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top