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 /clr:pure)
Result: command-line option '/clr:pure' 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
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.
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
/clr:pure 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
Re: How to use an unmanaged C library from a VC++ CLI project
Quote:
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
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