I am trying to run a hello world program and the tutorials don't work for me.
I am guessing that it's got something to do with qt4 <-> qt5 and linux <-> windows confusion.
I'm on Ubuntu 14.04, 64 bit. I did a sudo apt-get install build-essential and a sudo apt-get install qt5-default.
This is the code in my main.cpp:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Linux is wonderful", 0);
app.setMainWidget(label);
label->show();
return app.exec();
}
I run these commands:
qmake -project
qmake test.pro (for some reason it's not "main.pro")
make
Here is the generated .pro file:
######################################################################
# Automatically generated by qmake (3.0) So. Okt. 25 15:51:35 2015
######################################################################
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
# Input
SOURCES += mymain.cpp
And then I get QApplication: No such file or directory. Why?
You are missing the necessary module from .pro file. Apparently qmake -project does not add that by default (makes sense, since not all Qt apps are widget applications). So check for and add this:
QT += widgets
This is because Qt5 has widgets in a separate module (Qt4 had them in gui), and QApplication is part of that, as shown by docs too. The two modules which qmake adds automatically (and you have to remove if you don't want them) are core and gui (documented here), others you have to add to .pro explicitly.
Some notes: You generally run qmake -project only once to create initial .pro file. Then you need to edit it by hand, and don't want it to be overwritten! Then you never edit Makefiles by hand, instead you regenerate them by running qmake after editing the .pro file.
Related
I'm trying to cross-compile from WSL and Linux to Win32 using i686-w64-mingw32-gcc. The program is dependent on some DLL:s that I have downloaded, and are known to work when used for an exe cross-compiled on Cygwin. Compilation and linking works without throwing any errors or warnings, but when I run the resulting executable on Windows (by double-clicking on it in an Explorer window) I get a Windows-error-prompt:
The procedure entry point DeleteCriticalSection could not be located in the DLL...
and then it points to the program (the .exe) itself, not a DLL (message translated from Swedish ;-).
When I do the exact same thing on Cygwin with the same archive for the DLL:s and the same DLL:s the resulting exe works as it should.
The new(ish) Dependencies shows some red lines for COMCTL32 and OLEAUT32, but those are the same for both.
A very simple windows GUI app compiles and runs, so it's not the cross-compile as such that is causing the issue. The DLL:s in combination with WSL/Ubuntu/GNU cross-compilation seems to be the culprit.
Instructions
EDIT: after explicitly following my own instructions and explicitly re-installing the cross-compilation tool-chain the instructions below no longer creates a faulty exe. But the original problem remains.
I'm happy to take any ideas on what to try next.
Here are instructions to repeat what I have. Create an empty directory in WSL and run
$ sudo apt install binutils-mingw-w64-i686 gcc-mingw-w64-i686
$ wget https://github.com/DavidKinder/Windows-Glk/releases/download/1.50/WindowsGlk-150.zip
$ unzip WindowsGlk-150.zip
Then create startup.c with the following content
#include <unistd.h>
#include "glk.h"
#include "WinGlk.h"
int winglk_startup_code(const char* cmdline)
{
return 1;
}
void glk_main(void) {
sleep(10);
}
(Fix the capitalized include of "glk.h" in Glk.c or you'll get an error.)
Compile and link with
$ i686-w64-mingw32-gcc -mwindows -I Include/ Glk.c startup.c Glk.lib
to get an a.exe. The message only shows up in Gui-mode so you need to run it from an explorer window:
explorer.exe .
and double-click on a.exe.
WSL and Linux vs. Cygwin
I've done the same cross-compilation on a "real" Ubuntu 20.04 and getting the same problem. Again, doing the exact same steps in Cygwin produces a runable exe. This points to a cross-compilation problem with some facet of
what the exe and the DLL:s are doing. (There is no code in the exe that does anything with critical sections. Could this be an API mismatch?)
Since the DLL:s are the same it is reasonable to suspect the actual cross-compilation of sources in my program.
Is there anything in the cross-compilation toolchain on Linux that might differ? Which Windows run-times and API-versions are targeted?
I'm happy to take any ideas on what to try next.
I'm currently trying to use the "QSerialPort" library on a Virtual Machine with Debian on it and can't seem to make it work. It looks like the Library straight up doesn't exist on my machine. It doesn't auto-complete when I write it out and when I try compiling I get this.
/home/debian/Downloads/mainmenu.h:15: error: QSerialPort: No such file or directory
#include <QSerialPort>
^
So I'm pretty sure I just don't have the library. Even though my version of Qt is said to have it.
-Qt Creator 4.2.0
-Based on Qt 5.7.1 (GCC 6.3.0 20170415, 64 bit)
I even have an older version of Qt creator on my Windows OS and it has the library.
I was told to get the library myself by doing this:
git clone git://code.qt.io/qt/qtserialport.git
mkdir qtserialport-build
cd qtserialport-build
qmake ../qtserialport/qtserialport.pro
sudo make install
but I can't even get through the first line before getting this:
git clone git://code.qt.io/qt/qtserialport.git
Cloning into 'qtserialport'...
fatal: unable to connect to code.qt.io:
Also tried to install the Package: libqt5serialport5 (5.2.1-1)
and it pretty much changed nothing.
You need to download and install. Just follow my instructions given below, it will help you to fix the problem.
You are very close man (Also tried to install the Package: libqt5serialport5 (5.2.1-1))
1) You have to install (via Terminal):
sudo apt-get install libqt5serialport5
sudo apt-get install libqt5serialport5-dev
2) add in the .pro file
QT += core serialport
3) int the .h file add:
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
4) Example Device Info
serial -> setPortName("/dev/ttyACM3"); // just example for my device
serial -> setBaudRate(QSerialPort::Baud115200);
serial -> setDataBits(QSerialPort::Data8);
serial -> setParity(QSerialPort::NoParity);
serial -> setStopBits(QSerialPort::OneStop);
serial -> setFlowControl(QSerialPort::NoFlowControl);
serial -> open(QIODevice::ReadWrite);
It is probably the best option.
Alright! I figured it out.
First problem, was accessing a git library through a Firewall/Virtual Machine.
So instead of using the git link:
git://code.qt.io/qt-creator/qt-creator.git
I used the http link, which worked:
http://code.qt.io/qt-creator/qt-creator.git
Still had some issues until I followed these steps(I didn't download the dev version of the package, I guess):
1)
sudo apt-get install libqt5serialport5
sudo apt-get install libqt5serialport5-dev
2) add in the .pro file
QT += serialport
3) int the .h file add:
#include <QtSerialPort/QSerialPort>
I'm writing an OpenCV program for university and got some troubles with Eclipse.
I am running a 64bit Linux Mint (13) with Eclipse Juno. I installed OpenCV using this guide, except I installed Version 2.4.3.
Since the project my partner on MacOS shared with me didn't work, I created a plain C++ Project. I added the information needed in the build settings as followed:
Cross GCC Compiler -> -I -> "/usr/local/include/opencv" and "/usr/local/include/opencv2"
Cross G++ Linker -> Libraries -> -I -> "cv" and "highui"
-> -L -> "/usr/local/lib"
This is the code I'm using. Right, it does nothing:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char** argv) {
return 0;
}
So, everytime I'm running this, i get an ugly grey window, like a message window would look like, but nothing in it. This is the same es the actual program with code in it, so it's nothing to do with OpenCV commands.
Sometimes, this window disappears with killing Eclipse, with doens't response then. Sometimes, it even survives that and I have to start a new X session.
This is what it looks like:
The error messages you can see are not related to the crash itself, but shown before.
Sometimes it just says "Binary not found", which those messages come from. It somehow doesnt find the libraries.
This is pkg-config --libs opencv
/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so
/usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so
/usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so
/usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so
/usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so
/usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so
/usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so
/usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so
/usr/local/lib/libopencv_videostab.so
This is pkg-config --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include
It hast to do something with my OpenCV/CWT setup I guess. Since I tried out a lot of variations, does anybody got any idea what I did wrong?
Question is similar to this question
Handling header files dependencies with cmake
I have sample program dir having main.c main.h and CMakeLists.txt
main.h contents are
#ifndef MAIN_H
#define MAIN_H
int t=3;
int y=2;
#endif
main.c contents are
#include <main.h>
#include<stdio.h>
int main(){
printf("%d apple",t);
}
and CMakeLists.txt
PROJECT( test )
AUX_SOURCE_DIRECTORY(. test_SRCS)
include_directories(.)
ADD_EXECUTABLE (main ${test_SRCS})
but cmake is not rebuilding main.c on modification of header file.
I want it to auto-generate header file dependency.
Is it possible using cmake ?
if not is there any other tool which can do that ?
As mentioned in my comment, I have tried out your example and things were working fine: if main.h was modified then main.c would be recompiled.
My installation of CMake (version 2.8.0) told me to add
cmake_minimum_required(VERSION 2.8)
to the CMakeLists.txt file, but that is all of the adjustments I needed.
Answering this for others that google search...
I ran into this problem with one of my projects. As it turns out I added the header to the cpp file after running cmake. Re-running cmake fixed the problem. If you run into this, try that and see if it fixes the issue.
From the cmake 2.8.0 documentation of AUX_SOURCE_DIRECTORY:
It is tempting to use this command to avoid writing the list of source
files for a library or executable target. While this seems to work,
there is no way for CMake to generate a build system that knows when a
new source file has been added. Normally the generated build system
knows when it needs to rerun CMake because the CMakeLists.txt file is
modified to add a new source. When the source is just added to the
directory without modifying this file, one would have to manually
rerun CMake to generate a build system incorporating the new file.
Why do you want to avoid creating a list of files? Such lists generally do not change frequently.
I'm not a linux expert, and I'm trying to install a 2D graphics library on Ubuntu 10.10. I need to make a 2D display and after a little online research, GooCanvas seems like it will fit the bill.
I'm frustrated because it simply won't install and I don't get what I am supposed to do.
Here's what I did.
1> git clone git://git.gnome.org/goocanvas #built a goocanvas directory
2> cd goocanvas
3> ls
AUTHORS ChangeLog demo goocanvas.doap NEWS src
autogen.sh configure.in docs MAINTAINERS po TODO
autom4te.cache COPYING goocanvas-2.0.pc.in Makefile.am README
4> less README #here's what it says
To build it run './configure' and 'make'. To run the demo cd into 'demo' and
run './demo'. (Or run ./simple-demo for the very simple demo, or ./mv-demo
for the model-view demo.)
5> ./configure # error: bash: ./configure: No such file or directory
6> find . -name "configure*" -print #there aren't any other configure scripts?
'make; and 'make install' don't work either.
OK, I'm frustrated. Why does it say run configure if there isn't one? How do I install this thing?
Does anyone know an easy to use graphics library for ubuntu that will actually work. and can be easily installed?
Cairo, which is usually assumed when talking about GTK, is a good 2D library. Installing should be easy as this will be in your distributions repository (from the command line as root run apt-get install libcairo2-dev).
Now that I think about it - your new enough to Linux not to look at your repository for software first - learn to do that! I checked and found Ubuntu universe already has goocanvas, just apt-get install libgoocanvas-dev and you should be good to go.
Does anyone know an easy to use graphics library for ubuntu that will actually work.
and can be easily installed?
What is wrong with the big ones:
Qt
gtk
EFL (The Enlightenment libs)
Their instructions are out of date, execute the autogen.sh file first. You'll need the gtk-doc-tools and some other packages to support compiling things.
Edit 1:
Looks like it needs GTK 3.0, glib 2.28+, and Cairo 1.1+ - those are pretty modern. I'm not sure what Ubuntu 10.10 has them (I'm on 10.04), launch Synaptic Package Manager and search for libgtk the header files are in dev packages.
Edit 2:
What sort of graphics package are you looking for? SDL may work, or Cairo.
Using SDL
If you want to use graphics.h on Ubuntu platform you need to compile and install libgraph. It is the implementation of turbo c graphics API on Linux using SDL.
It is not very powerful and suitable for production quality application, but it is simple and easy-to-use for learning purpose.
You can download it from http://download.savannah.gnu.org/releases/libgraph/libgraph-1.0.2.tar.gz.
First install build-essential by typing
sudo apt-get install build-essential
Intall some additional packages by typing
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 \
guile-1.8-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev \
libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev \
libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev \
libslang2-dev libasound2 libasound2-dev
Now extract the downloaded libgraph-1.0.2.tar.gz file.
Goto extracted folder and run following command
./configure
make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
Now you can use #include on ubuntu platform
Compile it using gcc demo.c -o demo -lglut -lGL
/* demo.c*/
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glu.h>
void setup() { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); }
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0f, 0.0f, 0.0f);
glRectf(-0.75f,0.75f, 0.75f, -0.75f);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(800,600);
glutCreateWindow("Hello World");
setup();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Run it using ./demo
Check this out: We have developed a 2d Graphics library and Windowing System(GWS): https://github.com/MnMInfoTech/GWS