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.
Related
Hello I want to create a Qt5 project using Qt-creator and want to use mpfr/gmp so I need how to configure the project.
because if i compile I get these errors:
#include "mainwindow.h"
#include <QApplication>
#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
mpfr_t x, y, z, t;
mpfr_inits2 (256, x, y, z, t, (mpfr_ptr) 0);
return a.exec();
}
The output:
error: undefined reference to `mpfr_inits2'
But on codeblocks I add the include path and library path and add the flags -lgmp -lmpfr to the compiler and works fine.
In QtCreator, open the .pro file of your project and append the following line:
unix: LIBS += -lmpfr -lgmp
Alternatively, you can also use the UI to do this: In the "Projects" list, right-click on your project, select "Add library" > "System Library". In the "Library file" field add e.g. /usr/lib/mpfr.so. QtCreator will then turn this into -lmpfr, as shown in the "Summary" view. Repeat these steps to add /usr/lib/libgmp.so as well.
Compiler complaining undefined reference to std::thread::_State::~_State() when I am trying to create RSA_PrivateKey object in Botan C++.
#include <QCoreApplication>
#include <botan/rsa.h>
#include <botan/auto_rng.h>
#include <iostream>
using std::cout;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::unique_ptr<Botan::RandomNumberGenerator> rng(new Botan::AutoSeeded_RNG);
cout << rng->name();
// this line caused the error
std::unique_ptr<Botan::RSA_PrivateKey> theKey(new Botan::RSA_PrivateKey(*rng.get(),1024));
return a.exec();
}
Error shows like this:
Error when creating RSA_PrivateKey in Botan
I'm really not sure why the compiler is complaining. I need help, thanks in advance.
I added the botan library as a static library using the ".a" file. I did it by right-clicking the project folder > add library > External Library. I tried to compile in debug.
Added botan like this
OS: Windows 7
Compiler:Qt 5.11.2 MinGW 32-bit
You should create an instance of Botan::RSA_PrivateKey :
Botan::RSA_PrivateKey rsa(*rng.get(),1024);
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 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
A dupe-ish question of this question, which (possibly) has got an outdated answer, as I can't get it to work in Qt5.
I wish to create a symbolic link to a folder for a result similar to QFile::link(). Given that QDir doesn't have an equivalent function, QProcess (or an external library) seems like the way out if I'm up to snuff. How would this be managed in Qt5?
Big thanks in advance.
There are shortcuts and hardlinks on Windows. I think mklink refers to hardlinks.
It works for shortcuts:
#include <QCoreApplication>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile dir("D:\\source-dir");
bool ok = dir.link("D:\\target-dir.lnk");
if (ok)
{
qDebug() << "yeah!";
return 0;
}
else {
qDebug() << "Did not work :(";
return 1;
}
}
In this case you will find a shortcut in the Explorer but you cannot access the file D:\source-dir\Bitmap.bmp by typing D:\target-dir\Bitmap.bmp
I found out that it cannot be done in Qt, so I ended up using the Win32 API instead. Specifically the CreateSymbolicLink() function.