473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 3590

"Fabian" <Fa****@discussions.microsoft.comwrote in message
news:60**********************************@microsof t.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(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.
Jun 4 '07 #2

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

Similar topics

1
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...
4
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...
0
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...
3
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)...
3
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...
1
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,...
1
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...
4
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.