简体   繁体   中英

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.

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.

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:

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:

  • libsomelib.lib
  • 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.

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:

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. 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.

I tried to reproduce the compilation on Qt-Creator but without success; also tried to export a qmake project from VS using the Qt Add-in, but the issue persist in qt creator. So I'm giving up and continue to use VS to compile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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