我有2个dll test_dll1.c和test_dll2.c . test_dll2应该充当test_dll1的代理 . 我还有一个主程序test.c,它与test_dll2.lib链接,但链接器发出错误说“未解析的符号”,我不确定为什么 .
以下是附加的代码
test_dll1.c
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
__declspec(dllexport) void dummy1(void)
{
printf("Inside %s %s\n", __FILE__, __FUNCTION__);
return;
}
__declspec(dllexport) void dummy2(void)
{
printf("Inside %s %s\n", __FILE__, __FUNCTION__);
return;
}
cl.exe / LD test_dll1.c
test_dll2.c
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#pragma comment(linker, "/export:dummy3=test_dll1.dummy1")
#pragma comment(linker, "/export:dummy4=test_dll1.dummy2")
cl.exe / LD test_dll2.c test_forwards.c
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
__declspec(dllimport) void dummy3(void);
__declspec(dllimport) void dummy4(void);
int main()
{
dummy3();
dummy4();
}
$ cl.exe test_forwards.c test_dll2.lib
test_forwards.obj:错误LNK2019:函数_main test_forwards.obj中引用的未解析的外部符号__imp__dummy3:错误LNK2019:函数_main test_forwards.exe中引用的未解析的外部符号__imp__dummy4:致命错误LNK1120:2未解析的外部
我错过了什么?为什么链接器不能找到符号? dummy3和dummy4被定义为“test_dll2.dll”中的转发导出,因为我可以看到,如果我在test_dll2.dll中转储导出,那么导出的符号dummy3和dummy4确实存在 .
更新:顺便说一下,我将test_dll2.c更新为#pragma comment(链接器,“/ export:_dummy3 = test_dll1.dummy1”)#pragma comment(链接器,“/ export:_dummy4 = test_dll1.dummy2”)
在哪里我将dummy3和dummy4更改为_dummy3和_dummy4并且它有效 . 为什么我需要将符号名称更改为_dummy3和_dummy4?