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++ / June 2007

Tip: Looking for answers? Try searching our database.

Linker Error LNK2001 when using static variable in native class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fabian - 04 Jun 2007 13:21 GMT
I have a native singleton in a C++/CLI dll. To compile the dll itself I put a
declaration of the instance variable into the cpp file (otherwise the linker
complains with a LNK 2020).
I now want to use the singleton also from outside the dll project. So I just
#include the header file in a file in another dll.  It compiles but the
linker doesn't find the static variable (LNK2001).

Any suggestions?
Ben Voigt [C++ MVP] - 04 Jun 2007 14:49 GMT
>I have a native singleton in a C++/CLI dll. To compile the dll itself I put
>a
[quoted text clipped - 7 lines]
>
> Any suggestions?

Your immediate problem would be solved with a declaration tagged with
__declspec(dllimport)... but that's a bad idea.

Write extern "C" wrappers for the functions you want to call from the DLL's
client.  Sharing native C++ classes across module boundaries is a bad idea,
because it's almost impossible to get the exact same definition on both
sides, so you end up violating ODR and getting undefined behavior.  Use
extern "C" functions instead, or DCOM, or use a managed class.

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.