1

I have some problem with Qt environment. I want to use only environment Qt to console application, I am writing code in C++ but **I must use Cross Compilator. **Of course I have installed correctly in my Qt.

Additional I must use dbus-1.6.8. This is important condition, because I writing code to embedded systems, and library should be this same as was use in device.

http://dbus.freedesktop.org/releases/dbus/dbus-1.6.8.tar.gz

I put directory with source to directory with my project and modified *.pro file add path

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += ./dbus-1.6.8  

After this I included to my main.cpp right main header file which includes all next necessary header

#include <dbus/dbus.h>

Next I tried use this library

#include <dbus/dbus.h>
main(){

DBusError err;   // both values it is OK Qt finds this type
DBusConnection *dbus_conn;

// but below function doesn't find

    dbus_error_init(&err);
    dbus_conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);

}

I get error

 undefined reference to `dbus_error_init'
 undefined reference to `dbus_bus_get_private'
 collect2: error: ld returned 1 exit status

Of course above function is exist in source directory I checked. Despite this Qt doesn't find these declaration.

What is wrong ?

PS: Additionally I add tree directory, of course this is not all, but most important directory is visible

.
├── bus
├── cmake
│   ├── bus
│   ├── dbus
│   ├── doc
│   ├── modules
│   ├── test
│   │   └── name-test
│   └── tools
├── dbus
├── doc
├── m4

...
....
....

And only dbus direcytory

├── dbus
│   ├── dbus-address.c
│   ├── dbus-address.h
│   ├── dbus-arch-deps.h
│   ├── dbus-arch-deps.h.in
│   ├── dbus-auth.c
│   ├── dbus-auth.h
│   ├── dbus-auth-script.c
│   ├── dbus-auth-script.h
│   ├── dbus-auth-util.c
│   ├── dbus-bus.c
│   ├── dbus-bus.h
│   ├── dbus-connection.c
│   ├── dbus-connection.h
│   ├── dbus-connection-internal.h
│   ├── dbus-credentials.c
│   ├── dbus-credentials.h
│   ├── dbus-credentials-util.c
│   ├── dbus-dataslot.c
│   ├── dbus-dataslot.h
│   ├── dbus-errors.c
│   ├── dbus-errors.h
│   ├── dbus-file.c
│   ├── dbus-file.h
│   ├── dbus-file-unix.c
│   ├── dbus-file-win.c
│   ├── dbus.h                          // main header
│   ├── dbus-hash.c
│   ├── dbus-hash.h
│   ├── dbus-internals.c
│   ├── dbus-internals.h
│   ├── dbus-keyring.c
│   ├── dbus-keyring.h
│   ├── dbus-list.c
.....
.....
.....
Cœur
  • 37,241
  • 25
  • 195
  • 267
Mbded
  • 1,754
  • 4
  • 23
  • 43

1 Answers1

2

If you have compiled dbus, you should get a library named libdbus-1.so.

In your Qt .pro file, add the path to the library and link the library.

Example:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += ./dbus-1.6.8  
LIBS += -L./dbus-1.6.8 -ldbus-1

You have more info about dbus and related libraries here. You don't need to compile and install dbus from source. You could install it using apt-get. It's up to you anyway :)

Community
  • 1
  • 1
Tarod
  • 6,732
  • 5
  • 44
  • 50
  • In dbus direcytory I also find this `libdbus-1.la , libdbus-internal.la` it also shared library but probably this is not this same. I try recompile this. Line `LIBS += -L./dbus-1.6.8 -ldbus-1` give me for this time error `cannot find -ldbus-1`, so this is sugest that I still doesn't have this library. And remember I need this library for **DIFRENT ARCHITECTURE** Thx – Mbded Aug 31 '15 at 10:59
  • 1
    @Mbed Did you install the library or just compiled it? If you enter the root directory (in your case, `dbus-1.6.8`), did you have the path `dbus/.libs/`? In that directory, you should have the .so I stated before. In the .pro file, LIBS should be set to the right directory. – Tarod Aug 31 '15 at 11:19
  • @Mbed Enter the `dbus-1.6. 8` directory and try to find the .so with this command: `find . -name \*dbus-1\*` – Tarod Aug 31 '15 at 11:30
  • I got this library for some gay. I come in to this direcytory as You tell me and now I see file `libdbus-1.so , libdbus-1.so.3 , libdbus-1.so.3.7.2`. I changed in Qt in pro file line on `LIBS += -L ./dbus-1.6.8 -libdbus-1` but I still get error, can not find... – Mbded Aug 31 '15 at 11:31
  • 1
    But where are those libs? The `LIBS` variable must have the path to where the libraries are. And don't write `lib` after `-l` , only the library name: `dbus-1`. – Tarod Aug 31 '15 at 11:46
  • 1
    @Mbded, pay attention: not `-libdbus-1` but `-ldbus-1` event if library name is `libdbus-1.so`! This is not part of name but compiler option `-l`! – Gluttton Aug 31 '15 at 14:02
  • Gentelmen, something is still wrong I tryed path `LIBS += -L ./dbus-1.6.8/dbus -ldbus-1` and I also tryed `LIBS += -L ./dbus-1.6.8/dbus/.libs -ldbus-1` and still this same error can not find ldbus-1 – Mbded Aug 31 '15 at 19:44
  • Solved !!!, but I think something is wrong with my Qt... I copy this liberary `libdbus-1.so.3.7.2` **to direcytory /lib in my toolchain and works** ! May be something sugestion why doesn't work writed correct path ? I would remnid I create project for difrent architecture may by this have some impact ? – Mbded Aug 31 '15 at 20:00
  • 1
    Good news then! :) In my opinion, the project configuration you've mentioned shouldn't be the problem because if `INCLUDEPATH` is working and the project finds the headers, `LIBS` should also work. Are really the library in `./dbus-1.6.8/dbus/.libs` or did you find the .so in other subdirectory (such as cmake)? – Tarod Aug 31 '15 at 21:57
  • No I don't find more *.so it is only in .libs direcytory. My Qt behaves very strange, do not remeber last project, and setings, I do not see her in default program to programing, I do know. No less subject has been solved and this is most important. Thx agian – Mbded Sep 01 '15 at 07:32
  • @Mbded Thanks to you. Happy codding :) – Tarod Sep 01 '15 at 07:55