QTCreator g++.exe: fatal error: no input files (Windows) - c++

An error occurs during the build:
code *.pro:
QT += core gui
QT = widgets
TARGET = MYPROJECT
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
code mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
As a compliant is installed: C:\Strawberry\c\bin\g++.exe
The assembly is made in Windows 10 64 bit.
In time the assembly i get so error:
g++.exe: fatal error: no input files
compilation terminated.
09:38:38: The process "C:\Strawberry\c\bin\g++.exe" ended with code 1.
Error in assembling / installing the MYPROJECT project (set: MYPROJECT_DESCTOP)
During the "Build" stage
I tried include full path to files in .pro file, but it isn't helped.

Make sure you have all your code files in the current working directory, otherwise you'll have to include their path in the compile command.

Related

The program has unexpectedly finished in QT opencv

I know that this has been posted many times,but I could not find the solution from previous posts. I followed tutorial on How to setup Qt and openCV on Windows from wiki Qt.
My .pro file and mainwindows.cpp are shown below. I wanted to open image following the example. What is wrong here? Checked the opencv version and it is the same as libs included. The PATH is also correct.
The cpp file
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat image = cv::imread("C://1.jpg", 1);
cv::namedWindow("My Image");
cv::imshow("My Image", image);
}
MainWindow::~MainWindow()
{
delete ui;
}
and
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvtest
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv-build\bin\libopencv_core451.dll
LIBS += C:\opencv-build\bin\libopencv_highgui451.dll
LIBS += C:\opencv-build\bin\libopencv_imgcodecs451.dll
LIBS += C:\opencv-build\bin\libopencv_imgproc451.dll
LIBS += C:\opencv-build\bin\libopencv_features2d451.dll
LIBS += C:\opencv-build\bin\libopencv_calib3d451.dll
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
When program crashes like that under Qt Creator, and you have extra libraries, the very likely reason is that the extra libraries are missing from the runtime PATH.
In this case, you need to add C:\opencv-build\bin to the PATH. There are at least 3 ways to go about it.
Edit the system environment, so that the relevant directory is always in the system PATH. You need to restart Qt Creator for this change to take effect. This is not the recommended way, unless you actually want these things in there also for other purposes.
You can edit the Build environment of the project under Qt Creator Project view. There's separate configuration for each build type, so you may need to do this to them all separately, which both good and bad. It is good, because then you can have different directory for different builds (for example debug vs relase, MSVC vs MinGW builds). It's bad because it's extra hassle and makes it easier to have something wrong.
You can add it to the run environment in the Qt Creator Project view. Then it will be the same for all build types.
In this case, 3 is probably the way to go.
Qt Creator annoyingly does not display any information about which DLL is missing, it just says the program crashed. This can be solved by instead string the "Qt command prompt" for the correct toolchain from Windows Start menu (search Qt and you should find it). Then go to the built .exe directory and run the .exe. You should now get an error dialog where Windows tells you which DLL it failed to find. Then you can look where that DLL is and add it to the path and try again, until the program starts. After you know the directories using this method, you can then add them to Qt Creator as explained above.

Changing location of header file causes missing vtable error when compiling with CMake

I need to transition from qmake to CMake for a large C++ project, but while working through a toy example I encountered some behavior that I don't understand. The example code features a single header file, and when that header file is moved into a subdirectory, I get a missing vtable error for the MainWindow class.
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(HelloCMake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets CONFIG REQUIRED)
include_directories("include")
set(INCLUDES include/mainwindow.h)
set(SOURCES
main.cpp
mainwindow.cpp
mainwindow.ui
)
add_executable(hello-cmake ${SOURCES}) # error
# add_executable(hello-cmake ${SOURCES} ${INCLUDES}) # no error
target_link_libraries(hello-cmake Qt5::Widgets)
include/mainwindow.h (boilerplate)
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp (boilerplate)
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow() {
delete ui;
}
main.cpp (boilerplate)
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Here's what I see when I run make (after first running cmake .):
[ 20%] Automatic MOC and UIC for target hello-cmake
[ 20%] Built target hello-cmake_autogen
[ 40%] Linking CXX executable hello-cmake
Undefined symbols for architecture x86_64:
"vtable for MainWindow", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.cpp.o
MainWindow::~MainWindow() in mainwindow.cpp.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [hello-cmake] Error 1
make[1]: *** [CMakeFiles/hello-cmake.dir/all] Error 2
make: *** [all] Error 2
If I add the header to the target by swapping the second add_executable command for the first one in CMakeLists.txt, the error goes away. I can also make the error go away by moving the header into the base directory with the .cpp files. However, I'd like to know what's actually going on here. I understand the general value of including the header files in the target, but why is a missing vtable error generated when I don't do this? Unless I grossly misunderstand, all the contents of mainwindow.h should be available while mainwindow.cpp is being compiled by virtue of the #include, whether or not the header is part of the add_executable statement.
--
EDIT
Here are the contents of ui_mainwindow.h, in case they're somehow relevant.
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created by: Qt User Interface Compiler version 5.10.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QPushButton *pushButton;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QStringLiteral("MainWindow"));
MainWindow->resize(393, 307);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
pushButton = new QPushButton(centralWidget);
pushButton->setObjectName(QStringLiteral("pushButton"));
pushButton->setGeometry(QRect(10, 10, 113, 32));
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QStringLiteral("menuBar"));
menuBar->setGeometry(QRect(0, 0, 393, 22));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QStringLiteral("statusBar"));
MainWindow->setStatusBar(statusBar);
retranslateUi(MainWindow);
QObject::connect(pushButton, SIGNAL(released()), pushButton, SLOT(hide()));
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
pushButton->setText(QApplication::translate("MainWindow", "Do not press", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
I was able to migrate my real project to CMake with exactly one hiccup: the linker wasn't happy with any of the signal functions in my QObject-derived classes. (For those not familiar with Qt, a meta-object compiler, moc, magically converts certain empty functions marked as signals in a header file into real functions that the C++ compiler can use.) My conclusion is that both problems resulted from CMake not seeing the header files for a QObject-derived class, and so they were not sent to the moc in spite of the CMAKE_AUTOMOC setting.
The upshot is, if moc (or uic or rcc) needs to compile a file, then CMake has to know it exists before building any dependent targets. The crude solution I used for my project was to grep Q_OBJECT in the directory with all my header files, and copy/paste this list into a long set command in CMakeLists.txt
set(MOC_SOURCES
include/applewidget.h
include/borangewidget.h
...
)
and then add ${MOC_SOURCES} to my add_executable line. There may be a more sophisticated solution that involves building these objects separately, but my use of CMake has not yet reached that level of sophistication.
Meta object compiler (moc) generates moc_*.cpp files from headers. So the build system needs to know which headers to feed it. Similar to C++ compiler that needs to know which files to process. So when working with CMake and Qt you need to consider the header files as source files. CMake is smart enough to not ask C++ compiler to compile them so there's no harm in adding them for other libraries too.
Unfortunately neither Qt-CMake nor CMake-Qt documentation state this explicitly but you should always add headers to the list of sources in add_executable/add_library for CMAKE_AUTOMOC to work.
Another important thing is the minimal required version of CMake. CMake 2.6 does not support Qt5. Neither does CMake 2.8. The official Qt documentation claims the minimal CMake version to be 3.1.0. However CMake 3.0 already has Qt5 support. Still those version are way too old, slow, and buggy so consider updating the requirement. I'd recommend 3.11 or latest stable.

Simple Qt project with openCV instantly crash

I try to use openCV in a Qt project. But my release build instantly crash on launch if I link the release libs of openCV. Debug libs allow the programm to start but the application crashes when I try to use openCV functions (it is known that mixing release/debug in openCV causes some crash).
So I made a simple project and it won't even launch. Both release and debug build crashes and using debugger causes a small window saying 'unexpected CDB exit'.
Here are the source.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_openCV
TEMPLATE = app
#flags to generate a .map file
QMAKE_LFLAGS_RELEASE +=/MAP
QMAKE_LFLAGS_RELEASE += /debug
SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
INCLUDEPATH += $$PWD
INCLUDEPATH += "D:/openCV/build/include"
#Switching between handbuild and the build I downloaded have no effect.
#I am sure the path are good. Quadra checked.
#LIBS += -L"D:/openCV/build/x64/vc11/lib"
LIBS += -L"D:/openCV/hand_build/lib/Release"
LIBS += -L"D:/openCV/hand_build/lib/Debug"
#disables the "fopen not secure" warning in openCV.
DEFINES += _CRT_SECURE_NO_WARNINGS
win32:CONFIG(release, debug|release): LIBS += -lopencv_core2413 -lopencv_highgui2413 -lopencv_imgproc2413
else:win32:CONFIG(debug, debug|release): LIBS += -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
main.cpp:
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv/cv.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
and MainWindow.cpp:
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Removing this line will causes the program to start normally (guess it won't link the libs if nothing from openCV is used).
cv::Mat image;
}
MainWindow::~MainWindow()
{
delete ui;
}
What I get when launching app:
Starting D:\Colin\build_test_openCV\release\test_openCV.exe...
program suddenly ended
D:\Colin\build_test_openCV\release\test_openCV.exe crashed
I work on Windows 7 / MSCV2012 openGL 64bits / Qt 5.2.1 openGL.
Does anyone see a mistakes I could have made?
I have a similar setup as yours and was getting the exact same problem. The issue was that the path to the corresponding dlls was not defined. These dlls:
opencv_core2411.dll
opencv_highgui2411.dll
opencv_imgproc2411.dll
should be in D:/openCV/hand_build/bin/ (or maybe D:/openCV/hand_build/bin/Release/). Adding another line:
LIBS += -L"D:/openCV/hand_build/bin/Release/"
should work.
I just had a similar issue. The program was crashing because it could not find the appropriate DLL at runtime. Adding the OpenCV directories to my Windows PATH fixed the problem for me.
All items in your build must have been built using the same Visual Studio version, that means:
The Qt install you're using.
OpenCV.
Your code.
Most likely at least one of the above was not built using the same compiler. If OpenCV is linked against Qt, it must have been built against a binary-compatible version of Qt, too.

Qt creator cannot find, QTcpServer and QTcpSocket

Eventhough, I put 'network' in .pro file,
My Qt creator cannot find QTcpSocket and QTcpServer.
What should I do?
I remove the Qtcreator and redownloaded already but it also did not work.
My Linux version is Ubuntu 14.04 LTS
and I downloaded QT Creator by linux commands.
sudo apt-get install qtcreator
I even do the linus updates because I worried that I missed something.
sudo get-apt update
sudo get-apt upgrade
Why Qtcreator cannot perceive QTcpServer and QTcpSocket headers?
--------------*.pro -----------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = server11
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
-------------------mainwindow.h--------------------------------------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTcpSocket>
#include <QTcpServer>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
Did you install the complete framework? Or just the IDE?
Try downloading the Qt offline installer and downloading the framework through it. Download and install it from here.
Qt Open Source
Instructions for Ubuntu

Debug Assertion Failed (unsigned)(c+1) <= 256 (in VideoCapture::open [Qt Creator])

I've been trying to use cv::VideoCapture::open("< path to video file >") in QtCreator (opencv added). Even though the program runs without errors in "bebug mode" (debug build), it gives below runtime error in "release mode" (release build).
Debug Assertion Failed File:
f:/dd/vctools/crt_bld/self_x86/src/isctype.c Line: 56 Expression:
(unsigned)(c+1) <= 256
It is a simple program which uses only cv::VideoCapture::open() [for testing purposes]
Below is the .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/C/opencv/build/include
INCLUDEPATH += C:/C/opencv/build/include/opencv
LIBS += C:/C/opencv/build/x86/vc10/lib/opencv_highgui240d.lib
LIBS += C:/C/opencv/build/x86/vc10/lib/opencv_highgui240.lib
LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240d.dll
LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240.dll
Below is the Header file
#include <QMainWindow>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
cv::VideoCapture vcap;
};
Below is the .cpp file
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
vcap.open("C:/Users/ANURUDDHA/pedestrians/ThreePastShop2cor.mpg");
}
MainWindow::~MainWindow()
{
delete ui;
}
When I pass an int as the argument to cv::VideoCapture::open() [eg: vcap.open(0)] it runs without errors in both debug and release build and opens webcam successfully. Problem comes only when I pass a String to arguments.
Someone please shed some light on this. Really appreciated.
It looks like you're linking in both debug and release versions of the libs (twice?). That's caused me problems in the past before. Try using only LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240.dll for release builds and LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240d.dll for debug builds.
Also, 0 is the same as NULL. Probably the library aborts doing whatever it was doing (whether in debug or release) prior to the assert fail. You shouldn't be getting assert fails in release mode, but the fact that you are tells me that the debug library was loaded in your program that you compiled for release mode.
Edit:
Looks like somebody already answered you here:
http://answers.opencv.org/question/15838/videocaptureopenqt-creatordebug-assertion-failed/
I guess I found the answer though it seems kinda ambiguous to me. Anyway, now the program works in release mode.
Hope this might help someone in someway.
I copied dll files inside C:/C/opencv/build/x86/vc10/bin/ to Windows system folder. That is C:\Windows\SysWOW64. In case if someone is using a 32 bit version of Windows it should be System32.