I used the python amalmagate file to compile the json library. Now when I run the c++ code, I keep getting this error.
/usr/bin/ld: msort.cc:(.text+0x255): undefined reference to Json::Value::~Value()' /usr/bin/ld: msort.cc:(.text+0x264): undefined reference to Json::Value::~Value()'
/usr/bin/ld: msort.cc:(.text+0x278): undefined reference to Json::Value::operator[](int)' /usr/bin/ld: msort.cc:(.text+0x28c): undefined reference to Json::Value::Value(char const*)'
/usr/bin/ld: msort.cc:(.text+0x2a7): undefined reference to `Json::Value::get(char const*, Json::Value const&) const'
This is what I used to download the jsoncpp library
git clone https://github.com/open-source-parsers/jsoncpp.git
cd jsoncpp
python amalgamate.py
The code I ran to compile: g++ msort.cc -o msort
I understand that this means that the library is not connecting with my code. Any idea how I can fix this?
If you read the instructions for the amalgamated library you will see that you need to build with the library source file dist/jsoncpp.cpp:
g++ msort.cc dist/jsoncpp.cpp -o msort
Related
I'm just making my way through finishing the boost http server project, which was written in visual studio using msvc compiler. All went well until I started porting this to linux. Here's a linking error displayed in console
http_server.cpp:(.text+0x995): undefined reference to `vtable for boost::detail::thread_data_base'
/usr/bin/ld: http_server.cpp:(.text+0xa05): undefined reference to `pthread_condattr_setclock'
/usr/bin/ld: http_server.cpp:(.text+0xb83): undefined reference to `boost::thread::start_thread_noexcept()'
/usr/bin/ld: http_server.cpp:(.text+0xc69): undefined reference to `boost::thread::native_handle()'
/usr/bin/ld: http_server.cpp:(.text+0xc82): undefined reference to `boost::thread::join_noexcept()'
/usr/bin/ld: /tmp/ccFIQ0RA.o: in function `boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_context>, boost::_bi::list1<boost::_bi::value<boost::asio::io_context*> > > >::~thread_data()':
Here's my Makefile
STANDARD = c++11
LIBPATH=/usr/lib/x86_64-linux-gnu
LINUX_THREAD=-lpthread
BOOST_THREAD=/usr/lib/x86_64-linux-gnu/libboost_thread.a
OUTPUT=cppserver
build_gcc:
g++ -O2 -std=$(STANDARD) $(LINUX_THREAD) -o $(OUTPUT) CppServer/servers/http_server/http_server.cpp ;\
CppServer/servers/http_server/connection.cpp CppServer/core/app.cpp CppServer/core/dbconn.cpp ;\
CppServer/servers/http_server/response.cpp CppServer/servers/http_server/request.cpp ;\
CppServer/math_unit.cpp CppServer/main.cpp $(BOOST_THREAD) -L$(LIBPATH)
I also tried to set BOOST_THREAD to 'boost_thread', but it failed as well.
Any ideas?
a C++ code built into a shared library for HELib is using NTL and GMP static library. But it gets following error:
/usr/bin/ld: /usr/local/lib/libntl.a(FFT.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libntl.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
It was suggested int the post Click here
to recompile NTL and GMP with "-fPIC " flags.
I'am not able to find how I should do that.
Edit:
I'm able to build the shared library now after :
recompiling GMP and NTL by:
./configure --enable-shared
for gmp and
./configure SHARED=on
After make Install of HELib. I get error when I run the example codes.
The link to the Makefile : click to see makefile
Error:
g++ -g -O2 -std=c++11 -pthread -DFHE_THREADS -DFHE_BOOT_THREADS -DFHE_DCRT_THREADS -o Test_General_x Test_General.cpp -L/usr/local/lib -lntl -lgmp -lm -lfhe
/usr/local/lib/libfhe.so: undefined reference to write_raw_int(std::ostream&, long, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_ZZ(std::istream&, NTL::ZZ&)'
/usr/local/lib/libfhe.so: undefined reference to void write_raw_vector<long>(std::ostream&, std::vector<long, std::allocator<long> > const&)'
/usr/local/lib/libfhe.so: undefined reference towriteEyeCatcher(std::ostream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_xdouble(std::ostream&, NTL::xdouble)'
/usr/local/lib/libfhe.so: undefined reference toread_ntl_vec_long(std::istream&, NTL::Vec&)'
/usr/local/lib/libfhe.so: undefined reference to void read_raw_vector<long>(std::istream&, std::vector<long, std::allocator<long> >&)'
/usr/local/lib/libfhe.so: undefined reference toreadEyeCatcher(std::istream&, char const*)'
/usr/local/lib/libfhe.so: undefined reference to read_raw_int(std::istream&, long)'
/usr/local/lib/libfhe.so: undefined reference toread_raw_xdouble(std::istream&)'
/usr/local/lib/libfhe.so: undefined reference to write_raw_ZZ(std::ostream&, NTL::ZZ const&)'
/usr/local/lib/libfhe.so: undefined reference towrite_ntl_vec_long(std::ostream&, NTL::Vec const&, long)'
collect2: error: ld returned 1 exit status
Makefile:179: recipe for target 'Test_General_x' failed
make: *** [Test_General_x] Error 1
For NTL v11.5.1 atleast, doing ./configure --help | grep -i pic (as suggested in one of the comments for GMP) did not help at all - it found no matches. However, making a one line change in the file ntl-11.5.1/src/DoConfig (on line 17) from:
'CXXFLAGS' => '-g -O2'
to:
'CXXFLAGS' => '-g -O2 -fPIC',
solved the problem for me.
Marc Glisse provided the answer for the first two parts of the question.For the third part "Undefined Reference error" the answer is I'd not compiled and linked a x.cpp containing the functions that caused the undefined reference into my shared library. hence check : nm -CD /usr/local/lib/libfhe.so to see if these functions are listed with a linking address or not. If not then check which code provides this functionality. Link that code to the shared library.
I am trying to establish database connection using sqlpp-connector-mysql. After building this project when i am trying to run SampleTest.cpp it produce error saying
$ g++ -std=c++1y -lsqlpp-mysql SampleTest.cpp
SampleTest.cpp:(.text+0x12f): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)'
SampleTest.cpp:(.text+0x13e): undefined reference to `sqlpp::mysql::connection::~connection()'
SampleTest.cpp:(.text+0x157): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)'
SampleTest.cpp:(.text+0x19d): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'
SampleTest.cpp:(.text+0x201): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'
SampleTest.cpp:(.text+0x265): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'
SampleTest.cpp:(.text+0x2c9): undefined reference to `sqlpp::mysql::connection::execute(std::string const&)'
I think, sqlpp-mysql is not linking properly. Can someone give me some pointer, how to resolve this problem ?
P.S : I have build the requirements.
sqlpp11
date library
I build the both sqlpp11 and sqlpp11-connector-mysql like this
$ cd project_dir
$ cmake CmakeList.txt
$ sudo make install
I needed to link the library properly.
g++ -std=c++11 tests/SampleTest.cpp -I ../../sqlpp11/include -I . -I ../../date -lsqlpp-mysql -lmysqlclient
My cpp file has Scilab and Octave header files. I'm trying to compile using this command
g++ -l:/usr/lib/scilab/libscilab.so -L/usr/lib/scilab -L/usr/lib/scilab -I/usr/include/octave-3.8.1 -I/usr/include/octave-3.8.1/octave -I/usr/include/scilab s_o_test_v4.cpp -o s_o_test_v4
I get the following error
s_o_test_v4.cpp:(.text+0x5f4): undefined reference to `pvApiCtx'
s_o_test_v4.cpp:(.text+0x5ff): undefined reference to `isVarMatrixType'
s_o_test_v4.cpp:(.text+0x61a): undefined reference to `pvApiCtx'
s_o_test_v4.cpp:(.text+0x644): undefined reference to `getMatrixOfDouble'
s_o_test_v4.cpp:(.text+0x743): undefined reference to `string_vector::c_str_vec() const'
s_o_test_v4.cpp:(.text+0x755): undefined reference to `octave_main'
s_o_test_v4.cpp:(.text+0x7a2): undefined reference to `octave_value::octave_value(double)'
s_o_test_v4.cpp:(.text+0x847): undefined reference to `feval(std::string const&, octave_value_list const&, int)'
s_o_test_v4.cpp:(.text+0x8a3): undefined reference to `pvApiCtx'
Both Scilab and Octave functions show error. Should I include or remove something from my compile command?
Maybe the ordering of your make command is wrong, see also
this SO question:
Please also note that libraries need to be specified on the command
line after the files needing them
That would make your command:
g++ -I/usr/include/octave-3.8.1 -I/usr/include/octave-3.8.1/octave -I/usr/include/scilab s_o_test_v4.cpp -o s_o_test_v4 -l:/usr/lib/scilab/libscilab.so -L/usr/lib/scilab -L/usr/lib/scilab
a test file named ml.cc, I have already installed the mathgl headers to /usr/local/include and libmgl.a to /usr/local/lib
#include <mgl2/mgl.h>
int main()
{
mglGraph gr;
gr.FPlot("sin(pi*x)");
gr.WriteFrame("test.png");
return 0;
}
"g++ -c ml.cc" can work,but "g++ ml.cc" does not work,the error is
/tmp/ccPzPcZt.o: In function `mglGraph::mglGraph(int, int, int)':
ml.cc:(.text._ZN8mglGraphC2Eiii[_ZN8mglGraphC5Eiii]+0x3b): undefined reference to `mgl_create_graph_gl'
ml.cc:(.text._ZN8mglGraphC2Eiii[_ZN8mglGraphC5Eiii]+0x54): undefined reference to `mgl_create_graph'
/tmp/ccPzPcZt.o: In function `mglGraph::~mglGraph()':
ml.cc:(.text._ZN8mglGraphD2Ev[_ZN8mglGraphD5Ev]+0x28): undefined reference to `mgl_use_graph'
ml.cc:(.text._ZN8mglGraphD2Ev[_ZN8mglGraphD5Ev]+0x42): undefined reference to `mgl_delete_graph'
/tmp/ccPzPcZt.o: In function `mglGraph::SetFontSize(double)':
ml.cc:(.text._ZN8mglGraph11SetFontSizeEd[_ZN8mglGraph11SetFontSizeEd]+0x2a): undefined reference to `mgl_set_font_size'
/tmp/ccPzPcZt.o: In function `mglGraph::WriteFrame(char const*, char const*)':
ml.cc:(.text._ZN8mglGraph10WriteFrameEPKcS1_[_ZN8mglGraph10WriteFrameEPKcS1_]+0x2b): undefined reference to `mgl_write_frame'
/tmp/ccPzPcZt.o: In function `mglGraph::FPlot(char const*, char const*, char const*)':
ml.cc:(.text._ZN8mglGraph5FPlotEPKcS1_S1_[_ZN8mglGraph5FPlotEPKcS1_S1_]+0x30): undefined reference to `mgl_fplot'
collect2: error: ld returned 1 exit status
"g++ -L /usr/local/lib/ -l mgl ml.o" is the same error
I encoutered exactly the same problem and managed to solve it.
If you did the installation properly as you said. Then you simply need to add -lmgl AT THE END of the line! Like this:
g++ ml.o -lmgl
As luke already had mentioned, you have a linking error, thus compiling is not affected. Here is an explanation for this behaviour:
undefined reference to symbol even when nm indicates that this symbol is present in the shared library
Hope this solved your problem.
Peter
You have a linking error. To solve this you need to link against mgl. It looks like you are trying to, but its not working.
First, I would drop the space between the l and the mgl. so
g++ -L /usr/local/lib/ -lmgl ml.o
If that doesn't work, check to see if there are any other libraries you need to link against. See if g++ is throwing errors that it cannot find mgl.
Hope that helps.