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...)
You could try:
g++ -o processor processor.cpp -lzbar
Related
I'm learning Corba with OmniORB and try to compile simple example program but it doesn't work. Unfortunately is really hard to find some information how to do it.
What I do looks like:
I made simple interface file in idl directory
interface IssueAlert {
string sendAlert(in string alert);
};
Compile it using omniidl -bcxx -Wbexamples echo.idl
I get result files and using examples made that code as a server app.
#include "idl/echo.hh"
#include <iostream>
using namespace std;
class IssueAlert_i : public POA_IssueAlert {
public:
IssueAlert_i();
virtual ~IssueAlert_i();
char* sendAlert(const char* alert);
};
IssueAlert_i::IssueAlert_i(){}
IssueAlert_i::~IssueAlert_i(){}
char* IssueAlert_i::sendAlert(const char* alert){
cout << "Upcall: " << alert << endl;
return CORBA::string_dup(alert);
}
//////////////////////////////////////////////////////////////////////
int main(int argc, char** argv){
try {
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
PortableServer::Servant_var<IssueAlert_i> issue = new
IssueAlert_i();
PortableServer::ObjectId_var issue_id = poa->activate_object(issue);
// Obtain a reference to the object, and print it out as a
// stringified IOR.
obj = issue->_this();
CORBA::String_var sior(orb->object_to_string(obj));
cout << sior << endl;
PortableServer::POAManager_var pman = poa->the_POAManager();
pman->activate();
// Block until the ORB is shut down.
orb->run();
}catch (CORBA::SystemException& ex) {
cerr << "Caught CORBA::" << ex._name() << endl;
}catch (CORBA::Exception& ex) {
cerr << "Caught CORBA::Exception: " << ex._name() << endl;
}
return 0;
}
To compile it i'm using command:
clang++ -std=c++17 -Wall -Wextra -Wnarrowing -Wsign-conversion -lomniORB4 -lomnithread -lomniDynamic4 servant.cpp -I/usr/include -L/usr/lib64/ -o server
All OmniORB things installed by yum are in /usr/include and /usr/lib64.
I get that error:
/tmp/servant-e9e6b6.o: In function `IssueAlert_i::IssueAlert_i()':
servant.cpp:(.text+0x148): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
/tmp/servant-e9e6b6.o: In function `IssueAlert_i::~IssueAlert_i()':
servant.cpp:(.text+0x198): undefined reference to `POA_IssueAlert::~POA_IssueAlert()'
/tmp/servant-e9e6b6.o: In function `IssueAlert_i::~IssueAlert_i()':
servant.cpp:(.text+0x201): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
/tmp/servant-e9e6b6.o: In function `POA_IssueAlert::_this()':
servant.cpp:
(.text._ZN14POA_IssueAlert5_thisEv[_ZN14POA_IssueAlert5_thisEv]+0x1e): undefined reference to `IssueAlert::_PD_repoId'
/tmp/servant-e9e6b6.o:(.rodata+0x68): undefined reference to `_impl_IssueAlert::_dispatch(omniCallHandle&)'
/tmp/servant-e9e6b6.o:(.rodata+0x70): undefined reference to `_impl_IssueAlert::_ptrToInterface(char const*)'
/tmp/servant-e9e6b6.o:(.rodata+0x78): undefined reference to `_impl_IssueAlert::_mostDerivedRepoId()'
/tmp/servant-e9e6b6.o:(.rodata+0xf0): undefined reference to `virtual thunk to _impl_IssueAlert::_ptrToInterface(char const*)'
/tmp/servant-e9e6b6.o:(.rodata+0x100): undefined reference to `virtual thunk to _impl_IssueAlert::_mostDerivedRepoId()'
/tmp/servant-e9e6b6.o:(.rodata+0x120): undefined reference to `virtual thunk to _impl_IssueAlert::_dispatch(omniCallHandle&)'
/tmp/servant-e9e6b6.o:(.rodata+0x288): undefined reference to `typeinfo for POA_IssueAlert'
/tmp/servant-e9e6b6.o:(.rodata+0x290): undefined reference to `POA_IssueAlert::~POA_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x298): undefined reference to `POA_IssueAlert::~POA_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x2a8): undefined reference to `_impl_IssueAlert::_dispatch(omniCallHandle&)'
/tmp/servant-e9e6b6.o:(.rodata+0x2b0): undefined reference to `_impl_IssueAlert::_ptrToInterface(char const*)'
/tmp/servant-e9e6b6.o:(.rodata+0x2b8): undefined reference to `_impl_IssueAlert::_mostDerivedRepoId()'
/tmp/servant-e9e6b6.o:(.rodata+0x318): undefined reference to `typeinfo for POA_IssueAlert'
/tmp/servant-e9e6b6.o:(.rodata+0x320): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x328): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x330): undefined reference to `virtual thunk to _impl_IssueAlert::_ptrToInterface(char const*)'
/tmp/servant-e9e6b6.o:(.rodata+0x340): undefined reference to `virtual thunk to _impl_IssueAlert::_mostDerivedRepoId()'
/tmp/servant-e9e6b6.o:(.rodata+0x360): undefined reference to `virtual thunk to _impl_IssueAlert::_dispatch(omniCallHandle&)'
/tmp/servant-e9e6b6.o:(.rodata+0x3c8): undefined reference to `typeinfo for POA_IssueAlert'
/tmp/servant-e9e6b6.o:(.rodata+0x3d0): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x3d8): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x458): undefined reference to `typeinfo for _impl_IssueAlert'
/tmp/servant-e9e6b6.o:(.rodata+0x460): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x468): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x478): undefined reference to `_impl_IssueAlert::_dispatch(omniCallHandle&)'
/tmp/servant-e9e6b6.o:(.rodata+0x480): undefined reference to `_impl_IssueAlert::_ptrToInterface(char const*)'
/tmp/servant-e9e6b6.o:(.rodata+0x488): undefined reference to `_impl_IssueAlert::_mostDerivedRepoId()'
/tmp/servant-e9e6b6.o:(.rodata+0x4e8): undefined reference to `typeinfo for _impl_IssueAlert'
/tmp/servant-e9e6b6.o:(.rodata+0x4f0): undefined reference to `virtual thunk to _impl_IssueAlert::~_impl_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x4f8): undefined reference to `virtual thunk to _impl_IssueAlert::~_impl_IssueAlert()'
/tmp/servant-e9e6b6.o:(.rodata+0x500): undefined reference to `virtual thunk to _impl_IssueAlert::_ptrToInterface(char const*)'
/tmp/servant-e9e6b6.o:(.rodata+0x510): undefined reference to `virtual thunk to _impl_IssueAlert::_mostDerivedRepoId()'
/tmp/servant-e9e6b6.o:(.rodata+0x530): undefined reference to `virtual thunk to _impl_IssueAlert::_dispatch(omniCallHandle&)'
/tmp/servant-e9e6b6.o:(.rodata+0x6d0): undefined reference to `typeinfo for POA_IssueAlert'
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
Can someone help me with this compilation - unfortuantelly final project i want to do must use C++17 then best will be to stay with this compiler.
Solution found:
clang++ -std=c++17 -Wall -Wextra -Wnarrowing -Wsign-conversion -lomniORB4 -lomnithread -lomniDynamic4 servant.cpp idl/echoSK.cc -o server
It just require to add echoSK.cc into command.
I installed png++, a wrapper for libpng which happens to be for C-programs (i guess) where as for the ray tracing image generation I need to use libpng for a project written entirely in C++, so i installed png++ 2.7
On the documentation page, I tried to compile the example to check if the wrapper installed correctly. Here is the piece of code:
pngtest.cpp
#include <png++/png.hpp>
#include <iostream>
int main()
{
std::cout << "\n***********************************\n";
std::cout << "Testing libpng";
png::image< png::rgb_pixel > image(640, 480);
std::cout <<"Image width: " << image.get_width() <<"\n";
std::cout << "Image height: " << image.get_height() <<"\n";
for (size_t y = 0; y < image.get_height(); ++y)
{
for (size_t x = 0; x < image.get_width(); ++x)
{
//image[y][x] = png::rgb_pixel(x, y, x + y);
// non-checking equivalent of image.set_pixel(x, y, ...);
}
}
image.write("rgb.png");
std::cout << "\n***********************************\n";
return 0;
}
i compiled the above code using the following command:
g++ pngTest.cpp `libpng-config --cflags` -o pngTest.out
and this is the error i get:
pngTest.cpp:(.text._ZN3png9info_baseC2ERNS_7io_baseEP14png_struct_def[_ZN3png9info_baseC5ERNS_7io_baseEP14png_struct_def]+0x37): undefined reference to `png_create_info_struct'
/tmp/ccgfdQ53.o: In function `png::info::write() const':
pngTest.cpp:(.text._ZNK3png4info5writeEv[_ZNK3png4info5writeEv]+0xcc): undefined reference to `png_set_PLTE'
pngTest.cpp:(.text._ZNK3png4info5writeEv[_ZNK3png4info5writeEv]+0x12d): undefined reference to `png_set_tRNS'
pngTest.cpp:(.text._ZNK3png4info5writeEv[_ZNK3png4info5writeEv]+0x148): undefined reference to `png_write_info'
/tmp/ccgfdQ53.o: In function `png::info::sync_ihdr() const':
pngTest.cpp:(.text._ZNK3png4info9sync_ihdrEv[_ZNK3png4info9sync_ihdrEv]+0x6e): undefined reference to `png_set_IHDR'
/tmp/ccgfdQ53.o: In function `png::end_info::destroy()':
pngTest.cpp:(.text._ZN3png8end_info7destroyEv[_ZN3png8end_info7destroyEv]+0x49): undefined reference to `png_destroy_info_struct'
/tmp/ccgfdQ53.o: In function `png::end_info::write() const':
pngTest.cpp:(.text._ZNK3png8end_info5writeEv[_ZNK3png8end_info5writeEv]+0x23): undefined reference to `png_write_end'
/tmp/ccgfdQ53.o: In function `png::io_base::set_swap() const':
pngTest.cpp:(.text._ZNK3png7io_base8set_swapEv[_ZNK3png7io_base8set_swapEv]+0x26): undefined reference to `png_set_swap'
/tmp/ccgfdQ53.o: In function `png::io_base::set_interlace_handling() const':
pngTest.cpp:(.text._ZNK3png7io_base22set_interlace_handlingEv[_ZNK3png7io_base22set_interlace_handlingEv]+0x26): undefined reference to `png_set_interlace_handling'
/tmp/ccgfdQ53.o: In function `png::io_base::raise_error()':
pngTest.cpp:(.text._ZN3png7io_base11raise_errorEv[_ZN3png7io_base11raise_errorEv]+0x21): undefined reference to `png_set_longjmp_fn'
/tmp/ccgfdQ53.o: In function `png::io_base::raise_error(png_struct_def*, char const*)':
pngTest.cpp:(.text._ZN3png7io_base11raise_errorEP14png_struct_defPKc[_ZN3png7io_base11raise_errorEP14png_struct_defPKc]+0x18): undefined reference to `png_get_error_ptr'
/tmp/ccgfdQ53.o: In function `png::writer<std::basic_ofstream<char, std::char_traits<char> > >::writer(std::basic_ofstream<char, std::char_traits<char> >&)':
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEEC2ERS4_[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEEC5ERS4_]+0x28): undefined reference to `png_create_write_struct'
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEEC2ERS4_[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEEC5ERS4_]+0x57): undefined reference to `png_set_write_fn'
/tmp/ccgfdQ53.o: In function `png::writer<std::basic_ofstream<char, std::char_traits<char> > >::~writer()':
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEED2Ev[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEED5Ev]+0x3b): undefined reference to `png_destroy_write_struct'
/tmp/ccgfdQ53.o: In function `png::writer<std::basic_ofstream<char, std::char_traits<char> > >::write_info() const':
pngTest.cpp:(.text._ZNK3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10write_infoEv[_ZNK3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10write_infoEv]+0x24): undefined reference to `png_set_longjmp_fn'
/tmp/ccgfdQ53.o: In function `png::writer<std::basic_ofstream<char, std::char_traits<char> > >::write_row(unsigned char*)':
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE9write_rowEPh[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE9write_rowEPh]+0x28): undefined reference to `png_set_longjmp_fn'
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE9write_rowEPh[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE9write_rowEPh]+0x83): undefined reference to `png_write_row'
/tmp/ccgfdQ53.o: In function `png::writer<std::basic_ofstream<char, std::char_traits<char> > >::write_end_info() const':
pngTest.cpp:(.text._ZNK3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE14write_end_infoEv[_ZNK3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE14write_end_infoEv]+0x24): undefined reference to `png_set_longjmp_fn'
/tmp/ccgfdQ53.o: In function `png::writer<std::basic_ofstream<char, std::char_traits<char> > >::write_data(png_struct_def*, unsigned char*, unsigned long)':
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10write_dataEP14png_struct_defPhm[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10write_dataEP14png_struct_defPhm]+0x1d): undefined reference to `png_get_error_ptr'
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10write_dataEP14png_struct_defPhm[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10write_dataEP14png_struct_defPhm]+0x41): undefined reference to `png_get_io_ptr'
/tmp/ccgfdQ53.o: In function `png::writer<std::basic_ofstream<char, std::char_traits<char> > >::flush_data(png_struct_def*)':
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10flush_dataEP14png_struct_def[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10flush_dataEP14png_struct_def]+0x15): undefined reference to `png_get_error_ptr'
pngTest.cpp:(.text._ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10flush_dataEP14png_struct_def[_ZN3png6writerISt14basic_ofstreamIcSt11char_traitsIcEEE10flush_dataEP14png_struct_def]+0x39): undefined reference to `png_get_io_ptr'
collect2: error: ld returned 1 exit status
can anyone tell where things could have gone wrong. I am using Ubuntu 16.04 LTS and the version of libpng installed on my system is 1.6
this was a silly mistake of using the wrong flag for linker.
The correct compilation command should be:
g++ pngTest.cpp `libpng-config --ldflags` -o pngTest.out
as pointed out by #Galik in the comment the linker was -cflags instead of -ldflags
I would like to compile this code in windows 7: (this)
#include <libxml++/libxml++.h>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(){
xmlpp::DomParser doc;
// 'response' contains your HTML
doc.parse_memory(CleanHTML(html));
xmlpp::Document* document = doc.get_document();
xmlpp::Element* root = document->get_root_node();
xmlpp::NodeSet elemns = root->find("descendant-or-self::*[#id = 'some_id']");
std::cout << elemns[0]->get_line() << std::endl;
std::cout << elemns.size() << std::endl;
return 0;
}
I'm using Code::Blocks, but it gives me errors:
undefined reference to `xmlpp::DomParser::DomParser()'
undefined reference to `Glib::ustring::ustring(std::string const&)'
undefined reference to `xmlpp::DomParser::parse_memory(Glib::ustring const&)'
undefined reference to `Glib::ustring::~ustring()'
undefined reference to `xmlpp::DomParser::get_document()'
undefined reference to `xmlpp::Document::get_root_node() const'
undefined reference to `Glib::ustring::ustring(char const*)'
undefined reference to `xmlpp::Node::find(Glib::ustring const&) const'
undefined reference to `Glib::ustring::~ustring()'
undefined reference to `xmlpp::Node::get_line() const'
undefined reference to `xmlpp::DomParser::~DomParser()'
undefined reference to `Glib::ustring::~ustring()'
undefined reference to `Glib::ustring::~ustring()'
undefined reference to `xmlpp::DomParser::~DomParser()'
So, I thought that I did not linked my librarys correctly; I go in ->project->build options->compiler settings->other options : and I added =>
IC:/gdkdir/include/glib-2.0
IC:/gdkdir/lib/glib-2.0/include
IC:/gdkdir/lib -lglib-2.0 -lintl
IC:/gdkdir/include/gtk-3.0
IC:/gdkdir/include/cairo
IC:/gdkdir/include/pango-1.0
IC:/gdkdir/include/gdk-pixbuf-2.0
IC:/gdkdir/include/libpng15
IC:/gdkdir/include/pixman-1
IC:/gdkdir/include
IC:/gdkdir/include/freetype2
Helped with this I downloaded the librarys => libxml2 and glibmm2.4 and I included them.
And it still gives me the same errors!
Please help me.
UPDATE 17/06 : I also checked this but it still gives me the same errors!
UPDATE 18/06 : That's what I did:
i have the following code:
#include "Poco/Net/DatagramSocket.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Timestamp.h"
#include "Poco/DateTimeFormatter.h"
int main(int argc, char** argv)
{
Poco::Net::SocketAddress sa("127.0.0.1", 8080);
Poco::Net::DatagramSocket dgs(sa);
std::string syslogMsg;
Poco::Timestamp now;
syslogMsg = Poco::DateTimeFormatter::format(now,
"<14>%w %f %H:%M:%S Hello, world!");
return 0;
}
and after compiling i get the following errors:
/tmp/cc38RdWw.o: In function `main':
pocoSender.cpp:(.text+0x4d): undefined reference to `Poco::Net::SocketAddress::SocketAddress(std::string const&, unsigned short)'
pocoSender.cpp:(.text+0x7d): undefined reference to `Poco::Net::DatagramSocket::DatagramSocket(Poco::Net::SocketAddress const&, bool)'
pocoSender.cpp:(.text+0x93): undefined reference to `Poco::Timestamp::Timestamp()'
pocoSender.cpp:(.text+0x11f): undefined reference to `Poco::Timestamp::~Timestamp()'
pocoSender.cpp:(.text+0x135): undefined reference to `Poco::Net::DatagramSocket::~DatagramSocket()'
pocoSender.cpp:(.text+0x140): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()'
pocoSender.cpp:(.text+0x163): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()'
pocoSender.cpp:(.text+0x1ac): undefined reference to `Poco::Timestamp::~Timestamp()'
pocoSender.cpp:(.text+0x1ca): undefined reference to `Poco::Net::DatagramSocket::~DatagramSocket()'
pocoSender.cpp:(.text+0x1d9): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()'
/tmp/cc38RdWw.o: In function `Poco::DateTimeFormatter::format(Poco::Timestamp const&, std::string const&, int)':
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x15): undefined reference to `Poco::DateTime::DateTime(Poco::Timestamp const&)'
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x43): undefined reference to `Poco::DateTime::~DateTime()'
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x52): undefined reference to `Poco::DateTime::~DateTime()'
/tmp/cc38RdWw.o: In function `Poco::DateTimeFormatter::format(Poco::DateTime const&, std::string const&, int)':
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_8DateTimeERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_8DateTimeERKSsi]+0x41): undefined reference to `Poco::DateTimeFormatter::append(std::string&, Poco::DateTime const&, std::string const&, int)'
collect2: error: ld returned 1 exit status
i use the following commandline to compile:
g++ -L/usr/local/lib -lPocoUtil -lPocoFoundation -lPocoNet pocoSender.cpp -o hello
please do not mark the question as duplicate as i have included the required libraries using g++ flags, but i am still getting these errors.
It means that the compiler or linker did not find implementations of these functions. It seems that the corresponding libraries or object modules were not included in building of the project.
I have written below code using C++ Object Interface provided by IBM. I am trying to compile that on RHEL (Linux):
#include <it.h>
#include <iostream.h>
int main() {
ITDBInfo db("dbname","user","pwd","system");
ITConnection conn(db);
conn.Open();
if ( conn.Error() ) {
cout << "Couldn't open connection" << endl;
return -1;
}
ITQuery query( conn );
ITRow *row;
if( !(row = query.ExecOneRow( "select lname from customer;" )) ) {
cout << "Couldn't select from table customer" << endl;
return -1;
}
while ((row = query.NextRow()) != NULL) {
cout << row->Printable() << endl;
}
row->Release();
conn.Close();
}
While compiling on Linux like this:
g++ -Wno-deprecated -I/opt/Informix/11.5FC8/incl/c++ \
-I/opt/Informix/11.5FC8/incl/public \
-L/opt/Informix/11.5FC8/lib/c++ -g -o test1 test1.cpp
I am getting the errors shown below:
/tmp/cchJkPb1.o: In function `main':
test1.cpp:(.text+0x82): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0x90): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0x9e): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0xac): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0xc8): undefined reference to `ITDBInfo::ITDBInfo(ITString const&, ITString const&, ITString const&, ITString const&)'
test1.cpp:(.text+0xd1): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0xea): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0xfc): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x115): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x127): undefined reference to `ITString::~ITString()'
/tmp/cchJkPb1.o:test1.cpp:(.text+0x140): more undefined references to `ITString::~ITString()' follow
/tmp/cchJkPb1.o: In function `main':
test1.cpp:(.text+0x15f): undefined reference to `ITConnection::ITConnection(ITDBInfo const&)'
test1.cpp:(.text+0x178): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x194): undefined reference to `ITConnection::Open()'
test1.cpp:(.text+0x19d): undefined reference to `ITErrorManager::Error() const'
test1.cpp:(.text+0x1e6): undefined reference to `ITQuery::ITQuery(ITConnection const&)'
test1.cpp:(.text+0x1f4): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0x209): undefined reference to `ITQuery::ExecOneRow(ITString const&, ITEssential**)'
test1.cpp:(.text+0x222): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x23b): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x2a6): undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, ITString const&)'
test1.cpp:(.text+0x2c4): undefined reference to `ITQuery::NextRow(ITEssential**)'
test1.cpp:(.text+0x2f1): undefined reference to `ITConnection::Close()'
test1.cpp:(.text+0x317): undefined reference to `ITQuery::~ITQuery()'
test1.cpp:(.text+0x32c): undefined reference to `ITQuery::~ITQuery()'
test1.cpp:(.text+0x366): undefined reference to `ITConnection::~ITConnection()'
test1.cpp:(.text+0x378): undefined reference to `ITConnection::~ITConnection()'
test1.cpp:(.text+0x3b2): undefined reference to `ITDBInfo::~ITDBInfo()'
test1.cpp:(.text+0x3ce): undefined reference to `ITDBInfo::~ITDBInfo()'
collect2: ld returned 1 exit status
The directory /opt/Informix/11.5FC8/lib/c++ is listed in LD_LIBRARY_PATH. Can anyone help me to get rid of these errors?
You are not actually linking with the library using the -l command line parameter. The -L command line parameter tells the linker where to look to find it, but you don't specify the actual library.
Also LD_LIBRARY_PATH is used during runtime, but a better way to configure a non-standard directory is to configure the dynamic linker using /etc/ld.so.conf or a file in /etc/ld.so.conf.d/.