2

I am using the libdvbv5 library however I am having issues getting my program to compile.

I have the headers in /usr/local/include and there is libdvbv5.so in /usr/local/lib.

The code is extremely simple:

#include "libdvbv5/dvb-dev.h"

void doSatTest() {
    struct dvb_device *dvb;
    struct dvb_dev_list *dvb_dev;

    dvb = dvb_dev_alloc();
}

The eclipse indexer is satisfied that the function "dvb_dev_alloc" exists in the header file "dvb-dev.h" and the file compiles but fails on link

I have stopped using the eclipse builder so i can simplify the build command and pinpoint what is happening.

I try to compile and link using the following command:

g++ sat_test.cpp -ldvbv5

However it fails with:

sat_test.cpp:(.text+0x1f): undefined reference to `dvb_dev_alloc()'

What am I missing?

Cœur
  • 37,241
  • 25
  • 195
  • 267
uhsl_m
  • 322
  • 3
  • 11
  • And that is the *only* message you get? On many Linux systems `/usr/local` is not part of the standard include or library search paths. – Some programmer dude Nov 15 '18 at 14:59
  • Yes the only message, the full message is: `/tmp/cc3BD0pW.o: In function "doSatTest()": sat_test.cpp:(.text+0x1f): undefined reference to "dvb_dev_alloc()" collect2: error: ld returned 1 exit status` – uhsl_m Nov 15 '18 at 15:26

1 Answers1

1

The problem is that the the libdvbv5/dvb-dev.h does not provide a proper C++ prototype, and you are including it into a .cpp file.

The fix is to do this:

extern "C" {
#include "libdvbv5/dvb-dev.h"
}
... rest as before.

With above fix, your program will link fine.

A more detailed explanation here.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362