473,387 Members | 1,520 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,387 software developers and data experts.

Linker Errors Referencing a Mixed Assembly (CLR) with Native Types

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);}
---------------------------------------------------------------------------------------------------
Jul 19 '06 #1
3 3925
Banfa
9,065 Expert Mod 8TB
And what is the linker error(s) you would get from this?
Jul 19 '06 #2
Dear Banfa,

as I mentioned in my post, the main linker errors are LNK2028 errors (followed by LNK2019 and LNK1120). I have attached the exact messages for the example I have provided (they are in German, but I'm sure you get the picture).

By the way, if I use managed classes (i.e. public ref class MathFunctions and public ref class SomeMoreMathFunctions), all linker errors disappear if I uncomment the #using directive in my example.

Thanks,

Dietmar

-------------------------------------------------------------------------------------------------------
Verknüpfen...
extassembly.obj : error LNK2028: Nicht aufgelöstes Token (0A000092) ""public: static double __cdecl clrassembly::MathFunctions::Multiply(double,double )" (?Multiply@MathFunctions@clrassembly@@$$FSANNN@Z)" , auf das in Funktion ""public: static double __cdecl extassembly::SomeMoreMathFunctions::percent(double )" (?percent@SomeMoreMathFunctions@extassembly@@$$FSA NN@Z)" verwiesen wird.

extassembly.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: static double __cdecl clrassembly::MathFunctions::Multiply(double,double )" (?Multiply@MathFunctions@clrassembly@@$$FSANNN@Z)" in Funktion ""public: static double __cdecl extassembly::SomeMoreMathFunctions::percent(double )" (?percent@SomeMoreMathFunctions@extassembly@@$$FSA NN@Z)".

D:\dev\ms.net\primer\Debug\extassembly.dll : fatal error LNK1120: 2 nicht aufgelöste externe Verweise.
Jul 19 '06 #3
Banfa
9,065 Expert Mod 8TB
as I mentioned in my post, the main linker errors are LNK2028 errors (followed by LNK2019 and LNK1120).
Remember that without knowing the actual linker you are using the numbers are completely useless without the messages themselves. Even if you did give the actual linker it still wouldn't actually help anyone without access to that linker or it's documnetation.

OK I am going to take a guess here because

a. I don't know

and

b. I don't have time to copy your files to my computer and try it out

but here goes.

I think the error is that in your header files you declare your functions as being part of a name space but in your code files you do not defined them as part of that namespace so they actually exist in the normal name space not the delared namespace.

Change you code files like so

Expand|Select|Wrap|Line Numbers
  1. // clrassembly.cpp (source file for asssembly A)
  2.  
  3. #include "clrassembly.h"
  4.  
  5. namespace clrassembly {
  6.  
  7. double MathFunctions::Multiply(double a, double b){return a * b;}
  8.  
  9. }
  10.  
I'll leave to to convert the other source file if this works.
Jul 21 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
8
by: Ted Miller | last post by:
Hi folks, I'm looking at moving a large base of C++ code to .Net under tight time constraints. The code runs in mission-critical environments, and I am extremely concerned about the loader lock...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
1
by: Bern McCarty | last post by:
Our project consists of some mixed .dlls and recently we noticed that it had slowed down. When I investigated I figured out that some inlineable methods of a native C++ type were compiled into (not...
3
by: ralphsieminsky | last post by:
A project compiles fine under VS 2005 RC without the /clr option. However, when /clr is turned on several errors appear: - A symbol exported from a DLL is not found by another DLL referencing...
3
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
10
by: ajtaylor | last post by:
Hello, I have a load of native C++ code that I want to use in a CLR class library. My "logic" being that I create a C++/CLI managed class that acts as an interface to the unmanged code. I...
20
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...

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.