Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2008

Tip: Looking for answers? Try searching our database.

VC Linker Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NvrBst - 04 Mar 2008 22:59 GMT
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!
Carl Daniel [VC++ MVP] - 05 Mar 2008 04:29 GMT
> 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
Cody - 05 Mar 2008 22:11 GMT
On Mar 4, 8:29 pm, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospam> wrote:

> > 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?
[quoted text clipped - 11 lines]
>
> -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!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.