Undefined reference error C++ in example program - c++

I'm trying to run some example code from this repository
When going to the example folder (/binacpp/example) and run i.e.
./example.run.sh
It works.
However when I update the file (even with just an extra space in a comment) and try to recompile the program by typing:
make example
Then I get this error:
Making example
g++ -I../lib/libcurl-7.56.0/include -I../lib/jsoncpp-1.8.3/include -I../lib/libwebsockets-2.4.0/include -I../lib/libbinacpp/include \
example.cpp \
-L../lib/libcurl-7.56.0/lib \
-L../lib/libwebsockets-2.4.0/lib \
-L../lib/libbinacpp/lib \
-lcurl -lcrypto -lwebsockets -lbinacpp -o example
/tmp/ccCycCcN.o: In function `ws_depth_onData(Json::Value&)':
example.cpp:(.text+0xd85): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0xdf0): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0xf79): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0xfe4): undefined reference to `Json::Value::asString[abi:cxx11]() const'
/tmp/ccCycCcN.o: In function `ws_klines_onData(Json::Value&)':
example.cpp:(.text+0x1255): undefined reference to `Json::Value::asString[abi:cxx11]() const'
/tmp/ccCycCcN.o:example.cpp:(.text+0x1317): more undefined references to `Json::Value::asString[abi:cxx11]() const' follow
/tmp/ccCycCcN.o: In function `main':
example.cpp:(.text+0x22c4): undefined reference to `BinaCPP::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
example.cpp:(.text+0x242d): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x24aa): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x25e5): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x2659): undefined reference to `Json::Value::asString[abi:cxx11]() const'
example.cpp:(.text+0x27d2): undefined reference to `Json::Value::asString[abi:cxx11]() const'
/tmp/ccCycCcN.o:example.cpp:(.text+0x28a2): more undefined references to `Json::Value::asString[abi:cxx11]() const' follow
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target 'example' failed
make: *** [example] Error 1
I looked this error up and I'm guessing this is a linker error like described in this post. However I'm coming from Python and new to C++ and just don't see what is wrong. I see that the .h files are included and in
binacpp_websocket.h
I see
typedef int (*CB)(Json::Value &json_value );
Why am I getting the error?
NOTE: When trying to run the command "make example" I got the error:
Making example
g++ -I../lib/libcurl-7.56.0/include -I../lib/jsoncpp-1.8.3/include -I../lib/libwebsockets-2.4.0/include -I../lib/libbinacpp/include \
example.cpp \
-L../lib/libcurl-7.56.0/lib \
-L../lib/libwebsockets-2.4.0/lib \
-L../lib/libbinacpp/lib \
-lcurl -ljsoncpp -lcrypto -lwebsockets -lbinacpp -o example
/usr/bin/ld: cannot find -ljsoncpp
collect2: error: ld returned 1 exit status
Makefile:25: recipe for target 'example' failed
make: *** [example] Error 1
Somewhere in the repo (I cannot find it now) it said that "-ljsoncpp" shouldn't be there. After removing this the compiler did run but it gave the linker error.

Related

Undefined reference using the mysql c++ connector

I'm trying to use the mySQL c++ connector.
I have downloaded and extracted the binaries following the mysql guide https://dev.mysql.com/doc/connector-cpp/8.0/en/connector-cpp-installation-binary.html
When i include the xdevapi like so
#include <mysqlx/xdevapi.h>
I get the following errors
/tmp/cc6dzD4k.o: In function `mysqlx::string::operator std::__cxx11::basic_string, std::allocator >abi:cxx11 const':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/common.h:115: undefined reference to `mysqlx::string::Impl::to_utf8[abi:cxx11](mysqlx::string const&)'
/tmp/cc6dzD4k.o: In function `mysqlx::DbDoc::DbDoc()':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/document.h:153: undefined reference to `vtable for mysqlx::DbDoc'
/tmp/cc6dzD4k.o: In function mysqlx::DbDoc::~DbDoc()':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/document.h:127: undefined reference tovtable for mysqlx::DbDoc'
/tmp/cc6dzD4k.o: In function mysqlx::Value::print(std::ostream&) const':
/git_repos/FHM/Camera/Software/ExtractMetadata/Build/Linux/../../../mysql-connector-c++-8.0.13/include/mysqlx/devapi/document.h:507: undefined reference tomysqlx::common::Value::print(std::ostream&) const'
/tmp/cc6dzD4k.o:(.rodata._ZTCN6mysqlx5ValueE0_NS_6common5ValueE[_ZTVN6mysqlx5ValueE]+0x18): undefined reference to typeinfo for mysqlx::common::Value'
/tmp/cc6dzD4k.o:(.rodata._ZTCN6mysqlx5ValueE0_NS_6common5ValueE[_ZTVN6mysqlx5ValueE]+0x20): undefined reference tomysqlx::common::Value::print(std::ostream&) const'
/tmp/cc6dzD4k.o:(.rodata._ZTIN6mysqlx5ValueE[_ZTIN6mysqlx5ValueE]+0x28): undefined reference to `typeinfo for mysqlx::common::Value'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'x86' failed
make: *** [x86] Error 1
My Makefile look like this:
g++ -I../../Src -I../../../Fee/Src \
-I/../../../OpenCV/include/opencv \
-I../../../OpenCV/include/opencv2 \
-I../../../mysql-connector-c++-8.0.13/include/ \
-L../../../OpenCV/lib/LinX86 \
-L../../../mysql-connector-c++-8.0.13/lib64/libmysqlcppconn8-static.a -lssl -lcrypto -lpthread \
-g -D LINUX -o extractmetadata ../../Src/extractMetadata.cpp ../../../Fee/Src/Status.cpp \
-std=c++11 \
-lopencv_world -lstdc++fs \
Does anyone know what I'm missing here?
You are not linking with the MySQL library:
-L../../../mysql-connector-c++-8.0.13/lib64/libmysqlcppconn8-static.a
Use:
../../../mysql-connector-c++-8.0.13/lib64/libmysqlcppconn8-static.a
or:
-L../../../mysql-connector-c++-8.0.13/lib64/ -lmysqlcppconn8-static

error compiling c++ opencv application on Raspberry Pi

I have been spending the last few days attempting to address an error I have while compiling a brief example program I found online with opencv. The code for the application can be found below, with the console command and error following. Any and all help is appreciated.
.cpp file:
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(){
Mat img = imread("/home/pi/opencv/testPic.jpg",CV_LOAD_IMAGE_COLOR);
imshow("opencvtest",img);
waitKey(0);
return 0;
}
console command and error:
pi#LaserPhysics_RasPi ~/opencv $ g++ -o cppTest cppTest.cpp -I/usr/local/include/
/tmp/ccA0pvw2.o: In function `main':
cppTest.cpp:(.text+0x30): undefined reference to `cv::imread(cv::String const&, int)'
cppTest.cpp:(.text+0x74): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
cppTest.cpp:(.text+0x94): undefined reference to `cv::waitKey(int)'
/tmp/ccA0pvw2.o: In function `cv::String::String(char const*)':
cppTest.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x50): undefined reference to `cv::String::allocate(unsigned int)'
/tmp/ccA0pvw2.o: In function `cv::String::~String()':
cppTest.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccA0pvw2.o: In function `cv::Mat::~Mat()':
cppTest.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
/tmp/ccA0pvw2.o: In function `cv::Mat::release()':
cppTest.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x68): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
You have to link your binary against OpenCV... Assuming you properly installed OpenCV this can be done with:
g++ -o cppTest cppTest.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc

Errors Compiling OpenCV on Debian

I installed OpenCV from the repos on my Debian Wheezy (64bits). I was able to compile the source file of an example but when it goes to the build step this happens:
g++ -o dist/Debug/GNU-Linux-x86/opencvtestapp build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/ ... /main.cpp:9: undefined reference to `cv::VideoCapture::VideoCapture(int)'
/home/ ... /main.cpp:11: undefined reference to `cv::VideoCapture::isOpened() const'
/home/ ... /main.cpp:16: undefined reference to `cv::VideoCapture::get(int)'
/home/ ... /main.cpp:17: undefined reference to `cv::VideoCapture::get(int)'
/home/ ... /main.cpp:21: undefined reference to `cv::namedWindow(std::string const&, int)'
/home/ ... /main.cpp:26: undefined reference to `cv::VideoCapture::read(cv::Mat&)'
/home/ ... /main.cpp:33: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
/home/ ... /main.cpp:33: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
/home/ ... /main.cpp:35: undefined reference to `cv::waitKey(int)'
/home/ ... /main.cpp:40: undefined reference to `cv::VideoCapture::~VideoCapture()'
/home/ ... /main.cpp:40: undefined reference to `cv::VideoCapture::~VideoCapture()'
build/Debug/GNU-Linux-x86/main.o: In function `cv::Mat::~Mat()':
/usr/include/opencv2/core/mat.hpp:297: undefined reference to `cv::fastFree(void*)'
build/Debug/GNU-Linux-x86/main.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.hpp:382: undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/opencvtestapp] Error 1
make[2]: Leaving directory `/home/work/OpenCVTestApp'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/work/OpenCVTestApp'
make: *** [.build-impl] Error 2
I am using NetBeans 8.0 and OpenCV2.3 (from the repo).
Any suggestions on what I could be missing?
Thanks!
#berak is totally right on his comment, for that was the problem.
I forgot to add the libraries to the linker configuration. :P
As for 2.3 in 2014: I agree. I am planning to use 3.o alpha but this is what the repo had and I didn't want to compile the whole thing just to run some samples.
Thank you #berac! I hope the question is still useful for someone out there.

synergy won't compile -- undefined reference to `pthread_xxxx

When following the build instructions for Synergy, I get the following errors.
Is there an already-developed solution to get Synergy to build?
If not, how do I get Synergy to compile on Ubuntu 13.10?
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::newMutex()':
CArchMultithreadPosix.cpp:(.text+0x319): undefined reference to `pthread_mutexattr_init'
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::raiseSignal(IArchMultithread::ESignal)':
CArchMultithreadPosix.cpp:(.text+0x43b): undefined reference to `pthread_kill'
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::threadSignalHandler(void*)':
CArchMultithreadPosix.cpp:(.text+0x490): undefined reference to `pthread_detach'
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::closeThread(CArchThreadImpl*)':
CArchMultithreadPosix.cpp:(.text+0x62b): undefined reference to `pthread_detach'
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::newThread(void* (*)(void*), void*)':
CArchMultithreadPosix.cpp:(.text+0x8e6): undefined reference to `pthread_sigmask'
CArchMultithreadPosix.cpp:(.text+0x90f): undefined reference to `pthread_sigmask'
CArchMultithreadPosix.cpp:(.text+0x935): undefined reference to `pthread_create'
CArchMultithreadPosix.cpp:(.text+0x9a4): undefined reference to `pthread_create'
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::CArchMultithreadPosix()':
CArchMultithreadPosix.cpp:(.text+0xe11): undefined reference to `pthread_mutexattr_init'
CArchMultithreadPosix.cpp:(.text+0xf05): undefined reference to `pthread_sigmask'
CArchMultithreadPosix.cpp:(.text+0xf26): undefined reference to `pthread_sigmask'
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::startSignalHandler()':
CArchMultithreadPosix.cpp:(.text+0x10a8): undefined reference to `pthread_sigmask'
CArchMultithreadPosix.cpp:(.text+0x10cd): undefined reference to `pthread_sigmask'
CArchMultithreadPosix.cpp:(.text+0x1104): undefined reference to `pthread_create'
../../../../../lib/libarch.a(CArchMultithreadPosix.o): In function `CArchMultithreadPosix::cancelThread(CArchThreadImpl*)':
CArchMultithreadPosix.cpp:(.text+0x5e3): undefined reference to `pthread_kill'
collect2: error: ld returned 1 exit status
make[2]: *** [../../bin/synergyd] Error 1
make[1]: *** [src/cmd/synergyd/CMakeFiles/synergyd.dir/all] Error 2
make: *** [all] Error 2
Going back to: /usr/local/src/synergy-1.4.15-Source
Error: make failed: 512
SOLUTION: manually change the order of the contents of /synergy-1.4.15-Source/src/cmd/synergyd/CMakeFiles/synergyd.dir/link.txt to put -lpthread contents last.
You'd rather edit the CMakelists.txt file to add pthread at the end of the target_link_libraries command.
You may also add link_libraries(pthread).

how to compile and run this program, pthread issue?

I would like to compile the following program that makes alignment of fasta sequences, the program is available in:
http://compbio.cs.princeton.edu/mems/
I have downloaded a zip file called sparseMEM and downloaded the g++ in Ubuntu Linux, in the directory created there is a Makefile archive, so I tried to compile with make. The problem is that I got the following error:
g++ -lpthread -O3 -DSIXTYFOURBITS mummer.o qsufsort.o sparseSA.o fasta.o -o mummer
mummer.o: In function `main':
mummer.cpp:(.text.startup+0x480): undefined reference to `pthread_create'
mummer.cpp:(.text.startup+0x4a8): undefined reference to `pthread_join'
sparseSA.o: In function `sparseSA::MEM(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::vector<match_t, std::allocator<match_t> >&, int, bool, int)':
sparseSA.cpp:(.text+0x3bbc): undefined reference to `pthread_create'
sparseSA.cpp:(.text+0x3be0): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make: *** [mummer] Error 1
how I can make it run?
also if somebody knows how to test this program it would be great
thanks
For Linux you need -pthread instead of -lpthread.