Error when trying to use NTL vector - c++

I am trying to use NTL::Vec, but I get this error whenever I want to use SetLength()
The c++ code:
#include <NTL/ZZ.h>
#include <NTL/vector.h>
int main(int argc, const char * argv[]) {
NTL::Vec<NTL::ZZ> v;
v.SetLength(8);
return 0;
}
The error message:
/usr/include/NTL/ZZ.h:78: undefined reference to `_ntl_gfree(void**)'
./main.o: In function `NTL::Vec<NTL::ZZ>::AllocateTo(long)':
/usr/include/NTL/vector.h:334: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:337: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:343: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:354: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:369: undefined reference to `NTL::Error(char const*)'
collect2: error: ld returned 1 exit status
If I don't use v.SetLength(8), I don't get an error and everything is fine. What could be the problem ?
Thank you in advance

Related

undefined reference to `__dynamic_cast' when using sanitize=vptr

I build vfptr.cpp with fsanitize=vptr to an static file.
It has errors messages about "undefined reference to __dynamic_cast".
Both g++7.4.0 and g++11.0.0 have the problem. Is it reasonable for using sanitizer=vptr?
vptr.cpp
struct A {
virtual ~A() {};
};
int main() { A a; }
compiled option
g++ vptr.C -fsanitize=vptr -static
error message:
/usr/lib/gcc/x86_64-linux-gnu/7/libubsan.a(ubsan_type_hash_itanium.o): In function `isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long)':
(.text+0x52): undefined reference to `__dynamic_cast'
(.text+0x5e): undefined reference to `typeinfo for __cxxabiv1::__vmi_class_type_info'
(.text+0x6b): undefined reference to `__dynamic_cast'
/usr/lib/gcc/x86_64-linux-gnu/7/libubsan.a(ubsan_type_hash_itanium.o): In function `findBaseAtOffset(__cxxabiv1::__class_type_info const*, long)':
(.text+0x151): undefined reference to `__dynamic_cast'
(.text+0x15d): undefined reference to `typeinfo for __cxxabiv1::__vmi_class_type_info'
(.text+0x16a): undefined reference to `__dynamic_cast'
/usr/lib/gcc/x86_64-linux-gnu/7/libubsan.a(ubsan_type_hash_itanium.o): In function `__ubsan::checkDynamicType(void*, void*, unsigned long)':
(.text+0x293): undefined reference to `__dynamic_cast'
collect2: error: ld returned 1 exit status

undefined reference error in g++

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.

How to Compile ZBar examples? (undefined reference...)

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

C++ MsgPack: linker errors

I'm trying to compile the message pack (http://msgpack.org/) example code and keep getting these errors which I can't get to the bottom of:
g++ -o"MsgPack2" ./src/MsgPack2.o -lmsgpack -lmsgpackc
./src/MsgPack2.o: In function `main':
/mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:38:
undefined reference to msgpack::rpc::server::listen(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&, unsigned
short)'
./src/MsgPack2.o: In functionloop':
/usr/local/include/msgpack/rpc/loop.h:30: undefined reference to
mp::wavy::loop::loop()'
./src/MsgPack2.o: In functionbase':
/usr/local/include/msgpack/rpc/server.h:59: undefined reference to
msgpack::rpc::server::server(msgpack::rpc::loop)'
/usr/local/include/msgpack/rpc/server.h:59: undefined reference to
msgpack::rpc::server::serve(msgpack::rpc::dispatcher*)'
/usr/local/include/msgpack/rpc/server.h:59: undefined reference to
msgpack::rpc::server::~server()'
./src/MsgPack2.o: In function~base':
/usr/local/include/msgpack/rpc/server.h:64: undefined reference to
msgpack::rpc::server::~server()'
./src/MsgPack2.o: In function
myserver::dispatch(msgpack::rpc::request)':
/mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:14:
undefined reference to msgpack::rpc::request::method()'
/mnt/eoh/workspace/MsgPack2/Debug/../src/MsgPack2.cpp:18:
undefined reference tomsgpack::rpc::request::params()'
./src/MsgPack2.o: In function
msgpack::rpc::loop_util<msgpack::rpc::session_pool>::run(unsigned
long)':
/usr/local/include/msgpack/rpc/loop_util.h:34: undefined reference
tomsgpack::rpc::session_pool::get_loop()'
/usr/local/include/msgpack/rpc/loop_util.h:34: undefined reference
to mp::wavy::loop::run(unsigned long)'
./src/MsgPack2.o: In functionvoid
msgpack::rpc::request::call(int&,
msgpack::type::nil&)':
/usr/local/include/msgpack/rpc/request.h:119: undefined reference
to msgpack::rpc::request::is_sent() const'
/usr/local/include/msgpack/rpc/request.h:122: undefined reference
tomsgpack::rpc::request::get_msgid() const'
/usr/local/include/msgpack/rpc/request.h:125: undefined reference
to msgpack::rpc::request::send_data(msgpack::sbuffer*)'
./src/MsgPack2.o: In functionvoid
msgpack::rpc::request::call(msgpack::type::nil&, unsigned char&)':
/usr/local/include/msgpack/rpc/request.h:119: undefined reference
to msgpack::rpc::request::is_sent() const'
/usr/local/include/msgpack/rpc/request.h:122: undefined reference
tomsgpack::rpc::request::get_msgid() const'
/usr/local/include/msgpack/rpc/request.h:125: undefined reference
to msgpack::rpc::request::send_data(msgpack::sbuffer*)'
./src/MsgPack2.o: In functionvoid
msgpack::rpc::request::call, std::allocator >
(msgpack::type::nil&, std::basic_string,
std::allocator >&)':
/usr/local/include/msgpack/rpc/request.h:119: undefined reference
to msgpack::rpc::request::is_sent() const'
/usr/local/include/msgpack/rpc/request.h:122: undefined reference
tomsgpack::rpc::request::get_msgid() const'
/usr/local/include/msgpack/rpc/request.h:125: undefined reference
to msgpack::rpc::request::send_data(msgpack::sbuffer*)'
./src/MsgPack2.o: In function__shared_count':
/usr/include/c++/4.5/tr1/shared_ptr.h:121: undefined reference to
mp::wavy::loop::~loop()'
./src/MsgPack2.o: In function
std::tr1::_Sp_deleter::operator()(mp::wavy::loop*)
const':
/usr/include/c++/4.5/tr1/shared_ptr.h:99: undefined reference to
`mp::wavy::loop::~loop()'
collect2: ld returned 1 exit status
make: * [MsgPack2] Error 1
And here is the code:
#include <msgpack/rpc/server.h>
class myserver : public msgpack::rpc::server::base {
public:
void add(msgpack::rpc::request req, int a1, int a2)
{
req.result(a1 + a2);
}
public:
void dispatch(msgpack::rpc::request req)
try {
std::string method;
req.method().convert(&method);
if(method == "add") {
msgpack::type::tuple<int, int> params;
req.params().convert(&params);
add(req, params.get<0>(), params.get<1>());
} else {
req.error(msgpack::rpc::NO_METHOD_ERROR);
}
} catch (msgpack::type_error& e) {
req.error(msgpack::rpc::ARGUMENT_ERROR);
return;
} catch (std::exception& e) {
req.error(std::string(e.what()));
return;
}
};
int main(void)
{
myserver svr;
svr.instance.listen("127.0.0.1", 80800);
svr.instance.run(4); // run 4 threads
return 0;
}
If anyone has any ideas, it would be greatly appreciated.
Many thanks in advance,
You need -lmsgpack-rpc.
[Side note: 80800 is not a valid port.]

How can I query Informix database using C++ on Linux? Getting compiler errors when using Object Interface for C++

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/.