qmake missing object file - qt

Alright... So I am very new to Qt. I just installed it on my Ubuntu distribution.
I created a new test application to see if it worked with the following file (helloworld.cpp) in my ../helloworld/ directory:
/* helloworld.cpp */
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(250, 150);
window.setWindowTitle("Simple example");
window.show();
return app.exec();
}
and I ran qmake -project in order to generate the helloworld.pro file.
Next I ran qmake in order to genereate the Makefile
Next I ran make in order to compile and got the following output/error:
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG
-DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I.
-I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4
-I. -I. -o helloworld.o helloworld.cpp
helloworld.cpp:1:24: fatal error: QApplication: No such file or directory
compilation terminated.
make: *** [helloworld.o] Error 1
meaning the helloworld.o file is missing... How do I fix this? I tried adding QT += webkit as another discussion said... and that didn't work either.
Any code monkeys out there have any ideas how to fix this??? I would greatly appreciate it!

In your .pro file, add the below line
QT += core widgets gui
Don't forget to invoke qmake again in command line so that qmake recreates Makefile. This should fix the issue for you.

QApplication should be inside /usr/include/qt4/QtGui, provided you have installed the libqt4-dev package.
If that package is not installed, that's the reason of the error: just install it:
sudo apt-get install libqt4-dev

cpp:1:24: fatal error: QApplication: No such file or directory
compilation terminated.
The actual error is a missing header file (QApplication). That caused your code (helloworld.cpp) not to compile generating a secondary error
make: *** [helloworld.o] Error 1
Thus, the solution is to make sure QApplication can be found. That usually is handled by the Qt += statement in your .pro file.
Qt += webkit tells QMake that you are wanting to make a webkit (web browser) application. That should not be needed in this case.
What you are trying to build is a GUI application, so you need to make sure your .pro file specifies that. That can be done by specifying Qt += gui.
More over, I would suggest that you have Qt += gui core at the top of your file. This tells QMake that you are using both the core and gui components of Qt.

Related

Compiling avr c++ lib with Eclipse Photon CDT Core Builder

I'm trying to compile an Arduino lib I'm writing under Eclipse. This is the basic sketch sx.cpp I'm using, it compiles using standard Arduino IDE 1.8.0:
#include <Arduino.h>
#include <vector>
void setup() {
}
void loop() {
std::vector<byte> a(0x22);
}
This is the compiler out:
Building sx
"C:/Users/Ale/Documents/Arduino/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I"C:/Users/Ale/Documents/Arduino/packages/arduino/hardware/avr/1.6.21/cores/arduino" -I"C:/Users/Ale/Documents/Arduino/packages/arduino/hardware/avr/1.6.21/variants/standard" "../../sx.cpp" -o "project/sx.cpp.o"
../../sx.cpp:3:18: fatal error: vector: No such file or directory
#include <vector>
^
compilation terminated.
make: *** [project/sx.cpp.o] Error 1
makefile:67: recipe for target 'project/sx.cpp.o' failed
I'm using Eclipse 4.8.0 and Arduino project nature (CDT core compiler), but I'm not interested in uploading to real boards and/or debugging. Without vector a and relevant #include of course it compiles.
(EDIT) The longer story:
I have been writing this lib for like 5 days with text editors. I come from Java development, so please be patient. My lib uses some c++ standard classes, std::vector among a couple other. Everything was OK using Arduino IDE, but after 5 days it's way unpractical for me, so I decided to re-try Arduino with Eclipse after 5 years (my first eclipse-cdt experience was awful and complex). With newest Photon release, I noticed the 'Arduino' template project and the Arduino lib manager included "out-of-the-box", so I decided to give it a try.
I'm actually using an ESP32 board but again, I'm not interested in uploading/executing the code. I just need to be able to refactor it handly

Qt requires C++11 support

I used Qt 5.7 and gcc 4.9.2. Qt Core module throw Qt requires C++11 support error.
This page say that
gcc 4.9.2 fails to compile Qt.
So I installed gcc 4.8. I check using below command on terminal :
$ g++ --version
g++ (Ubuntu 4.8.4-1ubuntu15) 4.8.4
My kit uses cmake not qmake. I add TARGET_LINK_LIBRARIES ( xxxx yyyy /usr/bin/c++ -std=c++11 to CMakeLists-txt.
I restart my pc and run my application again. Same error is throwed.
/opt/Qt/5.7/gcc_64/include/QtCore/qbasicatomic.h:61: error: #error "Qt requires C++11 support"
# error "Qt requires C++11 support"
^
How can I solve it?
If using QtCreator, you can add this to your .pro file:
CONFIG += c++11
https://wiki.qt.io/How_to_use_C%2B%2B11_in_your_Qt_Projects
Its has been a while.
How I finally solve it is indicating in CMakeLists.txt the following line just after project(MyProject):
add_compile_options(-std=c++11)
That says to cmake, to create a Makefile that will use c++11 solving issues.
solution for me was (in your .pro file):
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
QMAKE_LFLAGS += -mmacosx-version-min=10.7
Turn c++11 on explicitly:
set(CMAKE_CXX_FLAGS "-std=c++11" CACHE STRING "compile flags" FORCE) after project(...) declaration.
add_library(MyLib SHARED ${PROJECT_HEADERS} ${PROJECT_SOURCES})
...
set_property(TARGET MyLib PROPERTY CXX_STANDARD 11)
set_property(TARGET MyLib PROPERTY CXX_STANDARD_REQUIRED ON)
SOMETIMES, this will not be a configuration issue as mentioned in other answers. In my case, the problem was one file that happened to have been saved with a .CPP extension rather than .cpp. QMake (Qt5) was misidentifying the file and trying to compile it with the C compiler rather than the C++ compiler. The QMake from Qt4 was not exhibiting this issue. Renaming the file fixed the issue.
My comment at the time was "Could this really be that f&%%& simple!!"

Qt5 programs won't compile

I'm trying to get Qt5 working on Ubuntu 12.04. I downloaded the 32-bit installer from http://qt-project.org/downloads and basically just let it install everything in my home folder.
I had to add ~/Qt/5.1.0/gcc/bin to my path for qmake to work, but now when I try to make a hello qt example (using qt4 book), when running make, it cannot find the QApplication or QLabel header. When I replace them with QtWidgets/QApplication, it finds the header, but I get all undefined references when linking.
This is the command make executes:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../../../../Qt/5.1.0/gcc/mkspecs/linux-g++ -I. -I. -I../../../../Qt/5.1.0/gcc/include -I../../../../Qt/5.1.0/gcc/include/QtGui -I../../../../Qt/5.1.0/gcc/include/QtCore -I. -o hello.o hello.C
I managed to figure out that it's qmake -project that is doing something wrong. When I make an app in Qt Creator (which actually works), the .pro file has lines like QT += widgets, that are not there when I run it on the command line.
I found the answer using qmake --help. This actually says:
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
Adding these lines to the .pro file solved the problem:
QT += core gui
QT += widgets
As an alternative to manually editing the .pro file after running qmake -project, you can specify assignments on the command line that will be included in the generated files:
qmake -project "QT = core gui widgets"
See http://qt-project.org/doc/qt-5.1/qtdoc/qmake-running.html

Integrating CUDA with Qt on Ubuntu 12.04

I am trying to integrate Qt with CUDA. I am working on Ubuntu 12.04. I already have CUDA and Qt installed.
I followed the steps here -
'linker input file unused because linking not done' when trying to setup QT creator & Cuda
However it still gives me an error.
Here is how I did it.
I created an empty Qt project called 'CUDA2' in my home directory.
I added the following files
cuda_interface.cu
// CUDA-C includes
#include <cuda.h>
extern "C"
void runCudaPart();
// Main cuda function
void runCudaPart() {
// all your cuda code here *smile*
}
main.cpp
#include <QtCore/QCoreApplication>
extern "C"
void runCudaPart();
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
runCudaPart();
return a.exec();
}
I added the following lines to the .pro file
QT += core
QT -= gui
TARGET = cuda2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
# Source files for C/C++ compiler
SOURCES += main.cpp
# project build directories
DESTDIR = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
# and C/C++ flags
QMAKE_CFLAGS_RELEASE =-O3
QMAKE_CXXFLAGS_RELEASE =-O3
# cuda source
CUDA_SOURCES += cuda_interface.cu
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib
# GPU architecture
CUDA_ARCH = sm_20
# NVCC flags
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# Path to libraries
LIBS += -lcudart -lcuda
# join the includes in a line
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
cuda.dependcy_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -O3 -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}
cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o
# Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda
I ran qmake to generate the makefile. When I click on 'build', I get this error -
13:33:35: Running build steps for project CUDA2...
13:33:35: Configuration unchanged, skipping qmake step.
13:33:35: Starting: "/usr/bin/make" -w
make: Entering directory `/home/alex/CUDA2'
Makefile:541: warning: overriding commands for target `Obj/main.o'
Makefile:538: warning: ignoring old commands for target `Obj/main.o'
/usr/local/cuda/bin/nvcc -m64 -O3 -arch=sm_20 -c --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v -I/usr/local/cuda/include -lcudart -lcuda cuda_interface.cu -o Obj/cuda_interface_cuda.o
ptxas info : Compiling entry function '__cuda_dummy_entry__' for 'sm_20'
ptxas info : Used 2 registers, 32 bytes cmem[0]
g++ -c -pipe -O3 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB - DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore - I/usr/include/qt4 -I/usr/local/cuda/include -I. -o Obj/main.o main.cpp
gcc -c -pipe -O3 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB - DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore - I/usr/include/qt4 -I/usr/local/cuda/include -I. -o Obj/cuda_interface.o cuda_interface.cu
gcc: warning: cuda_interface.cu: linker input file unused because linking not done
g++ -Wl,-O1 -o cuda2 Obj/cuda_interface_cuda.o Obj/main.o Obj/main.o Obj/cuda_interface.o -L/usr/local/cuda/lib -L/usr/lib/x86_64-linux-gnu -lcudart -lcuda - lQtCore -lpthread
g++: error: Obj/cuda_interface.o: No such file or directory
make: *** [cuda2] Error 1
make: Leaving directory `/home/alex/CUDA2'
13:33:36: The process "/usr/bin/make" exited with code 2.
Error while building project CUDA2 (target: Desktop)
When executing build step 'Make'
I am not sure if the .pro file will work with Linux. Looks like it was made for OSX.
Also, I don't know if the line CUDA_ARCH = sm_20 is correct. Is there a way I can find my gpu architecture? I am using an NVIDIA Quadro FX 380M
What am I doing wrong?
Thanks!
Based on the comments, you had some 'common mistakes' on your .pro file.
First, the CUDA toolkit has separated libraries directories for 32 and 64 bits. So, you need adjust the QMAKE_LIBDIR as follows:
QMAKE_LIBDIR += $$CUDA_DIR/lib64 # for 64bits operating system
or
QMAKE_LIBDIR += $$CUDA_DIR/lib # for 32bits operating system
Do not include the .cu files as SOURCES in the .pro file as they are not compiled with g++. The .pro file of your question does not show this case, but you commented that the .cu file were in the project in Qt remove them.
Finally, to be sure all your changes take effect do the following in the QT Creator IDE menu:
Build -> Clean Project # to clean old stuff
Build -> Run qmake # to take the .pro changes
Build -> Build Project # obvious
PS: As #aland commented, your GPU device compute capability is 1.2, so adjust CUDA_ARCH = sm_12.
This is the problem:
g++: error: Obj/cuda_interface.o: No such file or directory
I would delete all of your CUDA source and libraries, make sure everything is completely clean, and reinstall from scratch.
Here is a good guide:
http://laurencedawson.com/ubuntu-11.10-and-cuda-4.1
<= Assuming you already have Ubuntu and your NVidia drivers installed, then just reinstall and rebuild the CUDA toolkit and source.
Forget Qt and forget your graphical IDE until you get things working.
Please reinstall and rebuild CUDA from the command line.
Make sure you can run "deviceQuery" from the command line before you go back to Qt and the IDE.
Another good resource:
http://developer.download.nvidia.com/compute/DevZone/docs/html/C/doc/CUDA_C_Getting_Started_Linux.pdf

Help getting started with Qt

I am a newby in QT and cannot even get a starting example to work. The problem is that even QtCore is not found. Think something wrong with my path or not the right version is used?
#include <QtCore>
#include <iostream>
#include <QtXml/QXmlSimpleReader>
int main(int argc, char *argv[])
{
QDir xmldir("/xxx/xxx");
QXmlSimpleReader xmlReader;
}
Example of error is:
/Users/frank/xxx-build-desktop/../xxx/main.cpp:1: error: QtCore: No such file or directory.
Checked the path and the path to qmake is /usr/bin/qmake
If I run qmake -v this is printed:
QMake version 2.01a
Using Qt version 4.7.0 in /Library/Frameworks
I am using Mac 10.6.6
Any reply will be appreciated.
Here is the project file:
QT += core gui
QT += xml
QT += webkit
QT += xmlpatterns
TARGET = xxx
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Results from make:
iMac:~/xxx/ qmake -spec macx-g++
iMac:~/xxx/ ls -ltr
total 56
-rw-rw---- 1 frank staff 349 Feb 5 16:06 xxx.pro
-rw-rw---- 1 frank staff 3875 Feb 6 12:56 main.cpp
-rw-rw---- 1 frank staff 7985 Feb 6 12:56 xxx.pro.user
-rw-rw---- 1 frank staff 8974 Feb 6 12:56 Makefile
iMac:~/xxx/ make
g++ -c -pipe -g -gdwarf-2 -Wall -W -DQT_WEBKIT_LIB -DQT_XMLPATTERNS_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.7/mkspecs/macx-g++ -I. -I. -I/usr/include/QtCore -I. -I/usr/include/QtGui -I. -I/usr/include/QtXml -I. -I/usr/include/QtXmlPatterns -I. -I/usr/include/QtWebKit -I/usr/include -I. -F/Library/Frameworks -o main.o main.cpp
main.cpp:1:18: error: QtCore: No such file or directory
main.cpp: In function ‘int main(int, char**)’:
main.cpp:27: error: ‘QDir’ was not declared in this scope
main.cpp:27: error: expected `;' before ‘xmldir’
main.cpp:28: error: ‘xmldir’ was not declared in this scope
main.cpp:28: error: ‘QDir’ is not a class or namespace
main.cpp:28: error: ‘QDir’ is not a class or namespace
main.cpp:28: error: ‘QDir’ is not a class or namespace
main.cpp: At global scope:
main.cpp:25: warning: unused parameter ‘argc’
main.cpp:25: warning: unused parameter ‘argv’
main.cpp:63: warning: unused parameter ‘namespaceURI’
main.cpp:63: warning: unused parameter ‘localName’
main.cpp:63: warning: unused parameter ‘qName’
main.cpp:67: warning: unused parameter ‘namespaceURI’
main.cpp:67: warning: unused parameter ‘localName’
make: *** [main.o] Error 1
iMac:~/xxx/
For most C++ Qt applications you write, it's not immediately obvious how to compile the application by hand. This is complicated by a number of factors:
The header files may be placed in different directories depending on their version
moc, the meta-object compiler, needs to be run
The correct version of the DLLs need to be included
A number of preprocessor defines need to be in place
Given all of the above, it's easiest to use a build system like qmake, which is native to Qt, cmake, or some other build system that is Qt aware.
For people new to Qt, I recommend qmake.
Here's the basic command line usage. Qmake provides integration with both Visual Studio and XCode, but I won't address that here:
Create a directory for your project
Write whatever files you believe you need
Build a project file for qmake by running qmake on your project as follows: qmake -project "CONFIG+=xml". Since you're on mac, you might also want a -macx option, but I've never used it myself. At least in the past, qmake was not smart enough to pick up the XML dependency, so the "CONFIG+=xml" option adds it explicitly.
Create the makefiles from the project file by running qmake again: qmake
Now that you have makefiles, build the application using make, nmake, gmake, or the corresponding version of make for your system.
If everything has been picked up correctly by qmake, you should now be able to build your application by using make.
When you add new files to your project, they will need to be added to your project file (*.pro) and then qmake rerun without any options.
#includes are for header files. QtCore isn't a header, it's a directory that contains headers.
Since you're using QDir, change the first line to this:
#include <QtCore/QDir>
It is rather strange that your /usr/include/* directores don't exist. It seems that there is something wrong with the Qt installation. I don't understand Mac specifics, but from what I've been able to find out, it looks like the -F/Library/Frameworks parameter that make passes to G++ should allow you to use #include <QtCore/QtCore> instead of just #include <QtCore>. In a correct Qt installation on other platforms (Windows, Linux), both forms are equally acceptable though. But judging by the fact that G++ doesn't complain about the #include <QtXml/QXmlSimpleReader> line, the form #include <QtModule/ModuleHeader> works fine in your setup, so it could be used as a workaround, provided that there are no other problems.
Note that I wouldn't recommend to include QtCore in any form, though. It includes a lot of stuff most of which is probably useless to you and it will only increase compilation time and the probability of name conflicts. Include only what you intend to use instead, like #include <QDir> or #include <QtCore/QDir> in your case.
If you are new to Qt, and there's not special build requirement (PPC, 10.4, etc), I would strongly recommend that you download prepackaged Qt SDK of your platform. And use the included IDE, Qt Creator, to start. That will get your feet wet quickly and less painfully.
The variable settings you provided, which seems to be in your makefile, should actually be in a QMake file xxx.pro. You then run qmake, which generates the Makefile from xxx.pro, and then finally can run make. QMake uses variables such as QT and SOURCES, along with its knowledge of Qt and your installation, to produce a correct makefile.
If you do not find QtCore in /usr/include/, then this is an installation issue. In 4.7.0 I heard people having the same problem, so I guess there is a packaging problem for macs in 4.7.0.
Try to get 4.7.1 or build your own out of the sources.

Resources