473,805 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linker Error LNK2001 when using static variable in native class

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?
Jun 4 '07 #1
1 3619

"Fabian" <Fa****@discuss ions.microsoft. comwrote in message
news:60******** *************** ***********@mic rosoft.com...
>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?
Your immediate problem would be solved with a declaration tagged with
__declspec(dlli mport)... 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.
Jun 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1930
by: endo55 | last post by:
Hi I've got the following errors when trying to compile a program cvision error LNK2001: unresolved external symbol _IID_IGraphBuilde cvision error LNK2001: unresolved external symbo _IID_IFileSinkFilter cvision error LNK2001: unresolved external symbol _IID_ICreateDevEnu cvision error LNK2001: unresolved external symbol _IID_IBaseFilte cvision error LNK2001: unresolved external symbol _IID_IAMVideoProcAm
4
11340
by: Saran | last post by:
Hi All, I'm getting the following linker error when I try to build a library. nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype nafxcw.lib(filelist.obj) : error LNK2019: unresolved external symbol __mbctype referenced in function "void __stdcall...
0
1366
by: Smith | last post by:
Hi, I'm using Visual C++ .NET 2005 Beta1 and have an ATL Smart Device project. I've got lots of LNK2001 errors: menu.obj : error LNK2001: unresolved external symbol "void __cdecl std_ce::_Debug_message(char const *,char const *)" (?_Debug_message@std_ce@@YAXPBD0@Z) menu.obj : error LNK2001: unresolved external symbol "public: static void __cdecl std_ce::_String_base::_Xran(void)"
3
8120
by: ac2806 | last post by:
Hi I want to use the static MFC within a dll, but I get the following errors when linking: nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc nafxcwd.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
3
8092
by: Chucker | last post by:
Hi Folks, I got a Wrapper Dll around a native C++ static library. In .NET 1.1 this worked fine. When moving to .NET 2.0 I get a couple of unresolved externals / linker errors: Error 16 error LNK2028: unresolved token (0A000007) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" (?___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: virtual __thiscall...
1
3295
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly, but throws a load of linker errors
1
10363
by: iiitsunny | last post by:
i have ported one project which was working in VC6 to VC7. Now the project is working fine in VC7 also. I have made some additions in VC7 environment only. But the problem is that the project is not working in the release mode. I mean it is shooting off linking errors. I am required to generate an exe file and am looking for some suggestions!!! thank you all Linker Errors are something like this... error LNK2001: unresolved external...
4
2357
by: DaTurk | last post by:
Hi, I've noticed that when trying to create a managed, auto_gcrooted variable in a antive class, the compiler throws linker exceptions. While searching some forums I found out that this is a bug? I couldn't find the work around, just numerous references to the fact there is one. But apparently there are issues as to how to destroy said objects. Can anyone shed some more light on this topic for me? It would be much appreciated.
0
1229
by: Adamn | last post by:
Hi everybody! I'm using Visual Studio 2005 and don't know how to solve this problem. Till now, everything worked just fine, included all the necessary libs, headers and so on. But there is the problem: I have to implement a class ColorSpaces with static member functions, which manipulates a buffer from the class MSImage and returns it. ColorSpaces.h looks like this: class ColorSpaces { public:
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.