I'm trying to set up directory with shared files but I ended up with No rule to make target 'position.cpp', .... What am I doing wrong?
filesystem tree (simplified):
Project.pro client server shared
./client:
client.pro main.cpp main.h
./server:
main.cpp main.h server.pro
./shared:
position.cpp position.h shared.pri
Project.pro:
TEMPLATE = subdirs
SUBDIRS = client server
client.pro (server.pro looks similar):
LIBS += $$system(sdl2-config --libs) -lSDL2_ttf -lSDL2_image -lSDL2_net
QMAKE_CXXFLAGS += $$system(sdl2-config --cflags) -Wall -Wextra -Werror -pedantic -std=c++11
SOURCES += \
main.cpp
HEADERS += \
main.h
include(../shared/shared.pri)
shared.pri:
SOURCES += \
position.cpp
HEADERS += \
position.h
The given error could occur when make fails to find the referenced position.cpp file. The reason is that it tries to find the position.cpp in the directory where the .pro and not the .pri file is. To fix it you might try to use _PRO_FILE_PWD_ variable in your .pri file to properly set path to the position.cpp(h) files.
Related
I am using yocto build. I have .pro files and recipes(.bb) which build all cpp files present in .pro file. Recently I added two new cpp file i.e. gtest_main.cpp and lgeplugin_Test.cpp in .pro file. As show below
lgeplugin.pro
QMAKE_CXXFLAGS += -g
QMAKE_CFLAGS += -g
CFLAGS += \
-Wall \
-Wextra \
-fPIC \
-std=c++11
TARGET = lgeplugin
TEMPLATE = lib
message(Building)
INCLUDEPATH += ${Root}/include/ALL \
${Root}/include/gtest \
DEFINES += USE_LGE_TREE
SOURCES += ../../src/lgeplugin.cpp
contains(DEFINES, LGE_PLUGIN) {
SOURCES += \
../../src/internalclient.cpp \
../../src/Event.cpp \
../../src/gtest_main.cpp \
../../src/lgeplugin_Test.cpp
LIBS += -lLGEFramework -lgtest
}
lgeplugin.bb
QMAKE_PROFILES = "${S}/lgeplugin.pro"
do_install() {
install -d ${D}/usr/lib
cp -a ${B}/liblgeplugin.so* ${D}/usr/lib
}
Requirement : I need executable(a.out) of the newly added file i.e. gtest_main.cpp and lgeplugin_Test.cpp
I use gstreamer in my project, and if I compile program with make - IT WORKS well.
SOURCES= \
main.cpp
all: main.cpp
g++ $(INC) -std=gnu++11 $(SOURCES) -g -o myexe -lpthread -Wall -lgstapp-1.0 `pkg-config --cflags --libs gstreamer-1.0`
clean:
rm -rf *.o myexe
But I wrote the same in my .pro file in Qt creator and I get an error:
/usr/include/gstreamer-1.0/gst/gstelement.h:55: gst/gstconfig.h: No such file or directory
This is my full .pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
TEMPLATE = app
INCLUDEPATH += /usr/include/gstreamer-1.0/ \
/usr/include/glib-2.0/ \
/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \
/usr/include/libxml2/
LIBS += -std=gnu++11
LIBS += -lgstapp-1.0
LIBS += -lpthread
LIBS += `pkg-config --cflags --libs gstreamer-1.0`
SOURCES += main.cpp
Please tell, how to fix this ? I really want to use Qt creator.
Here is the correct .pro file with all needed paths:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
TEMPLATE = app
INCLUDEPATH += /usr/include/gstreamer-1.0/ \
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include \
/usr/include/glib-2.0/ \
/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \
/usr/include/libxml2/
LIBS += -std=gnu++11
LIBS += -lgstapp-1.0
LIBS += -lpthread
LIBS += `pkg-config --cflags --libs gstreamer-1.0`
SOURCES += main.cpp
I need to pass certain #define from library to main application. As far as I understand, it can be achieved with .prl files.
I've created simple subdirs project to test it:
This is main project file:
TEMPLATE = subdirs
SUBDIRS += \
app \
lib
app.depends = lib
This is library project file:
QT -= gui
TARGET = lib
TEMPLATE = lib
# Added create_prl option
CONFIG += staticlib create_prl
# This is the define I want to pass to main application
PRL_EXPORT_DEFINES += TEST_PRL_DEFINE
SOURCES += lib.cpp
HEADERS += lib.h
This is main application file:
QT += core
QT -= gui
CONFIG += c++11
TARGET = app
# Added link_prl option
CONFIG += console link_prl
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../lib/release/ -llib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../lib/debug/ -llib
else:unix: LIBS += -L$$OUT_PWD/../lib/ -llib
INCLUDEPATH += $$PWD/../lib
DEPENDPATH += $$PWD/../lib
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/liblib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/liblib.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/lib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/lib.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../lib/liblib.a
However, when I build the project (in Qt Creator, if that matters), no #define seems to be passed to main application except the standard ones:
cd lib\ && ( if not exist Makefile C:\Qt\5.4\mingw491_32\bin\qmake.exe C:\Qt\projects\test_prl\lib\lib.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile
mingw32-make[1]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[2]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
# Here you can see that TEST_PRL_DEFINE is added to defines of library project
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DTEST_PRL_DEFINE -DUNICODE -DQT_QML_DEBUG -DQT_CORE_LIB -I"..\..\test_prl\lib" -I"." -I"..\..\..\5.4\mingw491_32\include" -I"..\..\..\5.4\mingw491_32\include\QtCore" -I"debug" -I"..\..\..\5.4\mingw491_32\mkspecs\win32-g++" -o debug\lib.o ..\..\test_prl\lib\lib.cpp
ar -ru debug\liblib.a debug/lib.o
ar: creating debug\liblib.a
mingw32-make[2]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
mingw32-make[1]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
cd app\ && ( if not exist Makefile C:\Qt\5.4\mingw491_32\bin\qmake.exe C:\Qt\projects\test_prl\app\app.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile
mingw32-make[1]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[2]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
# Here no TEST_PRL_DEFINE is added to #defines of main application project
g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_CORE_LIB -I"..\..\test_prl\app" -I"." -I"..\..\test_prl\lib" -I"..\..\..\5.4\mingw491_32\include" -I"..\..\..\5.4\mingw491_32\include\QtCore" -I"debug" -I"..\..\..\5.4\mingw491_32\mkspecs\win32-g++" -o debug\main.o ..\..\test_prl\app\main.cpp
g++ -Wl,-subsystem,console -mthreads -o debug\app.exe debug/main.o -LC:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app/../lib/debug/ -llib -LC:/Qt/5.4/mingw491_32/lib -lQt5Cored
mingw32-make[2]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
mingw32-make[1]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
However, lib.prl file is created during build process and placed next to liblib.a.
How should I use create_prl/link_prl options?
better write clean makefiles on your own - the whole qmake stuff is far beyond any hope.
right now, I have to find why it silenty adds totally broken linker options like -L/usr/lib ... they're appearing in .prl files, but no idea where it comes from. smells like they never ever read the pkg-config manpage ...
In my project files I just want to be able to say:
main.cpp:
#include <foo.h>
#include <bar.h>
When these headers files reside in separate
-Project
-include
-foo
foo.h
-bar
bar.h
-src
main.cpp
I've setup my make file to attempt to achieve this but I still get fatal error: foo.h: No such file or directory so I haven't been able to set it up correctly.
Makefile:
LIBS = ./include/foo ./include/bar
all:
g++ -o bin/myapp src/main.cpp $(LIBS) -std=c++11
Is LIBS correct? How can I achieve relative/agnostic include paths?
INCLUDES = -I./include/foo -I./include/bar
all:
g++ -o bin/myapp src/main.cpp $(INCLUDES) -std=c++11
I am trying to learn Qt, I have file test.cpp that I run via the terminal using the following command:
g++ `pkg-config --cflags --libs libsbml` test.cpp -L /usr/local/lib -lsbml -lstdc++ -lm
How can I suppl the same options to Qt?
Thank you.
You could write the qmake snippet below. In short, you would need to take a look at the following qmake variables:
LIBS
INCLUDEPATH
TEMPLATE
TARGET
HEADERS
SOURCES
CONFIG
PKGCONFIG
test.pro
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
LIBS += -L /usr/local/lib -lsbml -lstdc++ -lm
unix {
CONFIG += link_pkgconfig
PKGCONFIG += libsbml
}
HEADERS += test.h
SOURCES += test.cpp
In .pro file add:
LIBS += -L /usr/local/lib -lsbml -lstdc++ -lm
look at the Makefile to figure out what variables are used. The makefile is in the build folder made by Qt.