I have this error when compiling my first gtkmm project.
gtkmmgui.cpp:2:10: fatal error: gtkmm-3.0: No such file or directory
I also tried this:
g++ gtkmmgui.cpp `pkg-config --cflags --libs gtkmm3.0`
but it still doesn't work.
Is this because of wrong #include directory?
Source:
#include <iostream>
#include <gtkmm-3.0>
int main() {
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Window::run(window)
return 0;
}
There should be nothing like
#include "gtkmm-3.0"
in your source.
Typically all includes look like:
#include <gtkmm/application.h>
#include <gtkmm/window.h>
You should provide also your source code here, because the error is something there! But please reduce it to the minimum where we can see your problem. Please never post all your code which is not related to the problem you ask for.
You also can check if your configuration of gtkmm is correct by simply looking in the output of you pkg-config command. Simply enter it on the command line:
> pkg-config gtkmm-3.0 --cflags
It should be something like:
-I/usr/include/gtkmm-3.0 -I/usr/lib64/gtkmm-3.0/include < a lot more >
EDIT: Your example code is broken in so many parts! Please read the manual of gtkmm!
The following works:
#include <gtkmm/window.h>
#include <gtkmm/main.h>
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Gtk::Window window;
kit.run(window);
return 0;
}
compiled and linked with:
g++ `pkg-config gtkmm-3.0 --cflags --libs` main.cpp
Related
I am trying to begin an opencv project. I have installed all of the dependancies etc.
I am running the following to compile the program
g++ $(pkg-config --cflags --libs opencv4) -std=c++11 main.cpp -o yourFileProgram
inside of main.cpp:
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
cv::RNG rng(12345);
int main(int argc, const char * argv[]) {
return 0;
}
The code compiles, however when I run ./yourFileProgram the exec never terminates.
Main.cpp
#include <QApplication>
int main (int argc, char* argv[]) {
QApplication app(argc, argv);
return app.exec();
}
test.pro
SOURCES += \
main.cpp
greaterThan(QT_MAJOR_VERSION,4) : QT +=widgets
outputs :
I can't compile my project because of "undefined reference to", it seems that my compiler doesn't find "QApplication" but i don't know how to solve it.
I unistall and reinstall my Qt but it didn't fix it.
I am new to C++ and to gtkmm. I am currently trying to compile a tutorial I found online using a window and a button. I am compiling in Ubuntu 12.04. I can compile a single file fine but when I try to compile several files using a Makefile I get an error that I don't understand:
sarah#superawesome:~/gtkexample$ make
g++ -c main.cc
In file included from HelloSarah.h:4:0,
from main.cc:1:
/usr/include/gtkmm-3.0/gtkmm/button.h:7:28: fatal error: glibmm/ustring.h: No such file or directory
compilation terminated.
make: *** [main.o] Error 1
I really don't understand the error, I've been searching for hours. I would really appreciate any help or insight into my problem.
These are my 3 files and Makefile:
#ifndef GTKMM_HELLOSARAH_H
#define GTKMM_HELLOSARAH_H
#include <gtkmm-3.0/gtkmm/button.h>
#include <gtkmm/window.h>
class HelloSarah : public Gtk::Window
{
public:
HelloSarah();
virtual ~HelloSarah();
protected:
//Signal handlers:
void on_button_clicked();
//Member widgets:
Gtk::Button m_button;
};
#endif
and
main.cc
#include "HelloSarah.h"
#include <gtkmm/application.h>
int main (int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
HelloSarah hellosarah;
//Shows the window and returns when it is closed.
return app->run(hellosarah);
}
and HelloSarah.cc
#include "helloSarah.h"
#include <iostream>
HelloSarah::HelloSarah()
: m_button("Hello Sarah") // creates a new button with label "HelloSarah".
{
// Sets the border width of the window.
set_border_width(10);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this,
&HelloSarah::on_button_clicked));
// This packs the button into the Window (a container).
add(m_button);
// The final step is to display this newly created widget...
m_button.show();
}
HelloSarah::~HelloSarah()
{
}
void HelloSarah::on_button_clicked()
{
std::cout << "Hello Sarah" << std::endl;
}
and finally my Makefile:
app: main.o HelloSarah.o
g++ -o app main.o HelloSarah.o
main.o: main.cc HelloSarah.h
g++ -c main.cc
HelloSarah.o: HelloSarah.cc HelloSarah.h
g++ -c HelloSarah.cc
clean:
rm -f *.o app
The following include statement in your example is not correct. It works only because the file path is relative to the standard /usr/include/ directory, but the include statement in button.h does not, so you get an error message.
#include <gtkmm-3.0/gtkmm/button.h>
You have to tell g++ where the necessary include files and shared objects can be found. You can use the output of pkg-config to do that job.
pkg-config --cflags --libs gtkmm-3.0
The whole g++ command should be something like that.
g++ `pkg-config --cflags --libs gtkmm-3.0` -c HelloSarah.cc
After that you can simply use the include line in gtkmm Hello World.
#include <gtkmm/button.h>
I had this problem too on Ubuntu.
The solution:
sudo apt-get install libgtkmm-3.0-dev
You can use any version as you need.
Here I am with a similar question as the last time, and for which I could not find any answer.
Note that I consider important: Normally I compile my programs in opencv with the next command:
g++ -o def program.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv`
This line will create an executable whose name will be def and that I will be able to use.
I am working in a project, and as it was getting bigger, I had to define some objects, just to make everything easier and possible to handle. I create one object from the files: homogra.cpp and homogra.h the comand I used for it was:
g++ -c homogra.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv`
Then, I wrote in my program.cpp the line #include "homogra.h"
And I compile like:
g++ -o def program.cpp homogra.o `pkg-config --cflags opencv` `pkg-config --libs opencv`
Until now everything is working fine.
Then I create a second object(with the same compilation line as for homogra, but this time with segmentator.cpp and segmentator.h), i wrote the line #include "segmentator.h",(in program.cpp) and I compile like:
g++ -o def program.cpp .o segmentator.o `pkg-config --cflags opencv` `pkg-config --libs opencv`
Now it is not working, and it is not recognising segmentator. I checked already if segmentator was working and everything works fine if homogra is the only include in the program.cpp.
I notice something strange. If I change the lines and I write before,in the #include lines, #include "segmentator.h" and then #include "homogra.h", then the compiler, with the same line for compiling :
g++ -o def program.cpp homogra.o segmentator.o `pkg-config --cflags opencv` `pkg-config --libs opencv`
is only recognising this time segmentator and not homogra. It is maybe a little difficult to understand, I tried to explained it as better as possible.
Any help!?
Many thanks in advance.
Here is homogra.h:
using namespace cv;
using namespace std;
#ifndef _NAMES_H
#define _NAMES_H
class homogra {
public:
Mat matCalculation( Mat img, Mat img2);
void printMatrix(Mat matrix);
};
#endif
In homogra.cpp I have all the tipical includes and homogra.h:
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <sstream>
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "homogra.h"
And then the functions explained.
Object 2 is segmentator.h
using namespace cv;
using namespace std;
#ifndef _NAMES_H
#define _NAMES_H
class segmentator {
public:
void search(Mat img,vector<std::vector<cv::Point> >& contours);
void similar(vector<std::vector<cv::Point> >& contours,vector<std::vector<cv::Point> >& contours2,vector<int>& idx);
vector<Mat> separate(Mat img,Mat img2,vector<std::vector<cv::Point> >& contours,vector<std::vector<cv::Point> >& contours2,vector<int> idx);
};
#endif
And in segmentator.cpp I have again all the same includes, except homogra.h and instead of this one I have segmentator.h.
Program.cpp is image_reg.cpp:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "homogra.h"
#include "segmentator.h"
using namespace cv;
using namespace std;
int main(int argc, char ** argv )
{ //Here is the code where I try to invoque two instances of homogra and segmentator.
}
If I let homogra.h as the first to be read in the includes list of image_reg.cpp then only homogra.h is recognised, if I let at the first position segmentator, then only segmentator.h instances would be created and homogra. h would not be recognised.
Thanks
Your include header guards are wrong. They should be unique, using the name of the source file, rather than just _NAMES_H.
So in homogra.h you should have this:
#ifndef HOMOGRA_H
#define HOMOGRA_H
...
#endif
...and in segmentator.h, you should have this
#ifndef SEGMENTATOR_H
#define SEGMENTATOR_H
...
#endif
Also, it's really bad practice to have a using namespace xxx; in a header file. You make it very difficult for your headers to coexist with others.
As Jonathan Wakely points out, beginning symbols with underscores is not a great idea, either.
Now I am feeling quite stupid. I am trying to do some stuff with xlib in Qt Creator.
My code:
#include <QtCore/QCoreApplication>
#include <X11/Xlib.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Display *display = XOpenDisplay(NULL);
return 0;
}
Just one line of code and gives me:
/main.cpp:8: undefined reference to `XOpenDisplay'
It is defined in Xlib.h as
extern Display *XOpenDisplay(
_Xconst char* /* display_name */
);
I feel I am missing something very basic.
I've figured it out.
Adding -lX11 to the the Makefile solved this issue.
#КодСерфинг145 I added LIBS += -lX11 to the make file (the .pro file)
Adding Additional arguments to Build steps inside Projects did not work for me either and neither did QMAKE_CXXFLAGS += -lX11 like many suggests.