简体   繁体   English

qt-creator和msvc无法添加(静态)库

[英]qt-creator and msvc can't add a (static) library

I have a 3rd party (closed source) static library (.lib) written in C, with a C++ compatible header and a very simple C++ test program. 我有一个用C语言编写的第三方(闭源)静态库(.lib),带有C ++兼容的头文件和一个非常简单的C ++测试程序。

After creating a new project in Qt-creator, I tried to compile the program and link to the static library, but the linker cannot resolve the symbols: "Unresolved external symbol", error LNK2019. 在Qt-creator中创建新项目后,我尝试编译程序并链接到静态库,但链接器无法解析符号:“未解析的外部符号”,错误LNK2019。

I am using Qt 5.3 with the compiler from VisualC++ 2013 Express (which I think is MSVC12), and the .pro file used in Qt-creator is the following: 我使用Qt 5.3与VisualC ++ 2013 Express(我认为是MSVC12)的编译器,Qt-creator中使用的.pro文件如下:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

LIBS += -L"C:/Users/myuser/myproject" -lsomelib

SOURCES += main.cpp

HEADERS += \
    somelib.h

assuming that in C:\\Users\\myuser\\myproject there are the following two files: 假设在C:\\Users\\myuser\\myproject有以下两个文件:

  • libsomelib.lib libsomelib.lib
  • somelib.h somelib.h

I am not sure about what to provide in the -l flag, so I tried with libsomelib.lib , libsomelib and somelib as I would do in Linux, but every combination was unsuccessful. 我不确定在-l标志中提供什么,所以我尝试使用libsomelib.liblibsomelibsomelib就像在Linux中一样,但是每个组合都不成功。

This is my first time using MSVC from Qt-creator (not that I have much experience with it), so I cannot really understand the linking command issued by qt-creator, which includes manifest files that I do not know, and - apparently - no files or libraries are listed explicitly in the command: 这是我第一次使用来自Qt-creator的MSVC(并非我对它有很多经验),所以我无法理解qt-creator发出的链接命令,其中包括我不知道的清单文件,并且 - 显然 - 命令中未明确列出任何文件或库:

link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\myproject.exe.embed.manifest /OUT:debug\myproject.exe @C:\Users\myuser\AppData\Local\Temp\myproject.exe.4260.531.jom

Note that if I do not use qmake and compile this example by hand using cl and link , the program links just fine. 请注意,如果我不使用qmake并使用cllink手动编译此示例,则程序链接就可以了。 To achieve this, I use the commands: 为此,我使用命令:

cl /MT /EHsc /c main.cpp 
link /LIBPATH:C:\Users\myuser\myproject libsomelib.lib main.obj  /out:test.exe

How can I fix that? 我该如何解决这个问题? Thanks in advance! 提前致谢!

Somehow I managed to compile the code using MSVC. 不知何故,我设法使用MSVC编译代码。

I tried to reproduce the compilation on Qt-Creator but without success; 我尝试在Qt-Creator上重现编译,但没有成功; also tried to export a qmake project from VS using the Qt Add-in, but the issue persist in qt creator. 还试图使用Qt Add-in从VS导出qmake项目,但问题仍存在于qt creator中。 So I'm giving up and continue to use VS to compile. 所以我放弃并继续使用VS进行编译。

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

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