-
June 30th, 2009, 05:27 PM
#1
How to use an unmanaged C library from a VC++ CLI project
I need to access two external APIs: one a native C interface (no classes), the other a C# .NET assembly. I have build a CLI Windows Forms project in VC++ 2008 that can access the .NET assembly.
When I attempt to link the LIB file for the native DLL, I get the message,
LNK1313: ijw/native module detected; cannot link with pure modules
I have tried different compiler and linker settings of /CLI, but without success.
Tried: Options>Linker>Advanced>CLRImageType = Force IJW (was Default) & rebuild
Result: fatal error: LINK1309: pure module detected AssemblyInfo.cpp
Tried: AssemblyInfo.cpp > Options > C/C++>General>Compile with CLR support = /clr (was /clrure)
Result: command-line option '/clrure' inconsistent with precompiled header
How do I force the precomipled header to recompile? Build <solution> didn't work.
Am I going about this the right way?
Is there some header, assembly, compiler option, #pragma statement or other step that I am missing for mixing managed C++ with an unmanaged C library?
Thank you,
Jeff Allan
-
July 1st, 2009, 01:21 AM
#2
Re: How to use an unmanaged C library from a VC++ CLI project
Dont link to the C# .NET assembly via it's .lib file, add the dll as a reference to the project.
Darwen.
-
July 1st, 2009, 02:15 AM
#3
Re: How to use an unmanaged C library from a VC++ CLI project
for a mixed-mode dll in c++/cli you should use only /clr
/clrure stands for: Pure MSIL is comprised of MSIL instructions, so code containing functions that cannot be expressed in MSIL will prevent compilation. (source: http://msdn.microsoft.com/en-us/libr...53(VS.80).aspx)
take a look at this http://msdn.microsoft.com/en-us/libr...52(VS.80).aspx
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
July 1st, 2009, 06:35 PM
#4
Re: How to use an unmanaged C library from a VC++ CLI project
Originally Posted by darwen
Dont link to the C# .NET assembly via it's .lib file, add the dll as a reference to the project.
Darwen.
Darwen,
Thanks, that's how I am using the .NET assembly and that is working fine.
My problem is how to also include (link, reference, whatever) the native C API which is in the form a .LIB and a .DLL. Can I include the .LIB file using Project>Add Existing Iterm? Or do I reference the .DLL using Project>Options>Linker>Input>Additional Dependencies?
The problem I'm having seems to be with the "/CLR: pure" compile & link options. I will try again making everything /CLR instead.
Jeff
-
July 3rd, 2009, 02:56 PM
#5
Re: How to use an unmanaged C library from a VC++ CLI project [solution]
The solution involved 3 steps:
- setting the linker option to /CRL
- setting the compiler option for each module to /CRL
- disabling precompiled headers
FYI, I included the .LIB file of the native library using Project > Add Existing Item
Thanks to those who replied.
Jeff Allan
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|