/usr/bin/ld: /tmp/cc9zxSDP.o: undefined reference to symbol - c++

The following compile error i am facing when i compile a .cc file. i am using apache ignite libraries and c++ libraries to compile and jdk path is specified.
#include <iostream>
#include "ignite/ignite.h"
#include "ignite/ignition.h"
using namespace ignite;
using namespace cache;
int main()
{
IgniteConfiguration cfg;
cfg.jvmInitMem = 512;
cfg.jvmMaxMem = 512;
cfg.springCfgPath = "/home/ignite/DataGridTest.xml";
try
{
Ignite grid = Ignition::Start(cfg);
std::cout << std::endl;
std::cout << ">>> Cache put-get example started." << std::endl;
std::cout << std::endl;
Cache<int, int> cache = grid.GetCache<int, int>("mycache");
cache.Clear();
cache.Put(1, 1);
int orgFromCache = cache.Get(1);
std::cout << ">>> Retrieved value from cache: " << std::endl;
std::cout << orgFromCache << std::endl;
std::cout << std::endl;
Ignition::StopAll(false);
}
catch (IgniteError& err)
{
std::cout << "An error occurred: " << err.GetText() << std::endl;
}
std::cout << std::endl;
std::cout << ">>> Example finished, press 'Enter' to exit ..." << std::endl;
std::cout << std::endl;
return 0;
}
In command line:
gcc -I /usr/java/jdk1.8.0_131/include/ -I
/usr/java/jdk1.8.0_131/include/linux/ -I
$IGNITE_HOME/platforms/cpp/jni/include/ -I
$IGNITE_HOME/platforms/cpp/core/include/ -I
$IGNITE_HOME/platforms/cpp/common/os/linux/include/ -I
$IGNITE_HOME/platforms/cpp/examples/include/ DataGridTest.cc -o DataGridTest -lignite
/usr/bin/ld: /tmp/cc9zxSDP.o: undefined reference to symbol '_ZN6ignite3jni4java12JniErrorInfoD1Ev'
/usr/local/lib//libignite-jni-2.0.0.19668.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Except for the libignite you also need to link to libignite-binary, libignite-common and libignite-jni.

Related

What causes the following linking error with the boost c++ libraries?

Hi I get a linking error when compiling my program with the gcc compiler on cygwin. The first picture is a simple sample program from the boost filesystem libraries tutorial page where I have included filesystem.hpp in the boost folder. Beneath that is the picture of my linker error when I try to compile with the following command:
g++ -I C:/Users/Ejer/Desktop/c++Dep/boost_1_77_0 -I C:/Users/Ejer/Desktop/c++Dep/eigen-3.4.0 -L C:/Users/Ejer/Desktop/c++Dep/boost_1_77_0/stage/lib test.cpp -o ser
Here I try to compile my program test.cpp with the eigen and boost libraries and set the includer path that they tell me to set as the path after I have built the library with b2.exe. I have also linked to the lib files for boost. I have also tried linking to the different filesystem lib files specifically. Thanks in advance
#include <iostream>
#include <boost/filesystem.hpp>
using std::cout;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: tut3 path\n";
return 1;
}
path p (argv[1]);
try
{
if (exists(p))
{
if (is_regular_file(p))
cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
for (directory_entry& x : directory_iterator(p))
cout << " " << x.path() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
}
else
cout << p << " does not exist\n";
}
catch (const filesystem_error& ex)
{
cout << ex.what() << '\n';
}
return 0;
}
I get a linking error when compiling my program
No, you don't. You are getting a linking error when linking your program, not when compiling it.
The reason: you didn't supply the library (-L C:/Users/.... tells the linker where to search for libraries; not which libraries to link). Your command line should look something like:
g++ -I ... -L ... test1.cpp -o ser -lboost_filesystem

std::system_error occurs at Protobuf ParseFromZeroCopyStream()

I'm testing protobuf with zlib compression.
I wrote some c++ sample code using protobuf 3.8.0, but the following error occurred at calling ParseFromZeroCopyStream() at Ubuntu.
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
(core dumped)
what can I do?
I tried to replace ParseFromZeroCopyStream() with ParseFromBoundedZeroCopyStream().
That results in no core dump, but ParseFromBoundedZeroCopyStream() returned false.
test.proto
syntax = "proto2";
package test;
message Msg
{
required uint32 data = 1;
}
test.cc
#include <iostream>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/io/gzip_stream.h>
#include "test.pb.h"
using namespace std;
using namespace google::protobuf;
using namespace test;
int main(void)
{
Msg srcMsg;
srcMsg.set_data(1);
long sSize = srcMsg.ByteSizeLong();
cout << "SerializedSize = " << sSize << endl;
char * compressedMsg = new char[sSize];
io::ArrayOutputStream aos(compressedMsg, sSize);
io::GzipOutputStream gos(&aos);
long cSize;
if (srcMsg.SerializeToZeroCopyStream(&gos) == true)
{
gos.Close();
cSize = aos.ByteCount();
cout << "compression success : " << cSize << " bytes" << endl;
}
else
{
cout << "compression error" << endl;
return 1;
}
Msg targetMsg;
io::ArrayInputStream ais(compressedMsg, cSize);
io::GzipInputStream gis(&ais);
if (targetMsg.ParseFromZeroCopyStream(&gis) == false)
{
cout << "decompression error" << endl;
}
else
{
cout << "decompression success : " << targetMsg.ByteSizeLong() << " bytes" << endl;
cout << "data = " << targetMsg.data() << endl;
}
delete[] compressedMsg;
return 0;
}
I expect that decompression succeeds.
You will need to learn to use a debugger to investigate further why exactly this "unknown error: -1" is thrown - if possible.
That being said, unknown library errors is sometimes caused by a failed memory allocation or in rarer cases some other ressource constraint like failing to start a thread/process, etc.

Linker error with simple threaded program (symbols from boost_chrono missing)

I'm learning boost::timed_mutex
The follwing code cannot be compiled:
#include <boost/thread.hpp>
#include <boost/chrono.hpp>
#include <iostream>
void wait(int seconds)
{
boost::this_thread::sleep_for(boost::chrono::seconds{seconds});
}
boost::timed_mutex mutex;
void thread1()
{
using boost::this_thread::get_id;
for (int i = 0; i < 5; ++i)
{
wait(1);
boost::unique_lock<boost::timed_mutex> lock{mutex};
std::cout << "Thread " << get_id() << ": " << i << std::endl;
boost::timed_mutex *m = lock.release();
m->unlock();
}
}
void thread2()
{
using boost::this_thread::get_id;
for (int i = 0; i < 5; ++i)
{
wait(1);
boost::unique_lock<boost::timed_mutex> lock{mutex,
boost::try_to_lock};
if (lock.owns_lock() || lock.try_lock_for(boost::chrono::seconds{1}))
{
std::cout << "Thread " << get_id() << ": " << i << std::endl;
}
}
}
int main()
{
boost::thread t1{thread1};
boost::thread t2{thread2};
t1.join();
t2.join();
}
My compile command is:
g++ -std=c++11 unique_lock.cpp -o unique_lock -g -lboost_system -lboost_thread-mt -pthread -lboost_timer
The error is something like the following:
/bin/ld: /tmp/ccRVKHNh.o: undefined reference to symbol '_ZN5boost6chrono12system_clock3nowEv'
/usr/lib64/libboost_chrono.so.1.53.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
What's wrong?
Apparently -lboost_chrono is missing.
Demo

How do you disconnect from a boost signal2 using a functor to a method of a class?

I am not getting the behavior I am expecting when disconnecting a slot (that is a class method) from from a boost::signals2. My terminology is probably off, so I will provide a minimal working example (MWE) below demonstrating what I see and what I expect. The short version is that I am disconnecting from the signal, but it is staying there. Everything works great if I do this with a stand-alone function, it is when I use a class method that I run into this behavior.
Any help would be greatly appreciated!
>> tree
.
├── main.cpp
└── SConstruct
0 directories, 2 files
>> cat SConstruct
Program('main.cpp')
>> cat main.cpp
#include <boost/signals2.hpp>
#include <iostream>
struct foo {
void bar(int n) {
std::cout << "Called foo::bar with " << n << std::endl;
}
};
typedef boost::function<void(int)> Signal_f;
int main() {
foo f;
boost::signals2::signal< void(int) > my_signal;
Signal_f functor = boost::bind(&foo::bar, f, _1);
std::cout << "Created signal, and it has "
<< my_signal.num_slots() << " subscribers." << std::endl;
my_signal.connect(functor);
std::cout << "Subscribed to signal, and it has "
<< my_signal.num_slots() << " subsciber." << std::endl;
my_signal(1);
my_signal.disconnect(&functor);
std::cout << "Un-Subscribed to signal, but it still has "
<< my_signal.num_slots()
<< " subsciber, and it should not have any now." << std::endl;
my_signal(2);
return 0;
}
>> scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o main.o -c main.cpp
g++ -o main main.o
scons: done building targets.
>> ./main
Created signal, and it has 0 subscribers.
Subscribed to signal, and it has 1 subsciber.
Called foo::bar with 1
Un-Subscribed to signal, but it still has 1 subsciber, and it should not have any now.
Called foo::bar with 2
re-implementing using scoped_connection:
#include <boost/signals2.hpp>
#include <iostream>
struct foo {
void bar(int n) {
std::cout << "Called foo::bar with " << n << std::endl;
}
};
typedef boost::function<void(int)> Signal_f;
int main() {
using boost::signals2::scoped_connection;
foo f;
boost::signals2::signal< void(int) > my_signal;
Signal_f functor = boost::bind(&foo::bar, f, _1);
std::cout << "Created signal, and it has "
<< my_signal.num_slots() << " subscribers." << std::endl;
// the scoped_connection object is RAII
auto con = scoped_connection(my_signal.connect(functor));
std::cout << "Subscribed to signal, and it has "
<< my_signal.num_slots() << " subsciber." << std::endl;
my_signal(1);
// disconnect the connection object, not the signal
con.disconnect();
std::cout << "Un-Subscribed to signal, and it now has "
<< my_signal.num_slots()
<< " subscibers." << std::endl;
my_signal(2);
return 0;
}
expected output:
Created signal, and it has 0 subscribers.
Subscribed to signal, and it has 1 subsciber.
Called foo::bar with 1
Un-Subscribed to signal, and it still has 0 subscibers.
I do disconnect from a boost::signal2::signal using boost::signals2::connection object returned by connect method.

undefined reference to `_gmtime32' with boost threads tutorial

I was following this beginner tutorial on boost threads:
http://www.codeproject.com/Articles/279053/How-to-get-started-using-Boost-threads
Everything was going fine with this sample they provided:
#define BOOST_THREAD_USE_LIB
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
void workerFunc()
{
boost::posix_time::seconds workTime(3);
std::cout << "Worker: running" << std::endl;
// Pretend to do something useful...
boost::this_thread::sleep(workTime);
std::cout << "Worker: finished" << std::endl;
}
int main(int argc, char* argv[])
{
std::cout << "main: startup" << std::endl;
boost::thread workerThread(workerFunc);
std::cout << "main: waiting for thread" << std::endl;
workerThread.join();
std::cout << "main: done" << std::endl;
return 0;
}
But then I decided to try it without the sleep function. So I commented out those lines.
#define BOOST_THREAD_USE_LIB
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
void workerFunc()
{
//boost::posix_time::seconds workTime(3);
std::cout << "Worker: running" << std::endl;
// Pretend to do something useful...
//boost::this_thread::sleep(workTime);
std::cout << "Worker: finished" << std::endl;
}
int main(int argc, char* argv[])
{
std::cout << "main: startup" << std::endl;
boost::thread workerThread(workerFunc);
std::cout << "main: waiting for thread" << std::endl;
workerThread.join();
std::cout << "main: done" << std::endl;
return 0;
}
I started to get the following compile error:
)]+0x40)||undefined reference to `_gmtime32'|
I've done quite a bit of snooping around trying to figure out what this means and why it is only happening when I remove those two lines. As of right now, I am leaning towards it being something to do with some kind of header, like time.h, that I have to include (although I tried that already obviously).
I am using a rather strange setup. Code::Blocks with mingw/gcc. I compiled the boost library myself with command line arguments following the codeblocks tutorial:
http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef
Everything seemed to work fine with this, but I suppose I could have built the libraries incorrectly.
I would dig deeper but the file name of the error is not standard and is listed as ")]+0x40)". I am not sure what this means - is it maybe some kind of file location address?
MORE INFO:
Windows XP 32 bit
CodeBlocks 10.05
MingW GCC 4.4.3
Boost 1_53_0
BUILD LOG:
Linking console executable: bin\Debug\Bjarne_Strousup_Samples.exe
....\CodeBlocks\lib\libboost_thread-mgw44-mt-1_53.a(thread.o):thread.cpp:(.text$_ZN5boost9date_time6c_time6gmtimeEPKlP2tm[boost::date_time::c_time::gmtime(long
const*, tm*)]+0x40): undefined reference to `_gmtime32' collect2: ld
returned 1 exit status Process terminated with status 1 (0 minutes, 6
seconds) 1 errors, 0 warnings
COMMAND LINE ATTEMPT:
C:\CodeBlocks Tests\BoostExamples>g++ main.cpp -lboost_thread -lboost_system -lb
oost_chrono
main.cpp:5:28: error: boost/thread.hpp: No such file or directory
main.cpp:6:31: error: boost/date_time.hpp: No such file or directory
main.cpp: In function 'int main()':
main.cpp:21: error: 'boost' has not been declared
main.cpp:21: error: expected ';' before 'workerThread'
main.cpp:24: error: 'workerThread' was not declared in this scope
C:\CodeBlocks Tests\BoostExamples>
LINKER SETTINGS:
IDM Link:
http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.basetechref%2Fdoc%2Fbasetrf1%2Fctime.htm
I think the error is on this line of c_time.hpp:
static std::tm* gmtime(const std::time_t* t, std::tm* result)