By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,812 Members | 1,288 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,812 IT Pros & Developers. It's quick & easy.

VC Linker Problem

P: n/a
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!
Mar 4 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"NvrBst" <nv****@gmail.comwrote in message
news:48**********************************@u10g2000 prn.googlegroups.com...
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

Mar 5 '08 #2

P: n/a
On Mar 4, 8:29 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
"NvrBst" <nvr...@gmail.comwrote in message

news:48**********************************@u10g2000 prn.googlegroups.com...
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
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!
Mar 5 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.