Hi *,
I'm in the process of porting an ANSI C++ project from a UNIX platform to .NET. After "getting rid of" some platform-specific stuff I managed to compile the first two libraries into mixed assemlies (DLLs) using MSVC8 (VS2005) with the /clr option. However, I get hundreds of linker errors (mostly LNK2028) because assembly B uses native types defined in assembly A.
I could easily get rid of the problem by #including the original source files in addition to the header files, but then, of course, I wouldn't need DLLs in the first place. You'll find attached at the end of this post a simple snippet of code to illustrate the problem.
Can anyone please tell me the least intrusive way to "export" the definitions for native types to be accessible to other DLLs and / or applications using the CLR.
Please remember that I try to stay as close as possible to the ANSI C++ standard for now. Since I need a single source base for both the UNIX and the .NET world (using #ifdefs), all changes need to be as platform-neutral as possible. I do not want to use .lib files because there is no need to export types to Win32-specific or other external applications.
Any help is appreciated.
Dietmar
--------------------------------------------------------------------------------------------------------
// clrassembly.h (header file for assembly A)
#pragma once
using namespace System;
namespace clrassembly {
class MathFunctions
{
public:
static double Multiply(double a, double b);
};
}
-------------------------------------------------------------------------------------------------------
// clrassembly.cpp (source file for asssembly A)
#include "clrassembly.h"
double MathFunctions::Multiply(double a, double b){return a * b;}
-------------------------------------------------------------------------------------------------------
// extassembly.h (header file for assembly B)
#pragma once
using namespace System;
namespace extassembly {
class SomeMoreMathFunctions
{
public:
double percent(double a);
};
}
-----------------------------------------------------------------------------------------------------
// extassembly.cpp (source file for assembly B)
#include "extassembly.h"
#include "clrassembly.h"
//#include "clrassembly.cpp" //uncomment this to resolve linker error
//#using "clrassembly.dll" // useless if you work with native types
using namespace clrassembly;
using namespace extassembly;
double SomeMoreMathFunctions::percent(double a) {return MathFunctions::Multiply(a, 100);}
---------------------------------------------------------------------------------------------------