Visual c++ 有没有办法强制链接器使用函数名而不是序号来导入函数?
创建一个DLL项目Visual c++ 有没有办法强制链接器使用函数名而不是序号来导入函数?,visual-c++,linker,Visual C++,Linker,创建一个DLL项目 void foo() { printf("foo"); } def 创建一个客户端项目 void foo(); int _tmain(int argc, _TCHAR* argv[]) { foo(); return 0; } 客户端可执行文件的导入表。 导入表中缺少函数名 您能告诉我,有没有办法强制链接器使用函数名?创建第二个不带序号的导入库: >type foo.names.def LIBRARY foo.dll E
void foo() {
printf("foo");
}
def
创建一个客户端项目
void foo();
int _tmain(int argc, _TCHAR* argv[])
{
foo();
return 0;
}
客户端可执行文件的导入表。
导入表中缺少函数名
您能告诉我,有没有办法强制链接器使用函数名?创建第二个不带序号的导入库:
>type foo.names.def
LIBRARY foo.dll
EXPORTS
foo
>lib /nologo /def:foo.names.def /machine:x86
Creating library foo.names.lib and object foo.names.exp
用法示例:
>type test.c
void foo();
int main()
{
foo();
return 0;
}
>cl /nologo test.c /link foo.names.lib
test.c
>dumpbin /nologo /imports:foo.dll test.exe
Dump of file test.exe
File Type: EXECUTABLE IMAGE
Section contains the following imports:
foo.dll
40C108 Import Address Table
410AA0 Import Name Table
0 time date stamp
0 Index of first forwarder reference
0 foo
与使用原始导入库时得到的结果进行对比:
>cl /nologo test.c /link foo.lib
test.c
>dumpbin /nologo /imports:foo.dll test.exe
Dump of file test.exe
File Type: EXECUTABLE IMAGE
Section contains the following imports:
foo.dll
40C108 Import Address Table
410AA0 Import Name Table
0 time date stamp
0 Index of first forwarder reference
Ordinal 1
如果我能修改图书馆怎么办?@Jichao:我不明白这个问题。如果希望将非顺序导入库命名为foo.lib,则可以告诉lib命令使用该名称构建库。
>cl /nologo test.c /link foo.lib
test.c
>dumpbin /nologo /imports:foo.dll test.exe
Dump of file test.exe
File Type: EXECUTABLE IMAGE
Section contains the following imports:
foo.dll
40C108 Import Address Table
410AA0 Import Name Table
0 time date stamp
0 Index of first forwarder reference
Ordinal 1