473,748 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LNK2005 from a C++/CLI dll linking against a non-CLR C++ static library

Hello all-

I have some static C++ libraries that I wrote in VS2003 but which
upgraded fine when i went to VS2005 Pro. In them i overload the global
versions of operators new, new[], delete, and delete[]. I also use the
STL and parts of boost (shared_ptr<> and weak_ptr<>) pretty heavily.
They have dependencies on various windows libs (dbghelp, winsock, etc...).

These static libraries have no common runtime support at all and use the
Multi-Byte character set.

I'm trying to expose the functionality provided by my libs up to .NET by
way of a C++/CLI DLL that links against them and exposes a new public
ref class in the generated assembly. This new CLR class will wrap and
broker their functionality to various C# apps.

I'm running into nasty linker errors, so I wrote a tiny little test case
that reproduces the failures I'm getting. I'd really appreciate it if
anyone would mind taking the time to look over them. The smallest way I
could repro it was to create a VS2005 solution with 2 projects. The
first is a C++ static library containing the dummy implementation and
the second is a C++/CLR executable that uses the static library. Note
that the problem occurs even if the C++/CLR project is a DLL; it doesn't
seem related in any obvious way.

The non-CLR static library is contained in UnmanagedTest.h and
UnmanagedTest.c pp as follows.

Unmanaged.h:
-----------------------------------------------------
#pragma once
#include <vector>

class Test
{
public:
Test();
~Test();

int* x;
std::vector<int > y;
};
-----------------------------------------------------

Unmanaged.cpp:
-----------------------------------------------------
#include "UnmanagedTest. h"
#include <cstdlib>

void* operator new(size_t size)
{
return std::malloc(siz e);
}

void operator delete(void* mem)
{
std::free(mem);
}

Test::Test()
{
x = new int[32];
for (int i = 0; i < 32; ++i)
x[i] = i;
}

Test::~Test()
{
delete[] x;
}
-----------------------------------------------------

The .NET C++/CLI executable has the default AssemblyInfo.cp p and one
..cpp file.

CppCliTest.cpp:
-----------------------------------------------------
#pragma unmanaged
#include "UnmanagedCppLi b/UnmanagedTest.h "
#pragma managed

using namespace System;

int main()
{
Test* test = new Test;

for (int i = 0; i < 32; ++i)
Console::WriteL ine(test->x[i]);

delete test;

return 0;
}
-----------------------------------------------------

The linker errors i'm getting are as follows:

-----------------------------------------------------
UnmanagedCppLib .lib(UnmanagedT est.obj) : error LNK2005: "void __cdecl
operator delete(void *)" (??3@YAXPAX@Z) already defined in
MSVCRT.lib(MSVC R80.dll)

D:\source\CppCl iTest\Release\C ppCliTest.exe : fatal error LNK1169: one
or more multiply defined symbols found
-----------------------------------------------------

My UnmanagedCppLib is set to use the Debug Multithreaded DLL CRT in
debug config and the Multithreaded DLL CRT in release. Interestingly,
this all compiles cleanly, links cleanly, and runs as expected in Debug
configuration. These link errors are only in Release build.

Here's where it gets a little crazy- I've found two separate ways to
make this work in Release configuration:

1. remove the overloads of global operators new and delete from
UnmanagedTest.c pp.

2. remove all references to std::vector from UnmanagedTest.h and
UnmanagedTest.c pp

Making either of these changes gets rid of the link errors.

I figure I must be doing something wrong here, but after paring it down
this far I can't figure out what to try next. Any time i see MSVCRT.lib
conflicts I immediately think that i'm using the wrong version of the
CRT but i only have one static lib (it uses MT DLL) and one C++/CLI DLL
(it has no choice but to use MT DLL).

Any advice or suggestions would be greatly appreciated.

Thanks in advance,
Charles Nicholson
Feb 25 '06 #1
3 5115
Charles Nicholson wrote:
Hello all-

I have some static C++ libraries that I wrote in VS2003 but which
upgraded fine when i went to VS2005 Pro. In them i overload the global
versions of operators new, new[], delete, and delete[]. I also use the
STL and parts of boost (shared_ptr<> and weak_ptr<>) pretty heavily.
They have dependencies on various windows libs (dbghelp, winsock, etc...).

These static libraries have no common runtime support at all and use the
Multi-Byte character set.

I'm trying to expose the functionality provided by my libs up to .NET by
way of a C++/CLI DLL that links against them and exposes a new public
ref class in the generated assembly. This new CLR class will wrap and
broker their functionality to various C# apps.

I'm running into nasty linker errors, so I wrote a tiny little test case
that reproduces the failures I'm getting. I'd really appreciate it if
anyone would mind taking the time to look over them. The smallest way I
could repro it was to create a VS2005 solution with 2 projects. The
first is a C++ static library containing the dummy implementation and
the second is a C++/CLR executable that uses the static library. Note
that the problem occurs even if the C++/CLR project is a DLL; it doesn't
seem related in any obvious way.

The linker errors i'm getting are as follows:

-----------------------------------------------------
UnmanagedCppLib .lib(UnmanagedT est.obj) : error LNK2005: "void __cdecl
operator delete(void *)" (??3@YAXPAX@Z) already defined in
MSVCRT.lib(MSVC R80.dll)

D:\source\CppCl iTest\Release\C ppCliTest.exe : fatal error LNK1169: one
or more multiply defined symbols found
-----------------------------------------------------


I tossed up a very small repro case i described in the original post at
http://cnicholson.net/CppCliTest.zip if any brave and kind souls feel
like taking a stab at it. (note, the filename is case-sensitive). This
is for VS2005 only.

It really feels like i'm doing something obviously wrong, but nothing's
jumping out at me.

Thanks in advance for any suggestions, corrections, ideas, etc...

Regards,
Charles Nicholson
Feb 27 '06 #2
Charles Nicholson wrote:
I have some static C++ libraries that I wrote in VS2003 but which
upgraded fine when i went to VS2005 Pro. In them i overload the
global versions of operators new, new[], delete, and delete[]. I also
use the STL and parts of boost (shared_ptr<> and weak_ptr<>) pretty
heavily. They have dependencies on various windows libs (dbghelp,
winsock, etc...).

These static libraries have no common runtime support at all and use
the Multi-Byte character set.

I'm trying to expose the functionality provided by my libs up to .NET
by way of a C++/CLI DLL that links against them and exposes a new
public ref class in the generated assembly. This new CLR class will
wrap and broker their functionality to various C# apps.
The linker errors i'm getting are as follows:

-----------------------------------------------------
UnmanagedCppLib .lib(UnmanagedT est.obj) : error LNK2005: "void __cdecl
operator delete(void *)" (??3@YAXPAX@Z) already defined in
MSVCRT.lib(MSVC R80.dll)

D:\source\CppCl iTest\Release\C ppCliTest.exe : fatal error LNK1169: one
or more multiply defined symbols found
-----------------------------------------------------


I tossed up a very small repro case i described in the original post at
http://cnicholson.net/CppCliTest.zip if any brave and kind souls feel
like taking a stab at it. (note, the filename is case-sensitive). This
is for VS2005 only.


I should also note that if I compile the static library with CLR support
that everything works fine. However, I'd like to use them the way they
were intended; as non-CLR libs. There are a fair amount of them and I'm
not crazy about introducing a new build config...

regards,
charles nicholson
Feb 28 '06 #3
I tried to reproduce your problem, but your solution copiles and links fine
on my machine.

According to you description, your poblems probably exist because you do not
use the right CRT in one of your libs. Linking with /clr object files
requires you to compile all your object files with the multithreaded DLL
variant of the CRT and to use only libs compiled with the multithreaded DLL
variant of the CRT.

Marcus

"Charles Nicholson" <ne**@cnicholso n.net> wrote in message
news:eO******** *****@TK2MSFTNG P12.phx.gbl...
Charles Nicholson wrote:
Hello all-

I have some static C++ libraries that I wrote in VS2003 but which
upgraded fine when i went to VS2005 Pro. In them i overload the global
versions of operators new, new[], delete, and delete[]. I also use the
STL and parts of boost (shared_ptr<> and weak_ptr<>) pretty heavily. They
have dependencies on various windows libs (dbghelp, winsock, etc...).

These static libraries have no common runtime support at all and use the
Multi-Byte character set.

I'm trying to expose the functionality provided by my libs up to .NET by
way of a C++/CLI DLL that links against them and exposes a new public ref
class in the generated assembly. This new CLR class will wrap and broker
their functionality to various C# apps.

I'm running into nasty linker errors, so I wrote a tiny little test case
that reproduces the failures I'm getting. I'd really appreciate it if
anyone would mind taking the time to look over them. The smallest way I
could repro it was to create a VS2005 solution with 2 projects. The
first is a C++ static library containing the dummy implementation and the
second is a C++/CLR executable that uses the static library. Note that
the problem occurs even if the C++/CLR project is a DLL; it doesn't seem
related in any obvious way.

The linker errors i'm getting are as follows:

-----------------------------------------------------
UnmanagedCppLib .lib(UnmanagedT est.obj) : error LNK2005: "void __cdecl
operator delete(void *)" (??3@YAXPAX@Z) already defined in
MSVCRT.lib(MSVC R80.dll)

D:\source\CppCl iTest\Release\C ppCliTest.exe : fatal error LNK1169: one or
more multiply defined symbols found
-----------------------------------------------------


I tossed up a very small repro case i described in the original post at
http://cnicholson.net/CppCliTest.zip if any brave and kind souls feel like
taking a stab at it. (note, the filename is case-sensitive). This is for
VS2005 only.

It really feels like i'm doing something obviously wrong, but nothing's
jumping out at me.

Thanks in advance for any suggestions, corrections, ideas, etc...

Regards,
Charles Nicholson

Feb 28 '06 #4

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

Similar topics

1
4208
by: Florian Liefers | last post by:
"Hello World\n", i have the following problem: One of my headerfiles for a lib is including <vector>. When i compile the lib, everything is done well. In my application another file is including <map>. By linking my application and the lib, following errors occur: error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
5
6767
by: J | last post by:
Hi everyone, I started embedding python into a 3D graphics App and I came across this linking problem. SO.lib(ScnGlobal.obj) : error LNK2001: unresolved external symbol __imp__Py_InitModule4TraceRefs SO.lib(ScnNode.obj) : error LNK2001: unresolved external symbol __imp___Py_RefTotal
1
1838
by: dullboy | last post by:
I have a non-MFC project which generated some linker errors "uuid.lib(ieguids.obj) : error LNK2005: _IID_Ixxx already defined in xxx.obj. _IID_Ixxx is an user-defined ID and xxx.obj is a user obj. I tried to add uuid.lib in setting/link/input/ignored libraries, but it didn't work. Any suggestion would be appreciated!
3
4697
by: Jon | last post by:
Hi! I have a problem that have followed me for a long time. When linking, sometimes this link error below arises. My solution is always to remove all files in the project, throw away all debug-files (.obj), rebuild, insert all files in the project and rebuild. After that procedure, the linker usually proceed. But not this time. So I decided to try and find the real problem, but failed. So here I am. When Linking in debug-mode, this...
3
3161
by: Taran | last post by:
Hi all, I have this config.h file which has all the declarations for the vars being used in the application. There are no compilation errors but link errors for all the vars declared in this "iof_config.h" file. //**************************************************** //FILE : iof_library.h //****************************************************
1
7903
by: sethuganesh | last post by:
HI, i have ported vc++ 6.0 code to visual studio 2005. During batch build in debug mode i din't get any error.But if i build the same in release mode i am getting the following error. LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in atlmincrt.lib(atlinit.obj) LIBCMT.lib(tidtable.obj) : error LNK2005: __encoded_null already defined in atlmincrt.lib(atlinit.obj)
1
3144
by: jemai_linda | last post by:
Hi, When i build my project i have the following linking errors: nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) déjà défini(e) dans libcpmtd.lib(newop.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) déjà défini(e) dans libcmtd.lib(dbgdel.obj)
2
2258
by: ppuniversal | last post by:
hello, my program snippet: /*****************************/ /******runThread Function*****/ /*to accept other client connections*/ /*****************************/ DWORD WINAPI runThread(LPVOID param)
6
9832
by: fcvcnet | last post by:
Hi all, I defined a class, as fellows: // Segment.h #pragma once #include "MyPoint.h" enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERSECTATDIASTOLE} twolinesolutioncases;
9
3213
by: dewi | last post by:
Dear All, I have several problem about VC++. I succeed to convert Simulink MATLAB to C code using Real-Time Workshop. I am trying to compile a C code using Visual C++ and found the error. Can anyone explain how to solve it? --------------------Configuration: PROJECT2 - Win32 Debug-------------------- Linking... RV2AJFRONT_NEW.obj : error LNK2005: _rtM_RV2AJFRONT_NEW already defined in RV2AJFRONT_NEW.obj RV2AJFRONT_NEW.obj : error...
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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
9254
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
8255
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
6799
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
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
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
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.