I am using QT Creator 2.7.0 based upon QT 5.0.2 on a Windows 7 machine and attempted to create a subdirs project with three sub-projects.
Project_Dir
- DbManager
- Gui
- Build
Using the example here How to use qmakes subdirs template, I created the Project files listed below, however, upon building I keep getting the error LNK1104 Cannot open file 'DbManager.lib'
My search usually yeilds results for Visual Studio type fixes, but no QT fixes
Project.pro
TEMPLATE = subdirs
SUBDIRS += \
DbManager \
Gui
CONFIG += ordered
SUBDIRS += Build
DbManager.pro
! include( ../common.pri ) {
error( Couldnt find the common.pri file! )
}
HEADERS += dbmanager.h
SOURCES += dbmanager.cpp
Gui.pro
! include( ../common.pri ) {
error( Couldnt find the common.pri file! )
}
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = target
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
Build.pro
TEMPLATE = app
DEPENDPATH += ../Gui
INCLUDEPATH += ../Gui
DEPENDPATH += ../DbManager
INCLUDEPATH += ../DbManager
LIBS += -L../DbManager -L../Gui -lDbManager -lGui
SOURCES += main.cpp
TARGET = ../OptionsTrader
QT += widgets
The following "Common.pri" file, was also included:
INCLUDEPATH += . ..
WARNINGS += -Wall
TEMPLATE = lib
UI_DIR = uics
MOC_DIR = mocs
OBJECTS_DIR = objs
I got the same problem before, and I just copy the lib file into the project working directory,it worked.
Related
I have created a project in qt creator with multiple subdirs and am deploying/running it on a beaglebone. Compiles fine, deploys fine, etc.
My issue is that when I try to debug, the only files I can set breakpoints in or step into are those in the same subdir where main.cpp is. Just to test, I duplicated the project with a flat folder structure and can set breakpoints and step into everything.
When the debugger starts up, the debug log tries to set the breakpoints and fails seemingly because it can't find the .cpp files:
"No source file named projectdir/dir1/myclass.cpp.\n"
8045^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="",pending="\"projectdir/dir1/myclass.cpp\":7",times="0",original-location="\"fullpathofprojectdir/dir1/myclass.cpp\":7"}
Whereas it says this for breakpoints in main:
8046^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x0001831c",func="main(int, char**)",file="projectdir/dir2/main.cpp",fullname="fullpathofprojectdir/dir2/main.cpp",line="27",thread-groups=["i1"],times="0",original-location="fullpathofprojectdir/dir2/main.cpp:27"}
Additionally, myclass.cpp doesn't show up in the source files panes either. How can I resolve this?
Here is the setup of my *.pro files:
Top level project file:
TEMPLATE = subdirs
SUBDIRS += \
dir1 \
dir2
unix {
target.path = /home/debian
INSTALLS += target
}
Project file of library (dir1, myclass.cpp, etc):
QT -= gui
TARGET = Common
TEMPLATE = lib
DEFINES += COMMON_LIBRARY
SOURCES += \
myclass.cpp
HEADERS += \
common_global.h \
myclass.h
unix {
target.path = /home/debian/lib
INSTALLS += target
}
CONFIG += debug
Project file containing main:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Test
TEMPLATE = app
SOURCES += \
main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Common/release/
-lCommon
else:win32:CONFIG(debug, debug|release): LIBS += -
L$$OUT_PWD/../Common/debug/ -lCommon
else:unix: LIBS += -L$$OUT_PWD/../Common/ -lCommon
INCLUDEPATH += $$PWD/../Common
DEPENDPATH += $$PWD/../Common
target.path = /home/debian
INSTALLS += target
Let me know if there's any other relevant data I forgot to provide. Qt Creator version is 4.5.0 and I'm running it on a 64 bit VM of ubuntu 16.04 if that's relevant.
I am trying to follow qt creators instructions to create static libraries.
https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
it shows the below for lines to include in my libraries .pro
TEMPLATE = lib
CONFIG += staticlib
# Input
HEADERS += test.h
SOURCES += test.cpp
and for the apps .pro
TEMPLATE = app
TARGET =
CONFIG += console
# Input
SOURCES += main.cpp
INCLUDEPATH += ../staticLibrary
LIBS += -L../staticLibrary/debug -lstaticLibrary
I have
library's .pro
QT -= gui
TARGET = test
TEMPLATE = lib
CONFIG += staticlib
SOURCES += test.cpp
HEADERS += test.h
unix {
target.path = /usr/lib
INSTALLS += target
}
app's .pro
QT += core
QT -= gui
CONFIG += c++11
TARGET = TestLink
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += ../test // ADDED BY ME
LIBS += -L../test/debug -ltest //ADDED BY ME
// LIBS += -L../test/debug -ltest.a //ALSO TRIED .a
My library is test. Both folder, the main app and the library are in the same folder. When I now include the .h
#include "test.h"
I get
C:\CPP\Test\TestLink\main.cpp:3: error: C1083: Cannot open include file: 'test.h': No such file or directory
It seems I am following the isntructions here. What am I missing?
This here also suggests the two lines I added should do the job
Using a static library in Qt Creator
Have tried to "link" two projects together. So one project knows the other ones classes. One project is the program, the other project is a test program for the first one. So i want the test program to have access to the other ones classes so i can test them.
Both projects are sub projects.
They are placed under header project, there folders are beside each other.
Have tried many different ways but with no result.
Head.pro
TEMPLATE = subdirs
SUBDIRS += \
MT \
Test
MT.pri same folder as the program.
INCLUDEPATH += $$PWD
SOURCES += $$PWD/parser.cpp
HEADERS += $$PWD/parser.h
MT.pro
QT += core bluetooth gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MT
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG += mobility
SOURCES += main.cpp\
mainwindow.cpp \
t.cpp \
parser.cpp \
devicediscovery.cpp
HEADERS += mainwindow.h \
parser.h \
devicediscovery.h \
t.h \
typedefs.h
FORMS += mainwindow.ui
MOBILITY =
INSTALLS += target
DISTFILES += \
MT.pri
Test.pro
include(../MT/MT.pri)
QT += widgets testlib core bluetooth gui
TARGET = tst_testmttest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
HEADERS += parser.h
SOURCES += tst_testmttest.cpp / parser.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
Use in Test Project:
include(Path/to/OtherProject/file.pri)
Use in Other project
QT += xml
INCLUDEPATH += $$PWD
SOURCES += $$PWD/parser.cpp
HEADERS += $$PWD/parser.h
works fine
I'm using QT(5)-Creator with 2 projects, that compile both with MinGW my C++ programs under Windows 7. One project generates a static library, and the other is just there to verify that the library is alright.
The error:
When building the library no errors are generated and it creates successfully the static lib MyClassName.a.
In turn, when trying to import the library, I get error messages durring building/compilation:
undefined reference to 'MyClassName::MyClassName()'
undefined reference to 'MyClassName::MyClassFunction()'
The files:
here's the main.cpp of my importer project
#include <QCoreApplication>
#include "MyClassName.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyClassName *mainThread = new MyClassName();
mainThread->MyClassFunction();
return a.exec();
}
and it's .pro file
QT += core
QT += widgets
QT -= gui
TARGET = TESTerase
CONFIG += console
CONFIG -= app_bundle
CONFIG +=extserialport
CONFIG +=staticlib
TEMPLATE = app
HEADERS += \
MyClassName.h
SOURCES += main.cpp
unix:!macx: LIBS += -L$$PWD/../MyClassName-Release/ -lMyClassName
INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/../MyClassName-Release/release
DEPENDPATH += $$PWD/../MyClassName-Release/release
unix:!macx: PRE_TARGETDEPS += $$PWD/../MyClassName-Release/release/MyClassName.a
btw I've used QT-Creator's include external library function
My guesses:
Since I'm able to [Strg+Click] the functions in the main, I assume the error is thrown by the Linker.
It may also be a manner of importing/creating/using libraries too, since I just started with that topic.
Anyways searching the Internet about it usually just results in the hint, to use the same compiler for both projects - which shouldn't matter in my case (since I'm building both projects with the same Creator and the same settings).
Has anybody an idea?
Thanks for your support
Kind Regards
[Update for Bogdans request]
the new .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2015-04-29T19:46:22
#
#-------------------------------------------------
QT += core
QT += widgets
QT -= gui
TARGET = TESTerase
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG +=extserialport
HEADERS += \
MyClassName.h
SOURCES += main.cpp
unix:!macx: LIBS += -L$$PWD/../MyClassName-Release/ -lMyClassName
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyClassName-Release/release/ -lMyClassName
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyClassName-Release/debug/ -lMyClassName
else:unix:!macx: LIBS += -L$$PWD/../MyClassName-Release/ -lMyClassName
INCLUDEPATH += $$PWD/../MyClassName-Release/release
DEPENDPATH += $$PWD/../MyClassName-Release/release
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/release/MyClassName.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/debug/MyClassName.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/release/MyClassName.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/debug/MyClassName.lib
else:unix:!macx: PRE_TARGETDEPS += $$PWD/../MyClassName-Release/MyClassName.a
Your .pro file defines library dependencies only for unix platform unix:!macx:. I suppose there should be also win32 for Windows.
Had the same problem just now. Build was working fine on macOS/OSX but not on Windows with the same codebase.
It was caused by the fact I was not exporting my symbols, which is necessary on Windows.
Use Q_DECL_EXPORT on functions when building the lib.
And use Q_DECL_IMPORT when using the functions from the lib.
Example how to do this here: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application#Creating_a_shared_library
Solved the problem in my case, hope it helps!
I have trouble in making an application which communicates FTDI devices via D2xx driver.There is some example project for Visual Studio in ftdi's website. But there isn't for QtCreator. I chose QtCreator as c++ IDE because my application needs Qt framework.
I put ftd2xx.h and ftd2xx.lib in the Qt project directory.
(ftd2xx.lib is static library, which were originally located in [download-folder]\CDM v2.08.30 for Windows 8.1\Static\i386)
When sample source code was compiled, I got following error message.
Error message when I use .pro file(1).
LNK1104: cannot open file 'ftd2xx.lib'
Error message when I use .pro file(2).
error: Assignment needs exactly one word on the left hand side.
How should I correct Qt project setup in order to utilizes ftd2xx library?
My source code and .pro file is here.
[main.cpp]
#include <QCoreApplication>
#include <windows.h>
#include "ftd2xx.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
FT_HANDLE ftHandle;
FT_STATUS ftStatus;
ftStatus = FT_Open(0,&ftHandle);
return a.exec();
}
[.pro file if the checkbox is enabled] ---(1)
#-------------------------------------------------
#
# Project created by QtCreator 2014-02-11T18:51:08
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = D2XXtest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
HEADERS += ftd2xx.h
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -lftd2xx
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -lftd2xxd
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/libftd2xx.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/libftd2xxd.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/ftd2xx.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/ftd2xxd.lib
[.pro file if the checkbox is NOT enabled] ---(2)
#-------------------------------------------------
#
# Project created by QtCreator 2014-02-11T18:51:08
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = D2XXtest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
HEADERS += ftd2xx.h
win32: LIBS += -L$$PWD/ -lftd2xx
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32:!win32-g++ PRE_TARGETDEPS += $$PWD/ftd2xx.lib
else:win32-g++: PRE_TARGETDEPS += $$PWD/libftd2xx.a
Any help would be appreciated. Thanks in advance.
[Note]
OS: Windows 8.1
IDE: Qt Creator 3.0.0
Compiler: MSVC2012(32bit)
Target device: ft232hl
[Additional Note]
The configuration of "Add Library" is following.
If I enable the checkbox "Add "d" suffix for debug version, then I got error message about LNK1104. Otherwise, I got different error message.
My hunch is that you've made a typo in your error message, and the real error message reads as follows:
LNK1104: cannot open file 'ftd2xxd.lib'
See that d there? It doesn't belong, there's no ftd2xxd.lib. You need to change any references to ftd2xxd.lib back to ftd2xx.lib, re-run qmake, and you should be all set. Otherwise your .pro file seems correct.
After your edit, you gave a .pro file with the "checkbox enabled". That's certainly not true, since the contents you show imply that the checkbox is disabled, not enabled.
Anyway, we don't care what the dialog box settings are. Just show the actual .pro file that you really use, because so far I don't know which one you do use, and I don't know if you've re-run qmake after the .pro file was changed.
Are you sure that the ftd2xx.lib file is actually in the same folder where the .pro file is?