繁体   English   中英

使用CRT库编译C ++ DLL Visual Studio链接错误

[英]Compiling C++ dll Visual Studio linking error with crt library

我很难在Visual Studio上编译C / C ++ dll。 它似乎已链接到CRT库。

一个简单的VS c ++ dll项目。 只是删除了重新编译的头文件,并添加了/ NOENTRY。 导出方法可以使用,但是一个简单的类(不打算导出)会在CRT库中引发很多链接错误:

Test.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();

测试文件

#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选项。 删除它解决了问题

/NOENTRY用于创建完全没有任何代码且仅包含位图等的dll: https ://docs.microsoft.com/zh-cn/cpp/build/creating-a-resource-only-dll?view = vs-2017

由于dll(应该)没有代码,因此Visual Studio也不会在运行时库中链接,但是由于有代码,它会生成未解析的运行时库符号的要求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM