简体   繁体   中英

How to reexport CLR c++ static library

I have these files:

  • foo.dll
  • foo.lib
  • foo.exp
  • bar.il
  • bar.netmodule

"foo" defines functions in its export directory.

I also have a Visual Studio 2010 C++ project which will create a managed "bar.dll"

I want to "bar" to statically link to "foo" and reexport all functions from "foo".

In the end I want bar to export the functions from foo and some additional code defined in foo .

Using code below does not work as it references foo instead of merging bar with foo .

#pragma comment(linker, "/include:_foomethod@12")

How do I do that?

See also: http://msdn.microsoft.com/en-us/library/f0z8kac4(v=VS.100).aspx

CFF Explorer to verify export directory: http://www.ntcore.com/exsuite.php

See also: http://msdn.microsoft.com/en-us/library/k669k83h.aspx

See also: http://blogs.msdn.com/b/texblog/archive/2007/04/05/linking-native-c-into-c-applications.aspx

call "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\link.exe" /DLL /LTCG /CLRIMAGETYPE:IJW   /ASSEMBLYMODULE:bar.netmodule   /OUT:bar.dll foo.lib bar.netmodule

foo.netmodule : fatal error LNK1302: only support linking safe .netmodules; unable to link ijw/native .netmodule

I have figured it out.

Instead those files will be required:

  • foo.obj
  • bar.cpp
  • bar.obj

The C++/CLI compiler cl.exe will be able to compile bar, reference unmanaged and managed worlds.

In a later step linker will be used to merge obj files into one mixed mode assembly containing:

  • unmanaged exports from foo
  • unmanaged exports from bar
  • managed IL types from bar

Command used for linking obj files:

call "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\link.exe" /DLL /LTCG /CLRIMAGETYPE:IJW     /OUT:bar.dll *.obj

Extra: One can rename exported function names after cpp to obj compilation in the export directory to their liking :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM