470,849 Members | 688 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

linker error when building a Windows DLL

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

Apr 25 '06 #1
2 1720
give me the code.

Apr 25 '06 #2
mshngo wrote:
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-lit...t.html#faq-5.9

Cheers! --M

Apr 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Red Hammer | last post: by
2 posts views Thread by Don Sealer | last post: by
reply views Thread by Daniel Myers | last post: by
1 post views Thread by sg10241024 | last post: by
1 post views Thread by Felix | last post: by
2 posts views Thread by ayan4u | last post: by
12 posts views Thread by kath.neumann | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.