我尝试从 Verialtor 源代码制作一个 .dll,因为他们已经实现了这种可能性。
他们使用通用处理程序typedef void* svScope
来初始化范围。.dll 也使用此句柄。现在我可以使用创建新功能
__declspec(dllexport) svScope svGetScope( void );
这是头代码 svdpi.h
#ifndef INCLUDED_SVDPI
#define INCLUDED_SVDPI
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) typedef void* svScope;
__declspec(dllexport) svScope svGetScope( void );
#ifdef __cplusplus
}
#endif
#endif
和一个简单的实现 svdpi.cpp
#include "svdpi.h"
svScope svGetScope() {return 0;}
我已经创建了测试文件 test.cpp
#include <stdlib.h>
#include <stdio.h>
#include "svdpi.h"
int main()
{
svScope Scope = svGetScope();
}
我编译了库并链接了它。编译器找到库但我收到此错误
g++ -o test.exe -s test.o -L。-lsvdpi
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(. text+0xf): undefined reference to `_imp__svGetScope' collect2.exe: error: ld returned 1 exit status