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

C++/CLI and C++ [Mixed] Class Library - project settings

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 created a new CLR class library and added my native/unmanaged C++
code then added some code to the unmanaged class.

Now, and this is where I am not sure, I turned off the CLR support in
the project settings

Configuration Properties | General | Common Language Runtime support

[I set this to "No Common Language Runtime support"]

and for the .CPP file that contains the managed code I set the

C/C++ | General | Common Language Runtime support

to /CLR.

When I build the project all is fine.

The problem comes when I try to use this assemly in another project I
get an error about a missing .LIB file for the assembly I am trying to
use.

Now I am pretty sure I read somewhere that the turning off of the CLR
option on the project was the correct thing to do when compiling mixed
code.

Can someone out there help me please as yet again C++/CLI is the poor
man interms of documention/books out there*

*depite IMHO being a better solution than using C#

Thanks.

Aug 3 '06 #1
10 2348
<aj******@hushmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
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 created a new CLR class library and added my native/unmanaged C++
code then added some code to the unmanaged class.

Now, and this is where I am not sure, I turned off the CLR support in
the project settings
FWIW: In a mixed mode application of mine, I ask for CLR support at the
project level and use

#pragma unmanaged

...

#pragma managed

where I need to turn that off.
is fine.

The problem comes when I try to use this assemly in another project I
get an error about a missing .LIB file for the assembly I am trying to
use.
If you post the exact text of the error message here someone will likely be
able to decipher it for you.
Can someone out there help me please as yet again C++/CLI is the poor
man interms of documention/books out there*
I feel your pain. This book has been in the offing for some time:

http://www.amazon.com/gp/product/032...lance&n=283155

and it is written by one of the big guns on the compiler team I have high
hopes for it. I do hope that it shows up on a bookshelf soon. On that page,
Amazon does have other C++/CLI books which actually exist but I have not
read them.

Regards,
Will
Aug 3 '06 #2

William DePalo [MVP VC++] wrote:
<aj******@hushmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
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 created a new CLR class library and added my native/unmanaged C++
code then added some code to the unmanaged class.

Now, and this is where I am not sure, I turned off the CLR support in
the project settings

FWIW: In a mixed mode application of mine, I ask for CLR support at the
project level and use

#pragma unmanaged

...

#pragma managed

where I need to turn that off.
is fine.

The problem comes when I try to use this assemly in another project I
get an error about a missing .LIB file for the assembly I am trying to
use.

If you post the exact text of the error message here someone will likely be
able to decipher it for you.
Can someone out there help me please as yet again C++/CLI is the poor
man interms of documention/books out there*

I feel your pain. This book has been in the offing for some time:

http://www.amazon.com/gp/product/032...lance&n=283155

and it is written by one of the big guns on the compiler team I have high
hopes for it. I do hope that it shows up on a bookshelf soon. On that page,
Amazon does have other C++/CLI books which actually exist but I have not
read them.

Regards,
Will
The error I get is

2>LINK : fatal error LNK1104: cannot open file
'..\debug\CalculationEngine.lib'

When it is attempting to link the CLR forms application that is
attempting to use the mixed assembly.

*the mixed assembly is called CalculationEngine and the dll is created
ok.

Aug 3 '06 #3

William DePalo [MVP VC++] wrote:
<aj******@hushmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.com...
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 created a new CLR class library and added my native/unmanaged C++
code then added some code to the unmanaged class.

Now, and this is where I am not sure, I turned off the CLR support in
the project settings

FWIW: In a mixed mode application of mine, I ask for CLR support at the
project level and use

#pragma unmanaged

...

#pragma managed

where I need to turn that off.
is fine.

The problem comes when I try to use this assemly in another project I
get an error about a missing .LIB file for the assembly I am trying to
use.

If you post the exact text of the error message here someone will likely be
able to decipher it for you.
Can someone out there help me please as yet again C++/CLI is the poor
man interms of documention/books out there*

I feel your pain. This book has been in the offing for some time:

http://www.amazon.com/gp/product/032...lance&n=283155

and it is written by one of the big guns on the compiler team I have high
hopes for it. I do hope that it shows up on a bookshelf soon. On that page,
Amazon does have other C++/CLI books which actually exist but I have not
read them.

Regards,
Will
Note I am currently using this book:

Pro Visual C++/CLI and the .NET 2.0 Platform (Hardcover)

for reference as it seems to be the only one on the subject that is
available at the moment.

Aug 3 '06 #4
<aj******@hushmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
The error I get is

2>LINK : fatal error LNK1104: cannot open file
'..\debug\CalculationEngine.lib'

When it is attempting to link the CLR forms application that is
attempting to use the mixed assembly.

*the mixed assembly is called CalculationEngine and the dll is created
ok.
At the risk of repeating the obvious, choose Options from the Tools menu.
Then navigate

Project and Solutions -VC++ Directories

Select Library Files in the combo box labeled "Show directories for" and
make sure that the directory containing your library is listed there.

Regards,
Will


Aug 3 '06 #5

William DePalo [MVP VC++] wrote:
<aj******@hushmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
The error I get is

2>LINK : fatal error LNK1104: cannot open file
'..\debug\CalculationEngine.lib'

When it is attempting to link the CLR forms application that is
attempting to use the mixed assembly.

*the mixed assembly is called CalculationEngine and the dll is created
ok.

At the risk of repeating the obvious, choose Options from the Tools menu.
Then navigate

Project and Solutions -VC++ Directories

Select Library Files in the combo box labeled "Show directories for" and
make sure that the directory containing your library is listed there.

Regards,
Will
Many thanks for your reply but my [all be it poor] understanding is
that I am creating a Mixed (Native and Managed) assembly
[CalculationEngine.dll] and as such there should not be a .lib file
produced!

Aug 3 '06 #6
<aj******@hushmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Many thanks for your reply
You are welcome.
but my [all be it poor] understanding is
that I am creating a Mixed (Native and Managed) assembly
[CalculationEngine.dll] and as such there should not be a .lib file
produced!
I might be wrong, but it looked to me like you added

CalculationEngine.lib

as a dependency and it looked like the linker could not find it. The
procedure that I sketched addresses that problem.

Regards,
Will

Aug 3 '06 #7

William DePalo [MVP VC++] wrote:
<aj******@hushmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Many thanks for your reply

You are welcome.
but my [all be it poor] understanding is
that I am creating a Mixed (Native and Managed) assembly
[CalculationEngine.dll] and as such there should not be a .lib file
produced!

I might be wrong, but it looked to me like you added

CalculationEngine.lib

as a dependency and it looked like the linker could not find it. The
procedure that I sketched addresses that problem.

Regards,
Will
Having done some testing it appears the issue is this.

If I create a CLR Class library project and for all the native /
unmanaged C++ files set them TO NOT USE CLR then all works fine.

If I make the project not use CLR and only set the managed files to use
CLR then I get the link error

As there are a lot of C++ native/unmanaged files I decided the 2nd
approach was less time consuming.

I am basing my approach [the only using CLR compilation option on the
managed files] on stuff I have read on the internet including

http://msdn.microsoft.com/msdnmag/is...h/default.aspx

and a presentation the author has on his personal website where he
shows that a C++ project can use managed code by simply flicking the
CLR compilation switch on that file.

I sort of understand why the linker is expecting a lib file as I
suppose by making the project settings not to use CLR then it looks
like a normal dll project.

What I dont understand is that if there is some unmanged code in the
project then surely the output is an .NET assembly and thus there is no
lib file.

*Confused*

Aug 3 '06 #8
aj******@hushmail.com wrote in
news:11**********************@h48g2000cwc.googlegr oups.com:
If I make the project not use CLR and only set the managed files to
use CLR then I get the link error

[...]

I sort of understand why the linker is expecting a lib file as I
suppose by making the project settings not to use CLR then it looks
like a normal dll project.

What I dont understand is that if there is some unmanged code in the
project then surely the output is an .NET assembly and thus there is
no lib file.
You are hitting a "bug" in the Visual C++ build system. We are not
supposed to try to link in an import library when the dependent DLL is
a managed DLL with no native exports.

However, there are a couple of reason why this "bug" exists. There are
also some workarounds that you can use.

Let me start with the reasons why this "bug" exists:

1. In a mixed-mode DLL, you can actually have both managed and native
exports. If you had native exports, we would need the import library. We
can't tell if you have native exports unless we inspect the binary.
Inspecting the binary is something that we currently do not do and would
be quite a significant change in how the build system works.

2. To determine that a DLL is a mixed-mode DLL when the project says
that /clr is not being used, we'd have to inspect the options on every
file in the project to see if any file has /clr. This will need to be
done on every build and can be quite expensive (imagine projects with
thousands of files). It will slow down the build for the standard "i'm
building a large native DLL" case which we consider an "evil" thing.

Ok. So what is the workaround? On the general linker settings page of
the consuming project, set "Link Library Dependencies" to "No". This
will have the effect of not linking the import library (which is what
you want) but will also have the effect of not linking in any static or
import libraries that this project depends on (which is probably not
what you want). To avoid the latter side-effect, you'll need to manually
add any dependent libraries you want linked in on the linker line
manually.

I hope this helps.

Thanks,
Tarek Madkour
Lead Program Manager
Microsoft Visual C++
Aug 3 '06 #9

Tarek Madkour [Microsoft] wrote:
aj******@hushmail.com wrote in
news:11**********************@h48g2000cwc.googlegr oups.com:
If I make the project not use CLR and only set the managed files to
use CLR then I get the link error

[...]

I sort of understand why the linker is expecting a lib file as I
suppose by making the project settings not to use CLR then it looks
like a normal dll project.

What I dont understand is that if there is some unmanged code in the
project then surely the output is an .NET assembly and thus there is
no lib file.

You are hitting a "bug" in the Visual C++ build system. We are not
supposed to try to link in an import library when the dependent DLL is
a managed DLL with no native exports.

However, there are a couple of reason why this "bug" exists. There are
also some workarounds that you can use.

Let me start with the reasons why this "bug" exists:

1. In a mixed-mode DLL, you can actually have both managed and native
exports. If you had native exports, we would need the import library. We
can't tell if you have native exports unless we inspect the binary.
Inspecting the binary is something that we currently do not do and would
be quite a significant change in how the build system works.

2. To determine that a DLL is a mixed-mode DLL when the project says
that /clr is not being used, we'd have to inspect the options on every
file in the project to see if any file has /clr. This will need to be
done on every build and can be quite expensive (imagine projects with
thousands of files). It will slow down the build for the standard "i'm
building a large native DLL" case which we consider an "evil" thing.

Ok. So what is the workaround? On the general linker settings page of
the consuming project, set "Link Library Dependencies" to "No". This
will have the effect of not linking the import library (which is what
you want) but will also have the effect of not linking in any static or
import libraries that this project depends on (which is probably not
what you want). To avoid the latter side-effect, you'll need to manually
add any dependent libraries you want linked in on the linker line
manually.

I hope this helps.

Thanks,
Tarek Madkour
Lead Program Manager
Microsoft Visual C++

Many thanks for the reply. As a matter of interest is this information
on the Microsoft website anywhere - if not perhaps it should be.

On a final note - is there any issue with making the project settings
use CLR and then making all the native C++ files settings to not use
CLR?

Aug 4 '06 #10
aj******@hushmail.com wrote in news:1154707267.422193.8880
@m79g2000cwm.googlegroups.com:
>You are hitting a "bug" in the Visual C++ build system. We are not
supposed to try to link in an import library when the dependent DLL is
a managed DLL with no native exports.

However, there are a couple of reason why this "bug" exists. There are
also some workarounds that you can use.

[...]

Many thanks for the reply. As a matter of interest is this information
on the Microsoft website anywhere - if not perhaps it should be.
It's not :(. I'll contact our support team to get a KB article out for it.
On a final note - is there any issue with making the project settings
use CLR and then making all the native C++ files settings to not use
CLR?
No. It makes the IDE happier but may be harder for you to maintain if you
have way more native sources than you have managed ones.

Thanks,
Tarek Madkour
Aug 4 '06 #11

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

Similar topics

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...
9
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and...
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...
7
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I'm new to working with mixed assemblies. All of my previous experience has been with VC++/MFC in native, unmanaged applications. When I create a mixed assembly in which one or more of the files...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.