uhsl_m
uhsl_m

Reputation: 342

Linking shared library libdvbv5, undefined reference

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?

Upvotes: 2

Views: 315

Answers (1)

Employed Russian
Employed Russian

Reputation: 213526

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.

Upvotes: 1

Related Questions