LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-01-2019, 10:38 PM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 537

Rep: Reputation: 74
fatal error: QMainWindow: No such file or directory


qt5 c++ newbie so hopefully this has an easy solution.

Follwing a zetcode tutorial - http://zetcode.com/gui/qt5/menusandtoolbars/

The first example is a simple menu with three files, simplemenu.h, simplemenu.cpp, and main.cpp. I cut and pasted them in corresponding file names.

I then ran "qmake -project", "qmake", and then "make". The make command returns the error mentioned in the subject.

Quote:
fatal error: QMainWindow: No such file or directory
To work around this issue I added include path to QtWidgets in Makefile.
Quote:
-isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets
This cleared the first error but caused numerous issues and eventually a fail.

Quote:
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o simplemenu.o simplemenu.cpp
g++ -Wl,-O1 -o simplemenu main.o simplemenu.o -lQt5Gui -lQt5Core -lGL -lpthread
main.o: In function `SimpleMenu::~SimpleMenu()':
main.cpp.text._ZN10SimpleMenuD2Ev[_ZN10SimpleMenuD5Ev]+0x19): undefined reference to `QMainWindow::~QMainWindow()'
main.o: In function `non-virtual thunk to SimpleMenu::~SimpleMenu()':
main.cpp.text._ZN10SimpleMenuD2Ev[_ZN10SimpleMenuD5Ev]+0x3d): undefined reference to `QMainWindow::~QMainWindow()'
main.o: In function `SimpleMenu::~SimpleMenu()':
main.cpp.text._ZN10SimpleMenuD0Ev[_ZN10SimpleMenuD5Ev]+0x1d): undefined reference to `QMainWindow::~QMainWindow()'
.
.
.
truncated
.
.
.
simplemenu.cpp.text+0xc7): undefined reference to `QMenuBar::addMenu(QString const&)'
simplemenu.cpp.text+0xf6): undefined reference to `QWidget::addAction(QAction*)'
simplemenu.cpp.text+0x114): undefined reference to `QAction::triggered(bool)'
simplemenu.cpp.text+0x159): undefined reference to `QAction::staticMetaObject'
simplemenu.cpp.text+0x1d0): undefined reference to `QMainWindow::~QMainWindow()'
collect2: error: ld returned 1 exit status
Makefile:144: recipe for target 'simplemenu' failed
make: *** [simplemenu] Error 1
I don't have a clue what to try next.

Any suggestions are welcome and thanks in advance.

Cheers,
 
Old 05-02-2019, 06:59 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
is this in your code?

#include <QMainWindow>

(without typos)
 
Old 05-02-2019, 10:40 AM   #3
sharky
Member
 
Registered: Oct 2002
Posts: 537

Original Poster
Rep: Reputation: 74
Quote:
Originally Posted by j-ray View Post
is this in your code?

#include <QMainWindow>

(without typos)
yep.

That #include is in a file called simplemenu.h. Then a file called main.cpp has "#include simplemenu.h".
 
Old 05-02-2019, 09:46 PM   #4
sharky
Member
 
Registered: Oct 2002
Posts: 537

Original Poster
Rep: Reputation: 74
Installed qtcreator and was able to get a simple QMainWindow to work. I'll compare the Makefile generated by qtcreator with what the command line qmake did.
 
Old 05-02-2019, 10:05 PM   #5
sharky
Member
 
Registered: Oct 2002
Posts: 537

Original Poster
Rep: Reputation: 74
Fixed!

Added "-lQt5Widgets" to the 'LIBS' section of Makefile and it compiled with no issues.
 
1 members found this post helpful.
Old 05-03-2019, 02:45 AM   #6
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Good idea and another good idea to share it!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] FATAL: Failed to open file - No such file or directory but file exists swb666 Linux - Newbie 15 01-24-2017 01:44 PM
fatal error: goo/gmem.h: No such file or directory; but file does exist!! lgoldma Linux - General 3 03-07-2013 04:00 PM
QT-Creator and QMainWindow Fantastic Programming 5 11-05-2010 11:05 AM
Buttons are invisible in the QMainWindow iwasapenguin Programming 5 02-14-2008 03:27 PM
Extending QMainWindow iwasapenguin Programming 1 11-18-2007 12:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration