【问题标题】:LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.objLNK2038:检测到“RuntimeLibrary”不匹配:值“MT_StaticRelease”与 main.obj 中的值“MD_DynamicRelease”不匹配
【发布时间】:2019-04-17 05:04:21
【问题描述】:

我正在尝试使用 msvc2017 从 github 编译 essnac-ng 库,以在现有的 qt-Project 中使用。

我设法使用 msys2(使用 make、autoconf、automake、yacc、bison)和 powershell 编译它:

cmd.exe /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86 `& powershell
cd D:\Projekte\esnacc-ng
bash ./boot.sh
bash ./configure LD=linker.exe
make
make install

问题 1:它只在编译静态库时出现以下警告:

warning: undefined symbols not allowed in x86_64-pc-msys shared libraries; building static only

在尝试了此线程所说的内容后: libtool: undefined symbols not allowed in i686-pc-mingw32 shared 我在制作过程中遇到错误:

cl : Befehlszeile error D8021 : Ungültiges numerisches Argument /Wl,-DLL,-IMPLIB:cxx-lib/.libs/cxxasn1.dll.lib.
make[1]: *** [Makefile:1641: cxx-lib/libcxxasn1.la] Error 2
make[1]: Leaving directory '/d/Projekte/esnacc-ng'
make: *** [Makefile:1370: all] Error 2
PS D:\Projekte\esnacc-ng>

问题 2: 尝试在我的 pri 文件中使用这样的静态库:

LIBS += -L$$PWD/cxx-lib/libs/ -lcxxasn1
LIBS += -L$$PWD/cxx-lib/libs/ -lcxxasn1rose

INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/cxx-lib/inc

HEADERS += $$PWD/MyAsnFile.h

SOURCES += $$PWD/MyAsnFile.cpp

QMAKE_CFLAGS_MT+=$$PWD/cxx-lib/inc
QMAKE_CXXFLAGS_MT+=$$PWD/cxx-lib/inc
#QMAKE_CFLAGS_RELEASE += /MD
DISTFILES += \
    $$PWD/cxx-lib/inc/snacc.h.in

我在编译期间收到错误:

Fehler: LNK2038: Konflikt ermittelt für "RuntimeLibrary": Der Wert "MT_StaticRelease" stimmt nicht mit dem Wert "MD_DynamicRelease" in main.obj überein.

我在这里看到了这个帖子,但不确定如何将其转换为对自己有用的东西: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj

【问题讨论】:

标签: c++ visual-studio qt compiler-errors linker


【解决方案1】:

我设法这样解决它: 我从项目的源代码中删除了 stdafx.hstdafx.cpp删除了包含它的行(对于 esnacc 它是snacdll.cpp)

我编译了静态库,配置如下:

bash ./configure LD=linker.exe CFLAGS=-MD CXXFLAGS=-MD --build=i686-pc-msys --host=i686-pc-msys

并将库 cxxasn1.lib 和 cxxasn1rose.lib 添加到我的 qtproject 但是我仍然会收到链接器错误:LNK2001 错误

error lnk2001 unresolved external symbol __imp__closesocket

所以我链接到 Ws2_32.lib 库:

LIBS += -L$$PWD/cxx-lib/libs/ -lcxxasn1
LIBS += -L$$PWD/cxx-lib/libs/ -lcxxasn1rose
LIBS += -lws2_32
INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/cxx-lib/inc

HEADERS += $$PWD/CoopIts.h

SOURCES += $$PWD/CoopIts.cpp

QMAKE_CFLAGS_MT+=$$PWD/cxx-lib/inc
QMAKE_CXXFLAGS_MT+=$$PWD/cxx-lib/inc

【讨论】:

    猜你喜欢
    • 2015-05-07
    • 2021-01-29
    • 1970-01-01
    • 2016-12-30
    • 2020-12-13
    • 2016-06-24
    • 2014-12-06
    • 2021-09-23
    • 2021-12-23
    相关资源
    最近更新 更多