我很难在 Visual Studio 上编译 C/C++ dll。它似乎链接到 CRT 库。
一个简单的 VS c++ dll 项目。刚刚删除了重新编译的 header ,并添加了/NOENTRY。导出方法是有效的,但是一个简单的类(不打算导出)会引发很多与 CRT 库的链接错误:
测试.h:
class ITest
{
public:
virtual void foo() = 0;
}
class Test final : public ITest
{
public:
Test();
~Test();
void foo();
};
// extern "C" __declspec(dllexport) ITest* __cdecl CreateTest();
测试.cpp
#include "Test.h"
Test::Test() {}
Test::~Test() {}
Test::foo() {}
// extern "C" __declspec(dllexport) ITest* __cdecl CreateTest() { return new Test; }
错误:
Test.obj : error LNK2001: unresolved external symbol _purecall
msvcrt.lib(delete_scalar.obj) : error LNK2019: unresolved external symbol free referenced in function "void __cdecl operator delete(void *)" (??3@YAXPEAX@Z)
取消注释导出会引发更多 msvcrt.lib 链接错误,更改 MDd、MT、MTd 的运行时库只会更改引用的库。
感谢您的帮助:)
最佳答案
问题来自项目属性->链接器->高级->无入口点中的/NOENTRY 选项。删除它解决了问题
关于c++ - 编译 C++ dll Visual Studio 链接错误与 crt 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54673682/