简体   繁体   English

如何重新导出CLR C ++静态库

[英]How to reexport CLR c++ static library

I have these files: 我有这些文件:

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

"foo" defines functions in its export directory. “ foo”在其导出目录中定义函数。

I also have a Visual Studio 2010 C++ project which will create a managed "bar.dll" 我也有一个Visual Studio 2010 C ++项目,它将创建一个托管的“ bar.dll”

I want to "bar" to statically link to "foo" and reexport all functions from "foo". 我想“禁止”静态链接到“ foo”,然后从“ foo”重新导出所有功能。

In the end I want bar to export the functions from foo and some additional code defined in foo . 最后,我想禁止foofoo中定义了一些额外的代码导出功能。

Using code below does not work as it references foo instead of merging bar with foo . 使用下面的代码不起作用,因为它引用foo而不是将barfoo合并。

#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 另请参阅: http : //msdn.microsoft.com/zh-cn/library/f0z8kac4(v=VS.100).aspx

CFF Explorer to verify export directory: http://www.ntcore.com/exsuite.php CFF Explorer来验证导出目录: http : //www.ntcore.com/exsuite.php

See also: http://msdn.microsoft.com/en-us/library/k669k83h.aspx 另请参阅: 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 另请参阅: 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 foo.obj
  • bar.cpp bar.cpp
  • bar.obj bar.obj

The C++/CLI compiler cl.exe will be able to compile bar, reference unmanaged and managed worlds. C ++ / CLI编译器cl.exe将能够编译bar,引用不受管和受管世界。

In a later step linker will be used to merge obj files into one mixed mode assembly containing: 在后续步骤中,将使用链接器将obj文件合并到一个包含以下内容的混合模式程序集中:

  • unmanaged exports from foo foo的不受管理的出口
  • unmanaged exports from bar 酒吧不受管理的出口
  • managed IL types from bar 从栏管理的IL类型

Command used for linking obj files: 用于链接obj文件的命令:

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 :) 附加:可以根据自己的喜好在导出目录中的cpp至obj编译后重命名导出的函数名称:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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