[solved, sort of]Porting qmake project to windows, project won't link
-
I have a project which is divided into a library and an application. The application links statically to my library.
This works fine on Linux.On windows with MinGW, I get complaints that it can't find the .a-file for my library. I've checked and it is present inside the build directory.
My .pro-files:
./noisemodeler.pro:
@TEMPLATE = subdirs
SUBDIRS = nmlib nmgui test_nmlib test_nmgui
nmgui.depends = nmlib
test_nmlib.depends = nmlib
test_nmgui.depends = nmgui@./nmlib/nmlib.pro:
@INCLUDEPATH += . .. ../dependencies
TEMPLATE = lib
CONFIG += staticlib
QMAKE_CXXFLAGS += -std=c++11
-Wall -Werror -Wextra
-pedantic-errors -Wshadow -Wwrite-strings -fshort-enums
-Wctor-dtor-privacy -Wzero-as-null-pointer-constant -Wuseless-cast
-Woverloaded-virtual -Wredundant-decls -Wsign-conversion
-Wold-style-cast
#flags that should probably be added again later:
#CMAKE_CXXFLAGS += -Weffc++SOURCES =
codegeneration/bodygenerator.cpp \... more source files
serialization/serializer.cpp
HEADERS =
codegeneration/bodygenerator.hpp \... more source files
serialization/serializer.hpp@
./nmgui/nmgui.pro:
@# Add more folders to ship with the application, here
folder_01.source = qml/noisemodeler
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01Additional import path used to resolve QML modules in Creators code model
QML_IMPORT_PATH =
TARGET = nmgui
QT += qml svgQMAKE_CXXFLAGS += -std=c++11
-Wall -Werror -Wextra
-pedantic-errors -Wwrite-strings -fshort-enums
-Woverloaded-virtual -Wredundant-decls
-Wold-style-castQt doesn't like these warnings
#QMAKE_CXXFLAGS += -Weffc++ -Wuseless-cast -Wzero-as-null-pointer-constant -Wsign-conversion -Wctor-dtor-privacy -Wshadow
The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
moduleq.cpp \.. more source files
document.cpp
HEADERS +=
moduleq.hpp \... more source files
document.hpp
Installation path
target.path =
INCLUDEPATH = . ..
LIBS += -L../nmlib -lnmlib
PRE_TARGETDEPS += ../nmlib/libnmlib.a
Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()RESOURCES +=
nmgui.qrc@The error I'm getting in qt creator is:
@cannot find -lnmlib@
End of compile output:
@g++ -Wl,-subsystem,windows -mthreads -o debug\nmgui.exe object_script.nmgui.Debug -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmaind -L../nmlib -lnmlib -LC:\Qt\Qt5.2.1\5.2.1\mingw48_32\lib -lQt5Quickd -lQt5Svgd -lQt5Qmld -lQt5Widgetsd -lQt5Networkd -lQt5Guid -lQt5Cored
c:/qt/qt5.2.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lnmlib
collect2.exe: error: ld returned 1 exit status
Makefile.Debug:142: recipe for target 'debug\nmgui.exe' failed
mingw32-make[2]: *** [debug\nmgui.exe] Error 1
mingw32-make[2]: Leaving directory 'C:/Users/johan/repos/build-noisemodeler-Desktop_Qt_5_2_1_MinGW_32bit-Debug/nmgui'
Makefile:34: recipe for target 'debug' failed
mingw32-make[1]: Leaving directory 'C:/Users/johan/repos/build-noisemodeler-Desktop_Qt_5_2_1_MinGW_32bit-Debug/nmgui'
makefile:66: recipe for target 'sub-nmgui-make_first' failed
mingw32-make[1]: *** [debug] Error 2
mingw32-make: *** [sub-nmgui-make_first] Error 2
11:03:24: The process "C:\Qt\Qt5.2.1\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project noisemodeler (kit: Desktop Qt 5.2.1 MinGW 32bit)
When executing step 'Make'
11:03:24: Elapsed time: 00:03.@Why does this work on Linux but not in Windows? I'm even using MinGW, which I assumed would be fairly similar. Have I understood something wrong about how to set the path to the library directory (-L../nmlib)?
Might this be an issue of windows having slashes pointing the wrong way?
-
Solved it :) Kind of...
So, the problem seems to be where the nmlib.a file was placed after it was built.
The folder structure of build directories is different on windows and on linux. On linux there is two separate build directories, one for debug and one for release.
@./build-noisemodeler-Debug/nmlib/nmlib.a
./build-noisemodeler-Debug/nmgui/@On windows, debug and release folders are created as subfolder of each subproject.
@./build-noisemodeler-Desktop_Qt_5_2_1_MinGW_32bit-Debug/nmlib/debug/nmlib.a
./build-noisemodeler-Desktop_Qt_5_2_1_MinGW_32bit-Debug/nmgui/@This was my fix. Feel like it is kind of dirty, though.
@win32{
LIBS += -L../nmlib/debug
PRE_TARGETDEPS += ../nmlib/debug/libnmlib.a
} else {
LIBS += -L../nmlib
PRE_TARGETDEPS += ../nmlib/libnmlib.a
}
LIBS += -lnmlib@ -
Hi,
AFAIK, it's a clean solution.
Another way would be to tell explicitly where the build output should go. But for e.g. unit test that can be problematic on Windows.