Qt link to libparted error

240 Views Asked by At

currently I want to make a Qt application that able to read the HDD partition (maybe in the future able to make patitions on HDD). And I found that libparted can be used for this (my application will be only for Linux).

Already install libparted on machine and here my simple code :

#include "parted/device.h"
...
void MainWindow::test() {
    ped_device_probe_all();
}

And add this libs to qmake

LIBS += -lparted

But have error linker :

undefined reference to `ped_device_probe_all()'

I am not sure whats wrong with my code, is there anyone has the problem, need help please.

2

There are 2 best solutions below

0
On BEST ANSWER

You have to add parted.h:

#include <parted/parted.h>
#include <parted/device.h>
... 
void MainWindow::test() {
    ped_device_probe_all();
}
0
On

I have encounted this error too. include parted.h doesn't help. libparted is C library, so I add extern "C" before include device.h, according to using c libraries for c++ programs, and it works.

extern "C" {
#include "parted/device.h"
}