Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DLL linking problem

0 views
Skip to first unread message

Torsten Hensel

unread,
Oct 16, 2008, 2:44:58 AM10/16/08
to
Hi!

I have a problem linking DLLs and static libraries together. Here's the
code:

I have a common DLL c and a rarely used DLL r, both third party. First,
I have created a static Win32 library L that links to c. L contains a
header file L.h with (simplified) content:
#pragma message("Automatically linking with L.lib")
#pragma comment(lib, "L.lib")
#pragma message("Automatically linking with c.lib")
#pragma comment(lib, "c.lib")
#define USE_C_DLL // use c as DLL
#include <c.h> // main header file of c

The test app for L uses #include <L.h> to link L, which compiles and
links fine.

Then I have created a DLL D that links to L and to r. The main header
file D.h contains:
#pragma message("Automatically linking with D.lib")
#pragma comment(lib, "D.lib")
#include <L.h> // main header file of L, links c
#include <r.h> // main header file of r, links r

The test app for D uses #include <D.h> to link D, which compiles and
links fine.

Finally I created a second DLL DD that links to D. The stdafx.h and the
main header file DD.h both contain:
#pragma message("Automatically linking with DD.lib")
#pragma comment(lib, "DD.lib")
#include <D.h> // main header file of D, links c

This compiles fine ("Automatically linking with c.lib" is displayed),
but I get several linker errors "" for functions that are defined in c.

What's the problem? Why do I get linker errors? I enabled /VERBOSE:link,
this showed me that the correct file c.lib is linked. Then where do the
errors come from?

Best regards,
hensz

Torsten Hensel

unread,
Oct 16, 2008, 2:46:32 AM10/16/08
to
Torsten Hensel wrote:
> This compiles fine ("Automatically linking with c.lib" is displayed),
> but I get several linker errors "" for functions that are defined in c.

Oops! Forgot the error message. I get linker errors "unresolved external
symbol"...

Best regards,
hensz


Joseph M. Newcomer

unread,
Oct 16, 2008, 2:25:21 PM10/16/08
to
If the DLLs are compiled in C, the header file needs to have declarations that specify C
naming conventions are used, e.g.,

extern "C" void MyFunc(whatever...);

or, the usual case is

#ifdef __cplusplus
extern "C"
{
#endif
void MyFunc(whatever...);
#ifdef __cplusplus
}
#endif

You might be the victim of "name mangling". Since you only reported the error messages,
and did not actually show them, it is hard to tell.
joe

On Thu, 16 Oct 2008 08:44:58 +0200, Torsten Hensel
<He...@expires-31-10-2008.news-group.org> wrote:

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages