You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

静态库被识别为动态库,LNK2038 RuntimeLibrary不匹配问题求助

静态链接第三方库时LNK2038运行时库不匹配问题

我尝试将第三方库静态链接到自己的.exe程序,以便仅需分发单个.exe文件。首先从源码编译生成了多个第三方静态.lib文件。

在Visual Studio中,将项目属性设置为Project->properties->C/C++->Code generation->Runtime Library = Multi-threaded (/MT),但链接器报错:

LNK2038 mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in ConsoleApplication1.obj

其中MT_StaticRelease符合静态链接的设置,但MD_DynamicRelease不符合,因为我提供的是静态库。已将Project->properties->Linker->General->Additional Library Dependencies指向仅包含*.lib的文件夹,且确认这些*.lib是静态库而非导入库。

当将Runtime Library改为Multi-threaded DLL (/MD)时,编译成功。Visual Studio将静态lib识别为动态库的情况非常奇怪。

已排查以下内容:

  • 检查了%PATH%以排除环境干扰;
  • 删除了之前构建的所有缓存。

相关代码如下:

#include "gdcmReader.h"

#ifdef _WIN32
#pragma comment(lib, "gdcmDSED")
#pragma comment(lib,"WS2_32")
#endif

typedef std::set<gdcm::DataElement> DataElementSet;
typedef DataElementSet::const_iterator ConstIterator;

int main(int argc, char *argv[])
{
    if (argc < 2) {
        std::cout << "Usage: xxxx.exe dicom_filename" << std::endl;
        return 1;
    }

    const char *filename = argv[1];

    gdcm::Reader reader;
    reader.SetFileName(filename);
    if (!reader.Read())
    {
        std::cerr << "Could not read: " << filename << std::endl;
        return 1;
    }
    std::stringstream strm;

    gdcm::File &file = reader.GetFile();
    gdcm::DataSet &ds = file.GetDataSet();
    gdcm::FileMetaInformation &fmi = file.GetHeader();


    if (ds.FindDataElement(gdcm::Tag(0x10, 0x10))) {
        const gdcm::DataElement &de = ds.GetDataElement(gdcm::Tag(0x10, 0x10));
        std::cout << de << std::endl;
    }
    return 0;
}

内容的提问来源于stack exchange,提问作者Mark Hayes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 05:36:06