我想用Microsoft Linker从我的对象文件中手动导出函数。当我像这样使用每个函数的参数时,它工作得很好:
/Export:ExportedFunction1$qqsv /Export:ExportedFunction2$qqsv and so on...然后,链接器自动分配正确的词条。然而,在导出表中,实际的导出名称是"ExportedFunction1$qqsv/ExportedFunction2$qqsv/etc..“,我尝试了参数,如下所示:
/Export:ExportedFunction1$qqsv,1,ExportedFunction1 /Export:ExportedFunction2$qqsv,2,ExportedFunction2但是我想我使用的参数是错误的?!如何正确使用/Export参数为导出指定自己的名称?
附注:我使用的是Microsoft (R) Incremental Linker版本7.00.9210
发布于 2013-02-21 04:02:20
下面是一个包含DEF文件的示例解决方案。
DLL-项目:
CppLib.h:
#ifdef CPPLIB_EXPORTS
#define CPPLIB_API __declspec(dllexport)
#else
#define CPPLIB_API __declspec(dllimport)
#endif
CPPLIB_API double MyFunction1(double);CppLib.cpp:
CPPLIB_API double MyFunction1(double dd)
{
return dd;
}CppLib.def:
LIBRARY
EXPORTS
MySuperFunction=MyFunction1 @1构建DLL。
如果我们在CppLib.DLL上运行,我们会得到:
...
ordinal hint RVA name
2 0 0001101E ?MyFunction1@@YANN@Z = @ILT+25(?MyFunction1@@YANN@Z)
1 1 0001101E MySuperFunction = @ILT+25(?MyFunction1@@YANN@Z)
...使用CppLib.dll的控制台应用程序:
#include "CppLib.h"
#include <Windows.h>
#include <iostream>
int main()
{
typedef double(*MY_SUPER_FUNC)(double);
HMODULE hm = LoadLibraryW(L"CppLib.dll");
MY_SUPER_FUNC fn1 = (MY_SUPER_FUNC)GetProcAddress(hm, "MySuperFunction"); // find by name
MY_SUPER_FUNC fn2 = (MY_SUPER_FUNC)GetProcAddress(hm, MAKEINTRESOURCEA(1)); // find by ordinal
std::cout << fn1(34.5) << std::endl; // prints 34.5
std::cout << fn2(12.3) << std::endl; // prints 12.3
return 0;
}发布于 2013-02-19 21:26:02
#pragma comment(linker, "/EXPORT:ExportedFunction1$qqsv=_YouMangledFunction1@@")
#pragma comment(linker, "/EXPORT:ExportedFunction2$qqsv=_YouMangledFunction2@@")发布于 2013-02-19 05:21:21
我不相信您可以使用/Export命令行开关来实现这种控制,但是您可以使用.DEF文件来实现:
https://docs.microsoft.com/en-us/cpp/build/reference/exports
https://stackoverflow.com/questions/14713419
复制相似问题