VC Linker Problem

N

NvrBst

I have C99 code (which I changed extensions to .cpp to compile as C+
+98). Which is does fine.

I create a Static Library Project (.lib) and Build, and it builds
the .obj files (9 of them) and makes the .lib.

I change the project to a Dynamic Linked Library (.dll), and then try
to compile and it makes all the .obj files, but fails with making the
DLL with a LINKER ERROR.

clib.obj : error LNK2019: unresolved external symbol _timer referenced
in function "void __cdecl cls_aprod(struct CLS *,int,int,int *
const,double * const,double * const)" (?
cls_aprod@@YAXPAUBCLS@@HHQAHQAN2@Z)
cls.obj : error LNK2001: unresolved external symbol _timer
clsqr.obj : error LNK2001: unresolved external symbol _timer
Debug\cls.dll : fatal error LNK1120: 1 unresolved externals

I exclude a few of the .cpp files that reference the timer function,
and re-build, and I get LNK errors again about other functions that
are in the project, but not in that .obj file (ie functions that
reference the other name.cpp files through the #include name.h ).

It seems like the DLL is not linking the functions from the other .cpp
files in the folder. If i remove everything and just try to make a
dll with 1 of the files (that do not reference any other functions)
like timer.cpp, it will make the timer.dll fine.

Once I try to make a DLL from a file like cls.cpp (which refrences the
timer.h) it fails with the __timer external symbol unresolved.


But it manages to link them all together fine with the Static Library
(.lib) project? How can I get this to compile as a DLL if I wish to?
How do I tell Visual Studio to make the dll with linking to the other
files in the project like the lib does?

I have played around with some of the options in the DLL Properties >
Linker >> (General/Input) tabs... but no success.

Thanks!
 
C

Carl Daniel [VC++ MVP]

But it manages to link them all together fine with the Static Library
(.lib) project? How can I get this to compile as a DLL if I wish to?
How do I tell Visual Studio to make the dll with linking to the other
files in the project like the lib does?

I think that you've hit on the head on the nail there: static libraries are
not linked, and there's no requirement that internal references be satisfied
within the library. A library is not significantly different from a ZIP
file containing a bunch of OBJ files. In contrast, a DLL is a linked image
and there cannot be any unsatisfied symbol references.

So, it sounds like you're missing a definition for _timer in your code -
something needs to supply that reference.

-cd
 
C

Cody

I think that you've hit on the head on the nail there: static libraries are
not linked, and there's no requirement that internal references be satisfied
within the library. A library is not significantly different from a ZIP
file containing a bunch of OBJ files. In contrast, a DLL is a linked image
and there cannot be any unsatisfied symbol references.

So, it sounds like you're missing a definition for _timer in your code -
something needs to supply that reference.

-cd

Hello;

the definition for the timer function is in a timer.cpp file in the
code. Which was included in the project... so I was confused.
But I ended up finding the problem, i was including bctimer.h from
another header file. And it had a:
#ifdef __cplusplus
extern "C" {
#endif
....
#include "bctimer.h"
....
#ifdef __cplusplus
}
#endif


This was what was causing the problem and making it not link the
bctimer stuff with the dll... however i was able to "compile" the
object files fine... so it was seeing the header information from
bctimer.h... just wsn't using it for linking.

Removing the #ifdef __cplusplus extern "C" { ... stuff made it
work. I can compile the .DLL and the .LIB files fine now! thanks for
all your help!
 

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