linker error when building a Windows DLL

M

mshngo

Hi,

I am having the following trouble in compiling DLL on windows. Suppose
I want to compile module A into a DLL library, and I want to declare an
external interger n in A. My intention is to have n actually defined in
another module B, and I want to compile B into an executable, which
will dynamically load module A at run-time. Such reference can then be
resolved when B loads A. Is there a way to achieve this? Right now when
I tried compiling module A into DLL, I got linker error LNK2001:
unresolved external symbol. (I'm using Visual Studio 2005)

It seems if I were to try compiling A into a static library or an
object file, this design could go through: A will first be compiled
successfully into a .lib or .obj file, which is then linked into the
object file for module B to form an executable. During that link stage
this external integer reference can be resolved.

One possible way around this is that instead of having A access the
global integer n, we pass the reference of n from B into A, when B
invokes certain function exported by A that reads and/or writes that
interger. On the other hand, if I have many global objects defined in
B, and want functions defined in A to access them, such parameter
passing will seem like an unnecessary burden. Any suggestions? I very
much appreciate your help!

Mingsheng
 
M

mlimber

mshngo said:
Hi,

I am having the following trouble in compiling DLL on windows. Suppose
I want to compile module A into a DLL library, and I want to declare an
external interger n in A. My intention is to have n actually defined in
another module B, and I want to compile B into an executable, which
will dynamically load module A at run-time. Such reference can then be
resolved when B loads A. Is there a way to achieve this? Right now when
I tried compiling module A into DLL, I got linker error LNK2001:
unresolved external symbol. (I'm using Visual Studio 2005)

It seems if I were to try compiling A into a static library or an
object file, this design could go through: A will first be compiled
successfully into a .lib or .obj file, which is then linked into the
object file for module B to form an executable. During that link stage
this external integer reference can be resolved.

One possible way around this is that instead of having A access the
global integer n, we pass the reference of n from B into A, when B
invokes certain function exported by A that reads and/or writes that
interger. On the other hand, if I have many global objects defined in
B, and want functions defined in A to access them, such parameter
passing will seem like an unnecessary burden. Any suggestions? I very
much appreciate your help!

Mingsheng

You should ask this question on a Windows-centric newsgroup since
standard C++ (the topic of this group) doesn't concern itself with
DLLs. See this FAQ for what is on-topic here and for some suggestions
of better places to post:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M
 

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

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,829
Latest member
KimberAlli

Latest Threads

Top