g++ is letting out an obscure error, undefined reference to '__gxx_personality_sj0' in two lines of my project. What does this mean in this context? I googled a lot and found out this is usually related to the inclusion of C code in C++ or something like that, which is not what I'm going for. (I know the code isn't high quality, but should compile, I believe).
Projecto.cpp
#include "Projecto.h"
#include <iostream>
#include <iomanip>
#include <string>
Projecto::~Projecto() {} //THIS LINE GETS THAT ERROR
void Projecto::adicionaVerba(float quantia){
verba+=quantia;
if(verba > verbamaxima)
verba -= quantia;
}
std::string Projecto::Tipo()
{ //THIS LINE GETS THAT ERROR
return "Projecto";
}
void Projecto::Imprime()
{
Identificador::Imprime();
cout << verbamaxima << endl;
}
bool Projecto::operator> (const Projecto &proj2) const
{
return proj2.verba > this->verba;
}
Projecto.h
#ifndef PROJECTO_H_
#define PROJECTO_H_
#include <iostream>
#include <iomanip>
#include "Identificador.h"
#include <string>
#include <vector>
using namespace std;
class Projecto: public Identificador {
protected:
int verbamaxima;
vector<string> projecto;
float verba;
public:
Projecto(int verbamaxima = 0):Identificador("Projecto") {verba=0;}
~Projecto();
string Tipo();
void Imprime();
void adicionaVerba(float quantia);
bool operator> (const Projecto &proj2) const;
};
#endif /* IDENTIFICADOR_H_ */
Identificador.cpp
#include "Identificador.h"
using namespace std;
#include <iostream>
#include <iomanip>
using namespace std;
Identificador::Identificador(string nome):codigo(id)
{
Identificador::nome = nome;
id+=2;
}
Identificador::~Identificador()
{
}
int Identificador::id = 1000;
string Identificador::Tipo(){}
void Identificador::Imprime()
{
cout << Tipo() << endl;
cout << Codigo() << endl;
cout << Nome() << endl;
}
int Identificador::Codigo() const
{
return codigo;
}
string Identificador::Nome()
{
return nome;
}
Identificador.h
#ifndef IDENTIFICADOR_H_
#define IDENTIFICADOR_H_
#include <iostream>
#include <iomanip>
using namespace std;
class Identificador {
protected:
static int id;
const int codigo;
string nome;
public:
Identificador(string nome);
virtual ~Identificador();
virtual string Tipo();
virtual void Imprime();
int Codigo() const;
string Nome();
};
#endif /* IDENTIFICADOR_H_ */
Thank you for reading this far!
EDIT:
I am using Eclipse with the mingw toolchain. I've recently installed Nuwen's Mingw distro in lieu of the official one. Compiling the project, I get this as console output (never happened before):
**** Build of configuration Debug for project estudo_CI1 ****
**** Internal Builder is used for build ****
g++ -oestudo_CI1.exe src\main.o src\Universidade.o src\Projecto.o src\Investigador.o src\Identificador.o
Warning: .drectve `-aligncomm:___mingw_gMTRemoveKeyDtor,2 ' unrecognized
Warning: .drectve `-aligncomm:___mingw_gMTKeyDtor,2 ' unrecognized
Warning: .drectve `-aligncomm:___mingw_usemthread_dll,2' unrecognized
Warning: .drectve `-aligncomm:___hexdig_D2A,2' unrecognized
src\Projecto.o: In function `ZN8ProjectoD2Ev':
C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:16: undefined reference to `__gxx_personality_sj0'
src\Projecto.o: In function `ZN8ProjectoD1Ev':
C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:16: undefined reference to `__gxx_personality_sj0'
src\Projecto.o: In function `ZN8ProjectoD0Ev':
C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:16: undefined reference to `__gxx_personality_sj0'
src\Projecto.o: In function `ZN8Projecto4TipoEv':
C:/Users/Francisco/workspace_aeda/estudo_CI1/Debug/../src/Projecto.cpp:27: undefined reference to `__gxx_personality_sj0'
src\Projecto.o: In function `ZNSt12_Vector_baseISsSaISsEE12_Vector_implD1Ev':
C:/strawberry/c/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_vector.h:(.text$_ZNSt6vectorISsSaISsEED1Ev[std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~vector()]+0xc): undefined reference to `__gxx_personality_sj0'
src\Projecto.o:C:/strawberry/c/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_vector.h:(.text$_ZNSt12_Vector_baseISsSaISsEED2Ev[std::_Vector_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~_Vector_base()]+0xc): more undefined references to `__gxx_personality_sj0' follow
/mingw/lib/libstdc++.a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev+0x719): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev+0x739): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev+0x759): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev+0x779): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev+0x799): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios_init.o):ios_init.cc:(.text$_ZNSt8ios_base4InitC2Ev+0x7b9): more undefined references to `_Unwind_Resume' follow
/mingw/lib/libstdc++.a(eh_throw.o):eh_throw.cc:(.text$__cxa_throw+0x4e): undefined reference to `_Unwind_RaiseException'
/mingw/lib/libstdc++.a(eh_throw.o):eh_throw.cc:(.text$__cxa_rethrow+0x37): undefined reference to `_Unwind_Resume_or_Rethrow'
/mingw/lib/libstdc++.a(misc-inst.o):misc-inst.cc:(.text$_ZStrsIwSt11char_traitsIwESaIwEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_E[std::basic_istream<wchar_t, std::char_traits<wchar_t> >& std::operator>><wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >(std::basic_istream<wchar_t, std::char_traits<wchar_t> >&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)]+0x270): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios.o):ios.cc:(.text$_ZNSt8ios_baseD2Ev+0xd1): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios.o):ios.cc:(.text$_ZNSt8ios_baseD0Ev+0xd6): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios.o):ios.cc:(.text$_ZNSt8ios_base13_M_grow_wordsEib+0x126): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios.o):ios.cc:(.text$_ZNSt8ios_base13_M_grow_wordsEib+0x18e): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ios.o):ios.cc:(.text$_ZNSt8ios_base17_M_call_callbacksENS_5eventE+0x4b): more undefined references to `_Unwind_Resume' follow
/mingw/lib/libstdc++.a(eh_personality.o):eh_personality.cc:(.text$__gxx_personality_v0+0xce): undefined reference to `_Unwind_GetIPInfo'
/mingw/lib/libstdc++.a(eh_personality.o):eh_personality.cc:(.text$__cxa_call_unexpected+0xd5): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEED1Ev[__gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::~stdio_filebuf()]+0x67): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEED0Ev[__gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::~stdio_filebuf()]+0x6f): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIwSt11char_traitsIwEED1Ev[__gnu_cxx::stdio_filebuf<wchar_t, std::char_traits<wchar_t> >::~stdio_filebuf()]+0x67): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIwSt11char_traitsIwEED0Ev[__gnu_cxx::stdio_filebuf<wchar_t, std::char_traits<wchar_t> >::~stdio_filebuf()]+0x6f): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(ext-inst.o):ext-inst.cc:(.text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEEC2EiSt13_Ios_Openmodej[__gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(int, std::_Ios_Openmode, unsigned int)]+0xb1): more undefined references to `_Unwind_Resume' follow
/mingw/lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text$__cxa_get_globals_fast+0xb): undefined reference to `__emutls_get_address'
/mingw/lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text$__cxa_get_globals+0xb): undefined reference to `__emutls_get_address'
/mingw/lib/libstdc++.a(istream.o):istream.cc:(.text$_ZNSi7getlineEPcic+0x26d): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(istream.o):istream.cc:(.text$_ZNSi6ignoreEii+0x2a4): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(istream.o):istream.cc:(.text$_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_+0x241): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(istream.o):istream.cc:(.text$_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_E+0x2d9): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(istream.o):istream.cc:(.text$_ZSt7getlineIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_ES4_+0x2a1): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(istream.o):istream.cc:(.text$_ZNSt13basic_istreamIwSt11char_traitsIwEE7getlineEPwiw+0x2a5): more undefined references to `_Unwind_Resume' follow
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$_ZN12_GLOBAL__N_1L4initEv+0x14): undefined reference to `__gthr_win32_recursive_mutex_init_function'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$_ZN9__gnu_cxx17__recursive_mutex6unlockEv[__gnu_cxx::__recursive_mutex::unlock()]+0x15): undefined reference to `__gthr_win32_recursive_mutex_unlock'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$__cxa_guard_acquire+0x40): undefined reference to `__gthr_win32_recursive_mutex_lock'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$__cxa_guard_acquire+0xe8): undefined reference to `__gthr_win32_recursive_mutex_unlock'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$__cxa_guard_acquire+0x12d): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$__cxa_guard_abort+0x21): undefined reference to `__gthr_win32_recursive_mutex_unlock'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$__cxa_guard_abort+0x5c): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$__cxa_guard_release+0x29): undefined reference to `__gthr_win32_recursive_mutex_unlock'
/mingw/lib/libstdc++.a(guard.o):guard.cc:(.text$__cxa_guard_release+0x64): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(c++locale.o):c++locale.cc:(.text$_ZSt14__convert_to_vIfEvPKcRT_RSt12_Ios_IostateRKPi+0x126): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(c++locale.o):c++locale.cc:(.text$_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKPi+0x129): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(c++locale.o):c++locale.cc:(.text$_ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKPi+0x151): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(iostream-inst.o):iostream-inst.cc:(.text$_ZNSdC2EPSt15basic_streambufIcSt11char_traitsIcEE[std::basic_iostream<char, std::char_traits<char> >::basic_iostream(std::basic_streambuf<char, std::char_traits<char> >*)]+0x9b): undefined reference to `_Unwind_Resume'
/mingw/lib/libstdc++.a(iostream-inst.o):iostream-inst.cc:(.text$_ZNSdC1EPSt15basic_streambufIcSt11char_traitsIcEE[std::basic_iostream<char, std::char_traits<char> >::basic_iostream(std::basic_streambuf<char, std::char_traits<char> >*)]+0xea): more undefined references to `_Unwind_Resume' follow
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1621 ms.
EDIT 2:
This has probably nothing to do with the above code, as all projects I compile seem fail with these errors (they compiled fine before).
EDIT 3:
SOLVED by deleting .metadata. Thanks anyway guys.
make sure you are compiling with g++, not gcc, AND make sure that the file extension is .cpp not .c
Furthermore, if you can edit your post and include the g++ command you are using, that would be a big help.
Are you consistently using the same g++ to compile and link?
You cleaned the project? Perhaps the previous .o files were built with another version of the libs.
Use g++ as the linker or link with -lstdc++
Related
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 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
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/.
Newbie question... I'm trying out Boost for the first time because I want to test drive the Boost Log library. I built this test program...
#include <boost/log/trivial.hpp>
#include <iostream>
int fibonacci(int num) {
int i;
int a = 1;
int b = 1;
for (i = 2; i <= num; ++i) {
BOOST_LOG_TRIVIAL(info) << "Iteration " << i << " (a = " << a << ", b = " << b << ")...";
b = a + b;
a = b - a;
}
return a;
}
int main() {
std::cout << "8th fibonacci number: " << fibonacci(8) << std::endl;
return 0;
}
Compile data:
**** Build of configuration Debug for project LoggingCpp ****
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -lpthread -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: LoggingCpp
Invoking: GCC C++ Linker
g++ -lpthread -o"LoggingCpp" ./main.o
./main.o: In function `~basic_logger':
/usr/include/boost/log/sources/basic_logger.hpp:90: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::~basic_attribute_set()'
./main.o: In function `boost::log_mt_posix::trivial::logger::construct_logger()':
/usr/include/boost/log/trivial.hpp:102: undefined reference to `boost::log_mt_posix::trivial::aux::init()'
./main.o: In function `void boost::call_once<void (*)()>(boost::once_flag&, void (*)())':
/usr/include/boost/thread/pthread/once.hpp:51: undefined reference to `boost::detail::get_once_per_thread_epoch()'
/usr/include/boost/thread/pthread/once.hpp:55: undefined reference to `boost::detail::once_epoch_mutex'
/usr/include/boost/thread/pthread/once.hpp:66: undefined reference to `boost::detail::once_epoch_mutex'
/usr/include/boost/thread/pthread/once.hpp:77: undefined reference to `boost::detail::once_global_epoch'
/usr/include/boost/thread/pthread/once.hpp:77: undefined reference to `boost::detail::once_global_epoch'
/usr/include/boost/thread/pthread/once.hpp:77: undefined reference to `boost::detail::once_global_epoch'
/usr/include/boost/thread/pthread/once.hpp:78: undefined reference to `boost::detail::once_epoch_cv'
/usr/include/boost/thread/pthread/once.hpp:84: undefined reference to `boost::detail::once_epoch_mutex'
/usr/include/boost/thread/pthread/once.hpp:84: undefined reference to `boost::detail::once_epoch_cv'
/usr/include/boost/thread/pthread/once.hpp:88: undefined reference to `boost::detail::once_global_epoch'
/usr/include/boost/thread/pthread/once.hpp:73: undefined reference to `boost::detail::once_epoch_cv'
./main.o: In function `record_pump':
/usr/include/boost/log/sources/record_ostream.hpp:293: undefined reference to `boost::log_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log_mt_posix::basic_record<char> const&)'
./main.o: In function `~auto_release':
/usr/include/boost/log/sources/record_ostream.hpp:280: undefined reference to `boost::log_mt_posix::aux::stream_provider<char>::release_compound(boost::log_mt_posix::aux::stream_provider<char>::stream_compound*)'
./main.o: In function `boost::log_mt_posix::sources::aux::logger_singleton<boost::log_mt_posix::trivial::logger>::init_instance()':
/usr/include/boost/log/sources/global_logger_storage.hpp:126: undefined reference to `boost::log_mt_posix::sources::aux::global_storage<char>::get_or_init(std::type_info const&, boost::function0<boost::shared_ptr<boost::log_mt_posix::sources::aux::logger_holder_base> > const&)'
/usr/include/boost/log/sources/global_logger_storage.hpp:147: undefined reference to `boost::log_mt_posix::odr_violation::throw_(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
./main.o: In function `boost::log_mt_posix::sources::aux::severity_level<boost::log_mt_posix::trivial::severity_level>::set_value(boost::log_mt_posix::trivial::severity_level)':
/usr/include/boost/log/sources/severity_feature.hpp:95: undefined reference to `boost::log_mt_posix::sources::aux::set_severity_level(int)'
./main.o: In function `boost::log_mt_posix::basic_record<char> boost::log_mt_posix::sources::basic_logger<char, boost::log_mt_posix::sources::severity_logger_mt<boost::log_mt_posix::trivial::severity_level>, boost::log_mt_posix::sources::multi_thread_model<boost::log_mt_posix::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_posix::keywords::tag::severity, boost::log_mt_posix::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log_mt_posix::keywords::tag::severity, boost::log_mt_posix::trivial::severity_level const> const&)':
/usr/include/boost/log/sources/basic_logger.hpp:269: undefined reference to `boost::log_mt_posix::basic_core<char>::open_record(boost::log_mt_posix::basic_attribute_set<char> const&)'
./main.o: In function `boost::log_mt_posix::sources::basic_logger<char, boost::log_mt_posix::sources::severity_logger_mt<boost::log_mt_posix::trivial::severity_level>, boost::log_mt_posix::sources::multi_thread_model<boost::log_mt_posix::aux::light_rw_mutex> >::push_record_unlocked(boost::log_mt_posix::basic_record<char> const&)':
/usr/include/boost/log/sources/basic_logger.hpp:280: undefined reference to `boost::log_mt_posix::basic_core<char>::push_record(boost::log_mt_posix::basic_record<char> const&)'
./main.o: In function `basic_logger<boost::parameter::aux::tagged_argument<boost::log_mt_posix::keywords::tag::severity, const boost::log_mt_posix::trivial::severity_level> >':
/usr/include/boost/log/sources/basic_logger.hpp:145: undefined reference to `boost::log_mt_posix::basic_core<char>::get()'
/usr/include/boost/log/sources/basic_logger.hpp:145: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::basic_attribute_set()'
./main.o: In function `~pair':
/usr/include/c++/4.5/bits/stl_pair.h:72: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()'
/usr/include/c++/4.5/bits/stl_pair.h:72: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()'
./main.o: In function `basic_logger':
/usr/include/boost/log/sources/basic_logger.hpp:135: undefined reference to `boost::log_mt_posix::basic_core<char>::get()'
/usr/include/boost/log/sources/basic_logger.hpp:135: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::basic_attribute_set(boost::log_mt_posix::basic_attribute_set<char> const&)'
./main.o: In function `boost::log_mt_posix::basic_attribute_set<char>::reference_proxy::operator=(boost::shared_ptr<boost::log_mt_posix::attribute> const&) const':
/usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::basic_slim_string(char const*, unsigned long)'
/usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::insert(boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> > const&, boost::shared_ptr<boost::log_mt_posix::attribute> const&)'
/usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()'
/usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()'
./main.o: In function `pair<std::basic_string<char>, boost::shared_ptr<boost::log_mt_posix::attribute> >':
/usr/include/c++/4.5/bits/stl_pair.h:116: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::basic_slim_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
./main.o: In function `boost::log_mt_posix::basic_attribute_set<char>::insert(std::pair<boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> > const, boost::shared_ptr<boost::log_mt_posix::attribute> > const&)':
/usr/include/boost/log/attributes/attribute_set.hpp:507: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::insert(boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> > const&, boost::shared_ptr<boost::log_mt_posix::attribute> const&)'
./main.o: In function `boost::log_mt_posix::sources::aux::severity_level<boost::log_mt_posix::trivial::severity_level>::dispatch(boost::log_mt_posix::type_dispatcher&)':
/usr/include/boost/log/sources/severity_feature.hpp:105: undefined reference to `boost::log_mt_posix::sources::aux::get_severity_level()'
./main.o: In function `boost::log_mt_posix::sources::aux::severity_level<boost::log_mt_posix::trivial::severity_level>::detach_from_thread()':
/usr/include/boost/log/sources/severity_feature.hpp:118: undefined reference to `boost::log_mt_posix::sources::aux::get_severity_level()'
collect2: ld returned 1 exit status
make: *** [LoggingCpp] Error 1
About Boost Log syntax
Did I install Boost Log incorrectly? Am I missing crucial libraries? Did I omit necessary linker flags?
You need to add something like -lboost-log-mt to your link line.
It looks like you haven't built log?
Once you've copied the log header files, etc into the corresponding folders in your boost distro (keep the same structure i.e. merge the headers to the headers, the libs folder into the libs folder of your boost distro, etc), you still need to build boost and then like John mentioned, link against it. That's why the link you referred to above points you to the standard boost build instructions.
It's a while ago, but AFAIR on linux you simply run ./bjam in the root of your boost folder.
Maybe switch unright version of the boost_log.
I have the same issue for undefined reference to "boost::log::v2_mt_posix::core::push_record_move(boost::log::v2_mt_posix::record&)"
I build the libboost_log by myself. And I use the nm to grep the push_record_move found that, "boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)"
From the experience of before, should add some cflag in the Makefile.