Frage

I need to use ZBar libs for my own c++ program, but I can't even compile the examples. It looks like the compiler can't find the object files or something like that, I get errors like "undefined reference to `_zbar_get_error_code'".

I copied from their wiki the following source:

#include <iostream>
#include <zbar.h>

using namespace std;
using namespace zbar;

class MyHandler : public Image::Handler
{
void image_callback (Image &image)
{
    for(SymbolIterator symbol = image.symbol_begin();
        symbol != image.symbol_end();
        ++symbol)
        cout << "decoded " << symbol->get_type_name() << " symbol "
             << "\"" << symbol->get_data() << "\"" << endl;
    }
};

int main (int argc, char **argv)
{
const char *device = "/dev/video0";
if(argc > 1)
    device = argv[1];
Processor proc(true, device);

proc.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);

MyHandler my_handler;
proc.set_handler(my_handler);

proc.set_visible();
proc.set_active();

try {
    proc.user_wait();
}
catch(ClosedError &e) {
}
return(0);
}

and I try to compile it with the shell command (copied from their wiki)

g++ -o processor -lzbar processor.cpp

and here are the errors i get:

/tmp/ccex0UN8.o: In function `zbar::throw_exception(void const*)':
scan.cpp:(.text+0xe): undefined reference to `_zbar_get_error_code'
/tmp/ccex0UN8.o: In function `zbar::Exception::what() const':
scan.cpp:(.text._ZNK4zbar9Exception4whatEv[zbar::Exception::what() const]+0x29): undefined reference to `_zbar_error_string'
/tmp/ccex0UN8.o: In function `zbar::SymbolSet::ref(int) const':
scan.cpp:(.text._ZNK4zbar9SymbolSet3refEi[zbar::SymbolSet::ref(int) const]+0x1f): undefined reference to `zbar_symbol_set_ref'
/tmp/ccex0UN8.o: In function `zbar::Symbol::ref(int) const':
scan.cpp:(.text._ZNK4zbar6Symbol3refEi[zbar::Symbol::ref(int) const]+0x1f): undefined reference to `zbar_symbol_ref'
/tmp/ccex0UN8.o: In function `zbar::Symbol::get_type_name() const':
scan.cpp:(.text._ZNK4zbar6Symbol13get_type_nameEv[zbar::Symbol::get_type_name() const]+0x1c): undefined reference to `zbar_get_symbol_name'
/tmp/ccex0UN8.o: In function `zbar::Symbol::init(zbar::zbar_symbol_s const*)':
scan.cpp:(.text._ZN4zbar6Symbol4initEPKNS_13zbar_symbol_sE[zbar::Symbol::init(zbar::zbar_symbol_s const*)]+0x1c): undefined reference to `zbar_symbol_get_type'
scan.cpp:(.text._ZN4zbar6Symbol4initEPKNS_13zbar_symbol_sE[zbar::Symbol::init(zbar::zbar_symbol_s const*)]+0x3a): undefined reference to `zbar_symbol_get_data_length'
scan.cpp:(.text._ZN4zbar6Symbol4initEPKNS_13zbar_symbol_sE[zbar::Symbol::init(zbar::zbar_symbol_s const*)]+0x47): undefined reference to `zbar_symbol_get_data'
/tmp/ccex0UN8.o: In function `zbar::SymbolIterator::SymbolIterator(zbar::SymbolSet const&)':
scan.cpp:(.text._ZN4zbar14SymbolIteratorC2ERKNS_9SymbolSetE[_ZN4zbar14SymbolIteratorC5ERKNS_9SymbolSetE]+0x55): undefined reference to `zbar_symbol_set_first_symbol'
/tmp/ccex0UN8.o: In function `zbar::SymbolIterator::SymbolIterator(zbar::SymbolIterator const&)':
scan.cpp:(.text._ZN4zbar14SymbolIteratorC2ERKS0_[_ZN4zbar14SymbolIteratorC5ERKS0_]+0x55): undefined reference to `zbar_symbol_set_first_symbol'
/tmp/ccex0UN8.o: In function `zbar::SymbolIterator::operator++()':
scan.cpp:(.text._ZN4zbar14SymbolIteratorppEv[zbar::SymbolIterator::operator++()]+0x24): undefined reference to `zbar_symbol_next'
scan.cpp:(.text._ZN4zbar14SymbolIteratorppEv[zbar::SymbolIterator::operator++()]+0x57): undefined reference to `zbar_symbol_set_first_symbol'
/tmp/ccex0UN8.o: In function `zbar::Image::Handler::_cb(zbar::zbar_image_s*, void const*)':
scan.cpp:(.text._ZN4zbar5Image7Handler3_cbEPNS_12zbar_image_sEPKv[zbar::Image::Handler::_cb(zbar::zbar_image_s*, void const*)]+0x13): undefined reference to            `zbar_image_get_userdata'
/tmp/ccex0UN8.o: In function `zbar::Image::get_symbols() const':
scan.cpp:(.text._ZNK4zbar5Image11get_symbolsEv[zbar::Image::get_symbols() const]+0xf): undefined reference to `zbar_image_get_symbols'
/tmp/ccex0UN8.o: In function `zbar::Processor::Processor(bool, char const*, bool)':
scan.cpp:(.text._ZN4zbar9ProcessorC2EbPKcb[_ZN4zbar9ProcessorC5EbPKcb]+0x1b): undefined reference to `zbar_processor_create'
/tmp/ccex0UN8.o: In function `zbar::Processor::~Processor()':
scan.cpp:(.text._ZN4zbar9ProcessorD2Ev[_ZN4zbar9ProcessorD5Ev]+0xf): undefined reference to `zbar_processor_destroy'
/tmp/ccex0UN8.o: In function `zbar::Processor::init(char const*, bool)':
scan.cpp:(.text._ZN4zbar9Processor4initEPKcb[zbar::Processor::init(char const*, bool)]+0x24): undefined reference to `zbar_processor_init'
/tmp/ccex0UN8.o: In function `zbar::Processor::set_handler(zbar::Image::Handler&)':
scan.cpp:(.text._ZN4zbar9Processor11set_handlerERNS_5Image7HandlerE[zbar::Processor::set_handler(zbar::Image::Handler&)]+0x25): undefined reference to `zbar_processor_set_data_handler'
/tmp/ccex0UN8.o: In function `zbar::Processor::set_config(zbar::zbar_symbol_type_e, zbar::zbar_config_e, int)':
scan.cpp:(.text._ZN4zbar9Processor10set_configENS_18zbar_symbol_type_eENS_13zbar_config_eEi[zbar::Processor::set_config(zbar::zbar_symbol_type_e, zbar::zbar_config_e, int)]+0x24): undefined reference to `zbar_processor_set_config'
/tmp/ccex0UN8.o: In function `zbar::Processor::set_visible(bool)':
scan.cpp:(.text._ZN4zbar9Processor11set_visibleEb[zbar::Processor::set_visible(bool)]+0x1d): undefined reference to `zbar_processor_set_visible'
/tmp/ccex0UN8.o: In function `zbar::Processor::set_active(bool)':
scan.cpp:(.text._ZN4zbar9Processor10set_activeEb[zbar::Processor::set_active(bool)]+0x1d): undefined reference to `zbar_processor_set_active'
/tmp/ccex0UN8.o: In function `zbar::Processor::user_wait(int)':
scan.cpp:(.text._ZN4zbar9Processor9user_waitEi[zbar::Processor::user_wait(int)]+0x16): undefined reference to `zbar_processor_user_wait'
collect2: ld returned 1 exit status

I'm using Ubuntu 12.04, installed build-essential and libzbar-dev

PS: I choosed ZBar over ZXing cause from the already compiled examples it detects much more QR-Codes (eg more inclinated, smaller, with more noise etc...)

War es hilfreich?

Lösung

You could try:

g++ -o processor processor.cpp -lzbar

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top