C++ PackageKit newb linking issue - c++

I'm trying to import PackageKit into a C++ project I'm working with (as a C++ newbie coming from a mostly Java background). My goal is do some things with the packages I have installed on my system.
I've installed libpackagekit-glib2-16, libpackagekit-glib2-dev, libpackagekit-qt2-6, libpackagekit-qt2-dev, and packagekit (I know I won't need all of these down the line, but I'm just covering my bases for now). I can see that they've been installed here: /usr/include/PackageKit which has the subfolders packagekit-glib2, packagekit-qt2, plugin.
To help me along I'm using qt 5.2.1 to act as a crutch for my Makefiles while I'm still learning, but I'm not actually using any qt resources for now. I've been able to import apt's and dpkg's libraries previously via -lapt-lib and -ldpkg under qt's LIBS+= but I can't figure out how to import the packagekit's library (I've tried multiple variations, but I can't figure out how to properly import this library).
This:
#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
#include <PackageKit/packagekit-glib2/packagekit.h>
int main(int argc, char *argv[])
{
return 0;
}
Results with this:
g++ -c -std=c++11 -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I../console-example -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I. -I. -o main.o ../console-example/main.cpp
In file included from ../console-example/main.cpp:3:0:
/usr/include/PackageKit/packagekit-glib2/packagekit.h:31:41: fatal error: packagekit-glib2/pk-catalog.h: No such file or directory
#include <packagekit-glib2/pk-catalog.h>
If this is necessary, my system is Ubuntu 14.04 64bit and as I've mentioned I'm using qt 5.2.1 to help with the makefile. Thanks to all in advance!

This seems to be a compilation problem. The compiler cannot find packagekit's headers. I suppose that into g++ line you need to add -I/usr/include/PackageKit or something similar.

From within my qt project's .pro file I had to make the following additions to get it to compile and link.
CONFIG += link_pkgconfig # This enables the next line
PKGCONFIG = gtk+-2.0 # This will link against gtk+-2.0
INCLUDEPATH += /usr/include/PackageKit/ \ # This is the include for packagekit
+= /usr/lib/glib-2.0/include/ # This will include glib, which packagekit is dependent on

Related

Qt creator not seeing Mac Frameworks

I am using Qt 5.6 with Qt Creator 4.3 on macOS Sierra 10.12.
I am building a Qt based application that uses OpenGL and OpenCL.
Software or system updates somewhere appear to have broken Qt Creators' ability to find the headers for OpenGL and OpenCL headers.
I have tried reinstalling Qt, Reinstalling Xcode and the Mac SDK and none of these options make it work.
The weird thing is my app compiles. QtCreator just cannot find the headers itself - this makes code navigation somewhat more complex.
So lets take OpenCL. I include it like this:
#ifdef __APPLE__
#include <OpenCL/cl.h>
#include <OpenCL/opencl.h>
#endif
My app.pro file for qmake has the following inside it:
macx:QMAKE_LFLAGS += -framework OpenCL
And with this it seems to compile. However the two OpenCL #include above in QtCreator are yellow underlined with a tooltip saying "OpenCL/cl.h: No such file or directory".
Now I can see that it compiles successfully as qmake is working out where the frameworks are and appending the paths successfully:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/me/Projects/app -I. -I/Users/me/Qt5.6.2/5.6/clang_64/lib/QtWidgets.framework/Headers -I/Users/me/Qt5.6.2/5.6/clang_64/lib/QtGui.framework/Headers -I/Users/me/Qt5.6.2/5.6/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I/Users/me/Qt5.6.2/5.6/clang_64/mkspecs/macx-clang -F/Users/me/Qt5.6.2/5.6/clang_64/lib -o main.o /Users/me/Projects/app/main.cpp
Now if I navigate to the following directory the headers are there and present:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A
So I cannot see what is missing.
I have tried to "teach" Qt Creator about this framework directory with combinations of the following, but I havent found something that will work:
macx:QMAKE_LFLAGS += -framework OpenCL
macx:INCLUDEPATH += /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/Headers
macx:QMAKE_LFLAGS += -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
macx:LIBS += -framework OpenCL
I'm struggling to find information about how QtCreator find the system frameworks on a mac and how i get it to start finding them again. Any help would be massively appreciated.
For anybody that has the same problem the answer was actually rather simple in the end.
When you setup the kit in Qt creator (which tells it what compiler and debugger to use amongst other things) you need to be careful with the compiler used. I had two copies of clang on my machine, one was installed in /usr/bin (the system one) and the other was installed inside the XCode app bundle. My kit was using the Xcode installed one as thats where the libraries live. While this compiled just fine, Qt creator for some reason does not hook up the paths to libraries properly. Simply switching this over to using the one in /usr/bin solved it.
Note that i did not explicitly ask it to use the one in the Xcode app bundle, thats just the one that was automatically selected when the project was first opened in Qt creator. So you might have to adjust its default behaviour in order to fix things.

Using Magick++ in Qt Creator

I am creating a Qt widget with a backend representation I wrote separately. The backend uses Magick++, and I can get it to compile from the command line:
g++ -c ../SpriteCreator/WriteGIF.cpp sprite.cpp -I ../SpriteCreator/ Magick++-config --cxxflags --cppflags Magick++-config --ldflags --libs -O2
but when I try to compile the project Qt Creator it tells me
/home/tpope/obeyYourThirst/qtSpriteEditor/backend/sprite.cpp:15: error: Magick++.h: No such file or directory
#include < Magick++.h>
I added the path for Magick++.h to the INCLUDEPATH, but now it has an error similar to this:
/home/tpope/obeyYourThirst/qtSpriteEditor/backend/sprite.cpp:66: error: undefined reference to `Magick::InitializeMagick(char const*)'
for every use of a Magick function. It seems to be not including the library. How do I do that in Qt Creator?
Since the .pro files in Qt Creator is (as far as I can tell) used to generate a Makefile, we can use make's ability to run a program on the shell and save its output.
I have added:
QMAKE_CXXFLAGS += $(shell Magick++-config --cppflags --cxxflags)
and
LIBS += $(shell Magick++-config --ldflags --libs)
to my .pro file, and I was able to add:
#include <Magick++.h>
to my program without a compile error, then compile a simple example (Just put out an animated .gif with a couple of colored pixels)
This obviously makes things like cross-compiling a little tricky (I don't know how to reference foreign libraries), but that's a problem for another time.

mac trying to compile with -nostdinc

I am trying to do a "clean" build of a c++ program on my mac. By clean, I mean, do not include anything that I do not explicitly specify.
My gcc installation is located at:
/Applications/gcc471/
So far, I can compile using
-nostdinc++
by including
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/x86_64-apple-darwin12.0.0
and doing
g++ -c *.cpp $(GPP-INCLUDES) -nostdinc++
I am pretty happy with that. However, I am trying to make the leap into compiling with
-nostdinc
And it seems that, no matter how many paths I include like
/usr/local/include
/usr/include
....
I get a crapton of errors like this:
/Applications/gcc471/include/c++/4.7.1/tr1/cmath: At global scope:
/Applications/gcc471/include/c++/4.7.1/tr1/cmath:156:11: error: ‘::double_t’ has not been declared
/Applications/gcc471/include/c++/4.7.1/tr1/cmath:157:11: error: ‘::float_t’ has not been declared
/Applications/gcc471/include/c++/4.7.1/tr1/cmath:160:11: error: ‘::acosh’ has not been declared
...
Does anyone know how to completely build a cpp program from scratch on the mac using -nostdinc?
I was able to compile using -nostdinc, but not without -I/usr/include/ as I had hoped. I do not trust Xcodes llvm/clang/gcc4.2 (Really old)/not real GCC nonsense. So I downloaded GCC from scratch and built it from source using the guide here: http://staticimport.blogspot.ca/2012/02/building-gcc-462-on-os-x-lion.html
The problem is that libstdc does not appear to ship with gcc anymore, only libstdc++. So all .hpp files are in my GCC directory, but really old headers, such as locale.h (From 1993), only appears to come with the libstdc XCode installs to /usr/include. I will keep looking for a vanilla libstdc to install, but for now, these are the most minimal and most "GNU" directories I can include to compile:
...
#FOR -nostdinc++
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/
GPP-INCLUDES += -I/Applications/gcc471/include/c++/4.7.1/x86_64-apple-darwin12.0.0
#for -nostdinc
GPP-INCLUDES += -I/Applications/gcc471/lib/gcc/x86_64-apple-darwin12.0.0/4.7.1/include/
GPP-INCLUDES += -I/usr/local/include
GPP-INCLUDES += -I/usr/include/ #bahhhhh cant get away
g++ -c *.cpp $(GPP-INCLUDES) -nostdinc++ -nostdinc -std=c++11

Errors in QT headers using clang

Questions:
My question is thus: How do I build my QT project without turning off warnings altogether (or having to sort through a million purposeless ones to find my own)? Can I suppress warnings for just the QT headers?
Details:
Issue
A number of months ago, I started a QT project in QT-Creator. At the time I was using gcc 4.6. After a bit other priorities asserted themselves and I found myself without time to work on the project until now. In the interim I switched to using clang. When I configured my QT project to use clang -- which project compiled without warnings in g++ -- it generated some 263 warnings all within the QT headers themselves. Mostly sign-conversion and unreachable-code.
Attempts
To try and get around this I added -isystem /path/to/QT/include/dir based on this entry in the Clang User Manual, but it did not seem to affect anything. Though I am not certain, I think it is because my code #include's the QT headers by name, not by directory. While the solution to that might be to manually list every single QT header used (have not tried), it would mean I would have to update it every time I upgraded QT or used a new header. Surely there is a better solution.
As requested here is the actual compile command being executed:
clang++ -c -pipe -Qunused-arguments -Weverything -cxx-isystem /path/to/qt/4.8.3/include/ -g -D_REENTRANT -DQT_NO_KEYWORDS -DQT_SHARED -I/path/to/qt/x86_64/4.8.3/mkspecs/unsupported/linux-clang -I. -I.moc -I.ui -I/path/to/qt/4.8.3/include/ -o .obj/main.o main.cpp
Specs
I am using:
Linux 3.2.0-40-generic #64-Ubuntu SMP x86_64 GNU/Linux
Though others on my team use Windows
QT creator 2.6.2
QT 4.8.3
clang version 3.2 (trunk 165250) (llvm/trunk 165249)
Target: x86_64-unknown-linux-gnu
I will answer my own question because, as it turns out, it is a specific environmental quirk in this case.
I have two copies of the QT libraries on my dev machine, one system-wide and one project specific (included in the VCS). The project libraries do not have qmake included, so I used my system qmake, which appended a different path than I was including in my -isystem specifications. To solve this, I added
QMAKE_INCDIR_QT =
to qmake.conf (in qt/mkspecs/unsupported/linux-clang/)
Since someone else on the project had fanangled qmake into using the project libraries everywhere else.
For those who stumble upon this question with a more general problem than the author.
Try inserting:
LIBS_USED_FOR_QT = QtCore QtSql QtMultimediaWidgets QtSensors QtSvg QtXml QtPrintSupport QtWidgets QtQuick QtQml QtPositioning QtGui QtWebKitWidgets
for(somelib, $$list($$LIBS_USED_FOR_QT)) {
QMAKE_CXXFLAGS += -isystem $$(QTDIR)/lib/$${somelib}.framework/Versions/5/Headers/
QMAKE_CXXFLAGS += -isystem $$(QTDIR)/lib/$${somelib}.framework/Headers/
}
in your .pro file.
Addtionally avoid includes like #include <QtCore/QtCore>
writing #include <QtCore> instead
This tamed qt quite efficiently for me.
see also this source

QT5 attaching project name with every sourcefile name, compiling error

i want to get started with QT. I donwloaded QT5 MINGW compiler with QT creator and i am trying to build the pre attached example named affine the problem is that the QT5 i think embed the project name with each of source file and thus gives error that file not found. some thing similar
:-1: error: ..affinemain.cpp: No such file or directory
while the file name is just
main.cpp
i don't know how to fix it. I searched lot on internet but could not found anything useful.
I even try to compile from command prompt but i am not fimmiliar with command prompt compiling as i am new to QT and previously i am totally developed with IDE in visual studio and eclipse for java so i have no idea about the make file and compiler command line arguments.
could some body please help me to fix this issue and can you tell please why compiler attaching project name with the source file name?
Thanks in advance
I have got the same problem and my solution may help you.
I am working with Qt5.0.1 now, and there are two distributions to work on windows with it: Qt5.0.1-mingw and Qt5.0.1-msvc2010.
I had to use mingw and there was a problem on my setup that "/" is ignored in path's.
So according to Qt Creator, compiler was called to process file mainwindow.cpp and this file was passed to it
g++ /*truncated*/ ..\qt-example\mainwindow.cpp
Below is the full compiler input:
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I..\qt-example -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtWidgets" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtGui" -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtCore" -I"debug" -I"." -I"." -I"..\..\..\..\..\..\Qt\Qt5.0.1\5.0.1\mingw47_32\mkspecs\win32-g++" -o debug\mainwindow.o ..\qt-example\mainwindow.cpp
And the error produced.
g++.exe: error: ..qt-examplemainwindow.cpp: No such file or directory
g++.exe: fatal error: no input files
compilation terminated.
So, we can see that "\" is ignored by the compiler and file name is merged with directory name.
The solution to that problem goes to the tools that are used - MinGW (Minimalist ports of GCC and Binutils). And also MSYS - a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. In our case - g++.
MSYS is not shipped with Qt5.0.1-mingw and g++ is not using it, but having MSYS available in your PATH environment variable breaks the system.
MSYS is used for git scm, which I have installed, so my path contains links to MSYS that goes bundled with git. So I have next paths in my PATH environment variable.
C:\Program Files (x86)\git\bin;C:\Program Files (x86)\git\cmd
I have not found how MSYS is used by Qt Creator or g++, or where it is linked, but when I have dropped next path from PATH:
C:\Program Files (x86)\git\bin;
and restarted Qt Creator - g++ succeeded on compiling my file, it worked.
The question why/how it influences the Qt Creator/g++ that should not use MSYS utils installed with git is still open.
i can´t comment.
important : delete all the files in the release and debug folder (compiled version) before try the tips of the autor ...