How do I include muparser library in my Qt project? - qt

I made a muparser.pri which had the following content,
macx|win32|equals(build_muparser, "true")|!packagesExist(muparser){
message("Using bundled muparser")
MUPARSER_DIR = src/rel/muparser
DEPENDPATH += $$MUPARSER_DIR/include \
$$MUPARSER_DIR/src
INCLUDEPATH += $$MUPARSER_DIR/include
GEN_LIB_DIR = ../../generated/lib
LIBS += -L$$GEN_LIB_DIR -lmuparser
PRE_TARGETDEPS += $$GEN_LIB_DIR/libmuparser.a
}else{
message("Using external muparser")
CONFIG += link_pkgconfig
PKGCONFIG += muparser
}
I, then, added a
include(./muparser.pri)
in my application's make file.
This gave me an error
":-1: error: No rule to make target '../../generated/lib/libmuparser.a', needed by 'debug/Akaar1.exe'. Stop."
What did I do wrong? How else am I supposed to include this library in my project?

In your .pro file you can do:
LIBS += -L*path to the library* -l*library name: foo for libfoo.a*

Related

Qt compile error : glib/galloca.h not found in glib-2.0/glib.h

I've the following error during Qt compiling phase :
In file included from ../test_ble2/main.cpp:12:
/opt/fsl-imx-xwayland/5.10-hardknott/sysroots/cortexa53-crypto-poky-linux/usr/include/glib-2.0/glib.h:30:10: fatal error: glib/galloca.h: No such file or directory
30 | #include <glib/galloca.h>
compilation terminated.
make: *** [Makefile:723: main.o] Error 1
looking for *.h and I found it on the board so the problem seems in *.pro file :
QT += quick
LIBS += -lbluetooth
LIBS += -lpython3
LIBS += -llibglib-2.0
SOURCES += \
main.cpp
RESOURCES += qml.qrc
QML_IMPORT_PATH =
QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
packagesExist(glib-2.0) {
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0
}
HEADERS += \
include/gattlib.h
unix:!macx: LIBS += -L$$PWD/lib/ -lgattlib
INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD/include
but I' dont fix it, any suggestion?
The platform is yocto form imx8.
Any suggestion? Thanks in advance

Why lupdate not include qml qstr string into .ts file?

I have this .pro file :
TEMPLATE = subdirs
SUBDIRS += internal app
app.depends = internal
app.subdir = src/app
internal.subdir = src/internal
TRANSLATIONS = \
$$PWD/translations/croatian.ts \
$$PWD/translations/danish.ts \
$$PWD/translations/english.ts \
$$PWD/translations/french.ts \
$$PWD/translations/german.ts \
$$PWD/translations/italian.ts \
$$PWD/translations/norwegian.ts \
$$PWD/translations/portuguese.ts \
$$PWD/translations/romanian.ts \
$$PWD/translations/spanish.ts
internal.pro is this:
TEMPLATE = lib
TARGET = internal
CONFIG += c++1z
QT += core core-private gui quick serialport sql multimedia
DEFINES += CURRENT_PATH=\\\"$$PWD\\\"
CONFIG(release, debug|release) {
CONFIG += qtquickcompiler
QMAKE_CXXFLAGS += -O3
}
CONFIG(debug, debug|release) {
QMAKE_CXXFLAGS += -O0
QMAKE_CXXFLAGS -= -O1
QMAKE_CXXFLAGS -= -O2
QMAKE_CXXFLAGS -= -O3
QMAKE_CXXFLAGS += --debug
}
#MS_SKELETON_MODULES = core utils network
#include($$PWD/../external/ms-skeleton/ms-skeleton.pri)
include($$PWD/aggiornamento/aggiornamento.pri)
include($$PWD/allarmi/allarmi.pri)
include($$PWD/comunicazione/comunicazione.pri)
include($$PWD/core/core.pri)
include($$PWD/jsoncpp/jsoncpp.pri)
include($$PWD/mqtt/mqtt.pri)
include($$PWD/other/other.pri)
include($$PWD/parametri/parametri.pri)
include($$PWD/programs/programs.pri)
include($$PWD/serializer/serializer.pri)
unix: target.path = /opt/Tagliavini/lib
!isEmpty(target.path): INSTALLS += target
and app.pro is this :
TEMPLATE = app
TARGET = UserInterface
CONFIG += c++1z
QT += core gui quick sql multimedia
DEFINES += CURRENT_PATH=\\\"$$PWD\\\"
CONFIG(release, debug|release) {
CONFIG += qtquickcompiler
QMAKE_CXXFLAGS += -O3
}
CONFIG(debug, debug|release) {
QMAKE_CXXFLAGS += -O0
QMAKE_CXXFLAGS -= -O1
QMAKE_CXXFLAGS -= -O2
QMAKE_CXXFLAGS -= -O3
QMAKE_CXXFLAGS += --debug
}
LIBS += -L$$shadowed($$PWD)/../internal/ -linternal
INCLUDEPATH += \
$$PWD/../internal \
$$PWD/../external/ms-skeleton
SOURCES += $$PWD/main.cpp
RESOURCES += \
$$PWD/../../font/fonts.qrc \
$$PWD/../../images/images.qrc \
$$PWD/qml/qml.qrc \
$$PWD/../../sounds/sounds.qrc
unix: target.path = /opt/Tagliavini/bin
!isEmpty(target.path): INSTALLS += target
when i try to create file .ts with lupdate , the files are generated correctly , but the file .ts not cointeins the qstr strings that are into qml files. ( the file qml are into app.pro ), instead the string that i want to translate into .cpp files are all recognized correctly and put into .ts file.(these are into internal.pro) Where is the problem??
It seems that you are including your .qml files in .qrc resources but not in the project SOURCES itself. lupdate will not pick/parse your .qrc files to list .qml files.
So, you will have to add your .qml files to SOURCES either one-by-one or per directory.
lupdate_only{
SOURCES+=example.qml
SOURCES+=app/FancyControls/*.qml
}
This will duplicate your QML file entries in Qt Creator project pane tree which is not very desirable. So, you can comment out those lines in your .pro file and uncomment it before any lupdate. It's also mandatory to fence those imports in lupdate_only{} conditional statement. Make sure that there is no space between lupdate_only and the curly bracket. Actually, your C/C++ compiler would not expect a qml file to be compiled.

QMake subdir Template outputs into the build directory instead of the main directory

I am trying to use qmake's subdirs template. The problem is that the output directory specified in the sub projects is created in the build directory instead of the directory that is being referenced in the projects. other then that everything works normally. I was wondering if there is a way to fix this.
Dir Structure
build-project_dir/
-Apps/ --this gets created
-Other things
project_dir/
-main.pro
-Apps/ -- I want it to use this instead
-Server/
----Server.pro
----some logic files
-Parser/
----Parser.pro
----Parser files
-muparser/
-build/
----muparser.pro
----main.cpp
Main.pro
TEMPLATE = subdirs
# where to find the sub projects - give the folders
Server.subdir = Server
Parser.subdir = Parser
muparser.file = muparser-2.2.5\build\muparser.pro
# what subproject depends on others
Server.depends = Parser
Parser.depends = muparser
SUBDIRS = muparser Parser Server
Server.pro
TEMPLATE = app
QT += core sql websockets xml
QT -= gui
TARGET = Server
CONFIG += console
CONFIG -= app_bundle
CONFIG += thread
SOURCES += $$files(src/*.cpp, true) $$files(src/*.c, true)
HEADERS += $$files(src/*.h, true)
INCLUDEPATH += src src/things/include
LIBS += -L../lib -lParser
DESTDIR = ../Apps
Parser.pro
TEMPLATE = lib
QT -= gui
TARGET = Parser
DEFINES += PARSER_LIBRARY
SOURCES += parser.cpp
HEADERS += parser.h
INCLUDEPATH += ./include
DEPENDPATH += $$PWD/./
LIBS += -L../lib -lmuparser
DESTDIR += ../lib
DLLDESTDIR += ../Apps
The reason for this is because there are DLL that are needed there.
Thank to Bill I was able to find a solution to the problem
I simply had to change the DESTDIR location for my apps to DESTDIR = $$_PRO_FILE_PWD_/../Apps_Win

Qwt framework not found

Good Morning,
I am currently trying to build a project in QT that uses the Qwt library. However, when I try to build the project I get
warning: directory not found for option '-F/usr/local/qwt-6.1.0/lib'
error:framework not found qwt
error:linker command failed with exit code 1
I have followed the steps in this post as well as this post but it still cannot find the framework
I am using Xcode 6, Qwt 6, QT 5.3, and Mac OSX 10.9.
My .pro file's relevant code is as follows:
#mac: QMAKE_MAC_SDK.macosx.path = Applications/Xcode.app/Contents/Developer/Patforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
#mac: QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9 #Added to help build QWT
#INCLUDEPATH += /usr/local/qwt-6.1.0/qwt.prf
include (/usr/local/qwt-6.1.0/qwt.prf )
#CONFIG += qwt
#macx:QMAKE_MAC_SDK += macosx10.9
QMAKEFEATURES += /usr/local/qwt-6.1.0/features
CONFIG += qwt
#mac:INCLUDEPATH += /Library/Frameworks/qwt.framework/Headers
#mac: INCLUDEPATH += /usr/local/qwt-6.1.0/src
mac: INCLUDEPATH += /usr/local.qwt-6.1.0/lib/qwt.framework/Headers
linux-g++:INCLUDEPATH += /usr/local/qwt-5.2.1/include
win32:INCLUDEPATH += C:/Qwt-5.2.1/include
FORMS += ui/
UI_HEADERS_DIR = inc_ui
OBJECTS_DIR = obj
MOC_DIR = moc
#mac:LIBS += /usr/local/qwt-6.1.0/lib -framework qwt
#mac:LIBS += -l /usr/local/qwt-6.1.0/lib/qwt.framework
mac:LIBS += -F /usr/local/qwt-6.1.0/lib -framework qwt
linux-g++:LIBS += /usr/local/qwt-5.2.1/lib/libqwt.so
win32:LIBS += C:/Qwt-5.2.1/lib/qwt5.dll
Any help is appreciated,
Thanks.

Linking Qt DLL to Qt App - unresolved references

I've just installed Qt 4.7.4 and trying to make a simple Qt App that uses Qt DLL. I added export/import in a class in DLL through ifdef as usual but when compiling App I het unresolved references. I also set that App depends on the DLL.
Here are the main files:
Lib.pro
QT -= gui
TARGET = Lib
TEMPLATE = lib
DEFINES += LIB_LIBRARY
SOURCES += lib.cpp
HEADERS += lib.h\
Lib_global.h
symbian {
MMP_RULES += EXPORTUNFROZEN
TARGET.UID3 = 0xE10C4E25
TARGET.CAPABILITY =
TARGET.EPOCALLOWDLLDATA = 1
addFiles.sources = Lib.dll
addFiles.path = !:/sys/bin
DEPLOYMENT += addFiles
}
unix:!symbian {
maemo5 {
target.path = /opt/usr/lib
} else {
target.path = /usr/lib
}
INSTALLS += target
}
App.pro
QT += core gui
TARGET = App
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
lib.h
#ifndef LIB_H
#define LIB_H
#include "Lib_global.h"
#include <QString>
class LIBSHARED_EXPORT Lib {
public:
Lib();
~Lib();
QString Hello(QString a);
};
#endif // LIB_H
Lib_global.h
#ifndef LIB_GLOBAL_H
#define LIB_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(LIB_LIBRARY)
# define LIBSHARED_EXPORT Q_DECL_EXPORT
#else
# define LIBSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // LIB_GLOBAL_H
What's wrong with this code? Why is it unresolved reference?
In App I just include "../Lib/lib.h" and try to use the class.
What looks to be missing is the link between your application and your dynamic library.
I usually do something like this for my desktop (linux) apps:
INCLUDEPATH += ./include
LIBS += -L./lib -lLib
Where:
INCLUDEPATH defines the path to where your shared library .h files are located.
LIBS defines the path to where your built library is.
You can find the relevant documentation here: QMake - Declaring Other Libraries
Updated:
I was able to build the project (Linux Qt v4.7.4) and link to the library using the code you posted. I will try to clarify as my response may not be entirely clear.
The INCLUDEPATH and LIBS variables must be added to the App.pro file.
For the linker to properly find the library the paths must be adjusted to the paths you are using for your project:
LIBS += -L PATH -l LIBNAME
Supposing your folder structure is similar to the following:
Project
|_ Lib (your sharded library project files)
|_ App (your application project files)
You would adjust the variables like so:
INCLUDEPATH += ../Lib
LIBS += -L../Lib -lLib
Note that you link differently depending on your platform, you can do something like this to cover Windows and Linux:
unix {
INCLUDEPATH += ../Lib
LIBS += -L../Lib -lLib
}
win32 {
INCLUDEPATH += ../Lib
LIBS += ../Lib.lib
}

Resources