OpenCV application (not library) linking errors - c++

After significant bit of searching around, I am still feeling quite clueless as to what is going on.
I have written a OpenCV simple application (more-or-less based on a tutorial), but getting it build has been a challenge. Here's the code:-
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main()
{
CvCapture *cam;
cam = cvCaptureFromFile("http://icarus#cocodyn.dynip.net:2002/videostream.cgi");
if (cam == NULL) {
printf("camera is null\n");
}
else {
printf("camera is non-null\n");
}
cvNamedWindow("Mycam", 0);
while (cvWaitKey(10) != atoi("q")) {
double t1 = (double) cvGetTickCount();
IplImage *img = cvQueryFrame(cam);
double t2 = (double) cvGetTickCount();
printf("time: %gms fps: %.2g\n", (t2-t1)/(cvGetTickFrequency() * 1000.), 1000./((t2-t1)/(cvGetTickFrequency() * 1000.)));
cvShowImage("Mycam", img);
}
cvReleaseCapture(&cam);
}
And here's what my Makefile looks like:
ipcamcap: ipcamcap.c
g++ `pkg-config --cflags --libs opencv` -o ipcamcap ipcamcap.c
Finally, here are the errors I get --
/home/icarus/Projects/ipcamcap$ make
g++ `pkg-config --cflags --libs opencv` -o ipcamcap ipcamcap.c
/tmp/ccV5YLqQ.o: In function `main':
ipcamcap.c:(.text+0xf): undefined reference to `cvCreateFileCapture'
ipcamcap.c:(.text+0x41): undefined reference to `cvNamedWindow'
ipcamcap.c:(.text+0x4b): undefined reference to `cvGetTickCount'
ipcamcap.c:(.text+0x61): undefined reference to `cvQueryFrame'
ipcamcap.c:(.text+0x6a): undefined reference to `cvGetTickCount'
ipcamcap.c:(.text+0x8c): undefined reference to `cvGetTickFrequency'
ipcamcap.c:(.text+0xd6): undefined reference to `cvGetTickFrequency'
ipcamcap.c:(.text+0x118): undefined reference to `cvShowImage'
ipcamcap.c:(.text+0x122): undefined reference to `cvWaitKey'
ipcamcap.c:(.text+0x147): undefined reference to `cvReleaseCapture'
collect2: ld returned 1 exit status
make: *** [ipcamcap] Error 1
/home/icarus/Projects/ipcamcap$
On the host, I can see that --
/home/icarus/Projects/ipcamcap$ echo `pkg-config --cflags --libs opencv`
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
/home/icarus/Projects/ipcamcap$
And, I do have the libs on this host as well --
/home/icarus/Projects/ipcamcap$ ls -l /usr/local/lib/libopencv_core.so*
lrwxrwxrwx 1 root root 21 2012-02-28 11:44 /usr/local/lib/libopencv_core.so -> libopencv_core.so.2.3
lrwxrwxrwx 1 root root 23 2012-02-28 11:44 /usr/local/lib/libopencv_core.so.2.3 -> libopencv_core.so.2.3.1
-rw-r--r-- 1 root root 2169691 2012-02-28 11:16 /usr/local/lib/libopencv_core.so.2.3.1
of course, apart from all the other OpenCV libraries.
Edited:
Note that I started with compiling the program with "gcc" compiler, but the errors were lot more, like -
gcc `pkg-config --cflags --libs opencv` -o ipcamcap ipcamcap.c
/tmp/cc9zt8fA.o: In function `cvDecRefData':
ipcamcap.c:(.text+0x9f2): undefined reference to `cvFree_'
ipcamcap.c:(.text+0xa7a): undefined reference to `cvFree_'
/tmp/cc9zt8fA.o: In function `cvGetRow':
ipcamcap.c:(.text+0xb91): undefined reference to `cvGetRows'
/tmp/cc9zt8fA.o: In function `cvGetCol':
ipcamcap.c:(.text+0xbbf): undefined reference to `cvGetCols'
/tmp/cc9zt8fA.o: In function `cvReleaseMatND':
ipcamcap.c:(.text+0xbd9): undefined reference to `cvReleaseMat'
/tmp/cc9zt8fA.o: In function `cvSubS':
ipcamcap.c:(.text+0xd35): undefined reference to `cvAddS'
/tmp/cc9zt8fA.o: In function `cvCloneSeq':
ipcamcap.c:(.text+0xd6e): undefined reference to `cvSeqSlice'
/tmp/cc9zt8fA.o: In function `cvSetNew':
ipcamcap.c:(.text+0xddb): undefined reference to `cvSetAdd'
/tmp/cc9zt8fA.o: In function `cvGetSetElem':
ipcamcap.c:(.text+0xe84): undefined reference to `cvGetSeqElem'
/tmp/cc9zt8fA.o: In function `cvEllipseBox':
ipcamcap.c:(.text+0xf69): undefined reference to `cvEllipse'
/tmp/cc9zt8fA.o: In function `cvFont':
ipcamcap.c:(.text+0xfa6): undefined reference to `cvInitFont'
/tmp/cc9zt8fA.o: In function `cvReadIntByName':
ipcamcap.c:(.text+0x1094): undefined reference to `cvGetFileNodeByName'
/tmp/cc9zt8fA.o: In function `cvReadRealByName':
ipcamcap.c:(.text+0x1147): undefined reference to `cvGetFileNodeByName'
/tmp/cc9zt8fA.o: In function `cvReadStringByName':
ipcamcap.c:(.text+0x11bd): undefined reference to `cvGetFileNodeByName'
/tmp/cc9zt8fA.o: In function `cvReadByName':
ipcamcap.c:(.text+0x11fd): undefined reference to `cvGetFileNodeByName'
ipcamcap.c:(.text+0x1213): undefined reference to `cvRead'
/tmp/cc9zt8fA.o: In function `cvCreateSubdivDelaunay2D':
ipcamcap.c:(.text+0x124f): undefined reference to `cvCreateSubdiv2D'
ipcamcap.c:(.text+0x126a): undefined reference to `cvInitSubdivDelaunay2D'
/tmp/cc9zt8fA.o: In function `cvContourPerimeter':
ipcamcap.c:(.text+0x1442): undefined reference to `cvArcLength'
/tmp/cc9zt8fA.o: In function `cvCalcHist':
ipcamcap.c:(.text+0x1472): undefined reference to `cvCalcArrHist'
/tmp/cc9zt8fA.o: In function `main':
ipcamcap.c:(.text+0x15bb): undefined reference to `cvCreateFileCapture'
ipcamcap.c:(.text+0x15ed): undefined reference to `cvNamedWindow'
ipcamcap.c:(.text+0x15f7): undefined reference to `cvGetTickCount'
ipcamcap.c:(.text+0x160d): undefined reference to `cvQueryFrame'
ipcamcap.c:(.text+0x1616): undefined reference to `cvGetTickCount'
ipcamcap.c:(.text+0x1638): undefined reference to `cvGetTickFrequency'
ipcamcap.c:(.text+0x167e): undefined reference to `cvGetTickFrequency'
ipcamcap.c:(.text+0x16bf): undefined reference to `cvShowImage'
ipcamcap.c:(.text+0x16c9): undefined reference to `cvWaitKey'
ipcamcap.c:(.text+0x16e9): undefined reference to `cvReleaseCapture'
collect2: ld returned 1 exit status
make: *** [ipcamcap] Error 1

gcc `pkg-config --cflags --libs opencv` -o ipcamcap ipcamcap.c
The order of flags sometimes matter. Try:
gcc -o ipcamcap ipcamcap.c `pkg-config --cflags --libs opencv`
You can get more information here.

Be sure you are correctly including and linking all library files.
I specified library's search path with the following:
-L/usr/local/lib
-lopencv_core -lopencv_highgui
and obviously included libraries for the compiler:
-I/usr/local/include/opencv
and compiled correctly your code snippet.

Related

Undefined reference errors for OpenCV Hello World in Ubuntu

I'm trying the following code:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char** argv) {
namedWindow("Output",1);
Mat output = Mat::zeros( 120, 350, CV_8UC3 );
putText(output,"Hello World",cvPoint(15,70),
FONT_HERSHEY_PLAIN,3,cvScalar(0,255,0),4);
imshow("Output", output);
waitKey(0);
return 0;
}
I then tried g++ -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui opencv_hello.cpp -o opencv_hello
and g++pkg-config opencv cvblob --cflags --libsopencv_hello.cpp -o opencv_hello
But they both give the same undefined reference errors:
opencv_hello.cpp:(.text+0x132): undefined reference to `cv::namedWindow(cv::String const&, int)'
opencv_hello.cpp:(.text+0x15f): undefined reference to `cv::Mat::zeros(int, int, int)'
opencv_hello.cpp:(.text+0x26f): undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
opencv_hello.cpp:(.text+0x2d7): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
opencv_hello.cpp:(.text+0x2ff): undefined reference to `cv::waitKey(int)'
/tmp/cctt8VGQ.o: In function `cv::String::String(char const*)':
opencv_hello.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cctt8VGQ.o: In function `cv::String::~String()':
opencv_hello.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/cctt8VGQ.o: In function `cv::Mat::~Mat()':
opencv_hello.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cctt8VGQ.o: In function `cv::Mat::release()':
opencv_hello.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
How can I fix this?
If pkg-config opencv --cflags --libs command finds OpenCV include files and libraries below compilation works wituout any errors.
g++ opencv_hello.cpp -o opencv_hello $(pkg-config opencv --cflags --libs)
or
g++ opencv_hello.cpp -o opencv_hello `pkg-config opencv --cflags --libs`

g++ cannot static link libmongcxx(r3.0.2) but dynamic link works

I use the example code from mongodb site to show the problem here. OS: ArchLiux, c++ is a link to g++
[dean#dell_xps_13 ~]$ c++ --version c++ (GCC) 6.2.1 20160830 Copyright
(C) 2016 Free Software Foundation, Inc. This is free software; see the
source for copying conditions. There is NO warranty; not even for
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
code is in test.cc file
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
bsoncxx::builder::stream::document document{};
auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
First compile it to object file:
c++ -g -std=c++11 -I../include -I/usr/include/bsoncxx/v_noabi
-I/usr/include/mongocxx/v_noabi -Wall -o test.o -c ./test.cc
Link it without -static works:
c++ test.o -o test -static-libgcc -static-libstdc++ -L/usr/lib
-lpthread -lmongocxx -lbsoncxx -lboost_log -lboost_log_setup -lboost_system -lboost_thread -lboost_filesystem
This can run and print out some messages:
[dean#dell_xps_13 mongo-cxx-driver-r3.0.2]$ ./test
{
"_id" : {
"$oid" : "58218e821b489308ae4411d1"
},
"hello" : "world"
}
Now get error with -static option
c++ test.o -o test -static-libgcc -static-libstdc++ -static
-L/usr/lib -lpthread -lmongocxx -lbsoncxx -lboost_log -lboost_log_setup -lboost_system -lboost_thread -lboost_filesystem
Many error messages show below:
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&,
mongocxx::v_noabi::options::client const&)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x28):
undefined reference tomongoc_client_new_from_uri'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x10c):
undefined reference to mongoc_client_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::operator=(mongocxx::v_noabi::client&&)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x190):
undefined reference to mongoc_client_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::~client()':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x1c3):
undefined reference to mongoc_client_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_concern(mongocxx::v_noabi::read_concern)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x214):
undefined reference to mongoc_client_set_read_concern'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_concern() const':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x243):
undefined reference to mongoc_client_get_read_concern'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x24b):
undefined reference tomongoc_read_concern_copy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x27c):
undefined reference to mongoc_read_concern_destroy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x2a3):
undefined reference tomongoc_read_concern_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_preference(mongocxx::v_noabi::read_preference)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3a4):
undefined reference tomongoc_client_set_read_prefs'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::read_preference() const':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3c3):
undefined reference tomongoc_client_get_read_prefs'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3cb):
undefined reference to mongoc_read_prefs_copy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x3fc):
undefined reference tomongoc_read_prefs_destroy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x423):
undefined reference to mongoc_read_prefs_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::uri() const':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x463):
undefined reference to mongoc_client_get_uri'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x46b):
undefined reference tomongoc_uri_copy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x49c):
undefined reference to mongoc_uri_destroy'
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x4c3):
undefined reference tomongoc_uri_destroy'
/usr/lib/libmongocxx.a(client.cpp.o): In function
mongocxx::v_noabi::client::write_concern(mongocxx::v_noabi::write_concern)':
/home/dean/work/github/mongo-cxx-driver/src/mongocxx/client.cpp:(.text+0x504):
undefined reference tomongoc_client_set_write_concern'
/usr/lib/libmongocxx.a(client.cpp.o): In function
`mongocxx::v_noabi::client::write_concern() const':
....
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::oid::to_string[abi:cxx11]() const':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x139):
undefined reference tobson_oid_to_string'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::oid::get_time_t() const':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x1ea):
undefined reference tobson_oid_get_time_t'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::oid_compare(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x24f):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator<(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x2af):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator>(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x30f):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator<=(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x36f):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o): In function
bsoncxx::v_noabi::operator>=(bsoncxx::v_noabi::oid const&,
bsoncxx::v_noabi::oid const&)':
/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x3cf):
undefined reference tobson_oid_compare'
/usr/lib/libbsoncxx.a(oid.cpp.o):/home/dean/work/github/mongo-cxx-driver/src/bsoncxx/oid.cpp:(.text+0x42f):
more undefined references to `bson_oid_compare' follow collect2:
error: ld returned 1 exit status
The -static flag forces the linker to accept only static libraries and not any shared libraries. In other words it does not require a dependency on dynamic libraries at runtime in order to run.
Most likely mongocxx has some dependencies.
To achieve static linking requires that the archive (.a) versions of your libraries exist on the system.
The another possible issue is that the order of static libraries in the linker command line does matter, so that might also be an issue if there is a dependency on different static libs. The linker will process the libraries in order as they are in the command line, and from each static lib it will only pull those symbols that are required (with as much information as the linker has at that time)
Use nm . That will give you the symbol names.

Tableau API linker error

This is probably trivial. I'm using Qt with the Tableau C++ api and I am having a bad time trying to get things to link appropriately.
I have the following directory structure.
allenh1#localhost ~/CS/tableau-api/tableau-qt
$ ls
bin include lib64 share src tableau-qt.pro ui
Here's the .pro file
QT += core gui widgets
CONFIG += c++14
TARGET = qt-tableau-demo
TEMPLATE = app
# Link with the Tableau SDK library files
QMAKE_RPATHDIR += lib64/tableausdk
SOURCES += src/main.cpp \
src/TableauTable.cpp
HEADERS += include/TableauTable.hpp
Note: the UI is not implemented yet, but will be after I get this to compile.
When I try to build it, I get the following:
allenh1#localhost ~/CS/tableau-api/tableau-qt
$ make
g++ -c -pipe -O2 -std=gnu++1y -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../../../Qt/5.6/gcc_64/include -I../../../../Qt/5.6/gcc_64/include/QtWidgets -I../../../../Qt/5.6/gcc_64/include/QtGui -I../../../../Qt/5.6/gcc_64/include/QtCore -I. -I../../../../Qt/5.6/gcc_64/mkspecs/linux-g++ -o main.o src/main.cpp
In file included from src/../include/tableau-sdk/TableauExtract.hpp:18:0,
from src/../include/TableauTable.hpp:3,
from src/main.cpp:2:
src/../include/tableau-sdk/TableauCommon.hpp:144:38: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
const TAB_RESULT GetResultCode() const { return m_result; }
^
src/main.cpp:14:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char *argv[])
^
src/main.cpp:14:31: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char *argv[])
^
g++ -c -pipe -O2 -std=gnu++1y -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../../../Qt/5.6/gcc_64/include -I../../../../Qt/5.6/gcc_64/include/QtWidgets -I../../../../Qt/5.6/gcc_64/include/QtGui -I../../../../Qt/5.6/gcc_64/include/QtCore -I. -I../../../../Qt/5.6/gcc_64/mkspecs/linux-g++ -o TableauTable.o src/TableauTable.cpp
In file included from src/../include/tableau-sdk/TableauExtract.hpp:18:0,
from src/../include/TableauTable.hpp:3,
from src/TableauTable.cpp:1:
src/../include/tableau-sdk/TableauCommon.hpp:144:38: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
const TAB_RESULT GetResultCode() const { return m_result; }
^
g++ -Wl,-O1 -Wl,-z,origin -Wl,-rpath,\$ORIGIN/lib64/tableausdk -Wl,-rpath,/home/allenh1/Qt/5.6/gcc_64/lib -o perscio-tableau-demo main.o TableauTable.o -L/home/allenh1/Qt/5.6/gcc_64/lib -lQt5Widgets -L/usr/lib64 -lQt5Gui -lQt5Core -lGL -lpthread
main.o: In function `fill_table(TableauTable*&)':
main.cpp:(.text+0x88): undefined reference to `bool TableauTable::add_column<std::type_info const&>(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::type_info const&)'
main.cpp:(.text+0xc6): undefined reference to `bool TableauTable::add_column<std::type_info const&>(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::type_info const&)'
main.cpp:(.text+0xfd): undefined reference to `bool TableauTable::add_column<std::type_info const&>(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::type_info const&)'
TableauTable.o: In function `Tableau::(anonymous namespace)::MakeTableauString(wchar_t const*)':
TableauTable.cpp:(.text+0x48): undefined reference to `ToTableauString'
TableauTable.o: In function `TableauTable::TableauTable()':
TableauTable.cpp:(.text+0x1b0): undefined reference to `TabTableDefinitionCreate'
TableauTable.cpp:(.text+0x1ba): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text+0x1ef): undefined reference to `TabTableDefinitionSetDefaultCollation'
TableauTable.cpp:(.text+0x22d): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0x2a7): undefined reference to `TabGetLastErrorMessage'
TableauTable.o: In function `TableauTable::init(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >)':
TableauTable.cpp:(.text+0x42b): undefined reference to `TabExtractAPIInitialize'
TableauTable.cpp:(.text+0x434): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text+0x47f): undefined reference to `TabExtractCreate'
TableauTable.cpp:(.text+0x509): undefined reference to `TabExtractHasTable'
TableauTable.cpp:(.text+0x5ff): undefined reference to `TabTableDefinitionCreate'
TableauTable.cpp:(.text+0x65f): undefined reference to `TabExtractAddTable'
TableauTable.cpp:(.text+0x721): undefined reference to `TabTableDefinitionClose'
TableauTable.cpp:(.text+0x74b): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0x7f7): undefined reference to `TabExtractOpenTable'
TableauTable.cpp:(.text+0x8b9): undefined reference to `TabTableGetTableDefinition'
TableauTable.cpp:(.text+0x8c2): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text+0x8df): undefined reference to `TabTableDefinitionCreate'
TableauTable.cpp:(.text+0xd0e): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xe09): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xe78): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xef7): undefined reference to `TabGetLastErrorMessage'
TableauTable.cpp:(.text+0xf97): undefined reference to `TabGetLastErrorMessage'
TableauTable.o:TableauTable.cpp:(.text+0xffa): more undefined references to `TabGetLastErrorMessage' follow
TableauTable.o: In function `std::_Sp_counted_ptr<Tableau::TableDefinition*, (__gnu_cxx::_Lock_policy)2>::_M_dispose()':
TableauTable.cpp:(.text._ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x2a): undefined reference to `TabTableDefinitionClose'
TableauTable.cpp:(.text._ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x33): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text._ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt15_Sp_counted_ptrIPN7Tableau15TableDefinitionELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x76): undefined reference to `TabGetLastErrorMessage'
TableauTable.o: In function `Tableau::TableDefinition::Close()':
TableauTable.cpp:(.text._ZN7Tableau15TableDefinition5CloseEv[_ZN7Tableau15TableDefinition5CloseEv]+0x24): undefined reference to `TabTableDefinitionClose'
TableauTable.cpp:(.text._ZN7Tableau15TableDefinition5CloseEv[_ZN7Tableau15TableDefinition5CloseEv]+0x2d): undefined reference to `TAB_RESULT_Success'
TableauTable.cpp:(.text._ZN7Tableau15TableDefinition5CloseEv[_ZN7Tableau15TableDefinition5CloseEv]+0x68): undefined reference to `TabGetLastErrorMessage'
collect2: error: ld returned 1 exit status
Makefile:200: recipe for target 'qt-tableau-demo' failed
make: *** [qt-tableau-demo] Error 1
The .so files needed (at least to my understanding) are located in the lib64 directory.
allenh1#localhost ~/CS/tableau-api/tableau-qt
$ ls lib64/tableausdk
Java libboost_thread.so libicuuc.so.44
libQt5Core.so.5 libboost_thread.so.1.56.0 libicuuc.so.44.0
libQt5Core.so.5.4.1 libcurl.so libmetrics2.so
libQt5Network.so.5 libcurl.so.4 libtabcrypto.so
libQt5Network.so.5.4.1 libcurl.so.4.4.0 libtabcrypto.so.1.0.0
libTableauCommon.so libexpat.so libtabssl.so
libTableauExtract.so libexpat.so.1 libtabssl.so.1.0.0
libTableauServer.so libexpat.so.1.6.0 libtabsys.so
libboost_chrono.so libicudata.so.44 libtabz.so
libboost_chrono.so.1.56.0 libicudata.so.44.0 libtabz.so.1
libboost_date_time.so libicui18n.so.44 libtabz.so.1.2.8
libboost_date_time.so.1.56.0 libicui18n.so.44.0 libtbb.so.2
libboost_system.so libicuio.so.44 libtbbmalloc.so.2
libboost_system.so.1.56.0 libicuio.so.44.0

matlab engine+ pcl build linker errors

code:
#include <pcl/io/pcd_io.h>
#include <pcl/filters/passthrough.h>
int
main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr filteredCloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) != 0)
{
return -1;
}
pcl::PassThrough<pcl::PointXYZ> filter;
filter.setInputCloud(cloud);
filter.setFilterFieldName("z");
filter.setFilterLimits(0.0, 2.0);
filter.filter(*filteredCloud);
}
Cmakelists1.txt: (with support to connect to matlab engine)
Cmakelists2.txt: (no support)
when i build the code with Cmakelists2.txt, I get no errors
But when i build the code with Cmakelists1.txt, I get a huge list of undefined reference errors. Cmakelists1.txt is a superset of Cmakelists2.txt, so whatever builds with 2 should build with 1
The code is a minimalist code & i have removed the matlab part for clarity.
Can anybody help?
Cmakelists1.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(passthrough_test)
find_package(PCL 1.2 REQUIRED)
set (PROJECT_LINK_LIBS libeng.so libmat.so libmx.so libut.so)
link_directories(${PCL_LIBRARY_DIRS} /usr/local/MATLAB/R2014a/bin/glnxa64)
include_directories(${PCL_INCLUDE_DIRS} /usr/local/MATLAB/R2014a/extern/include/)
add_definitions(${PCL_DEFINITIONS})
add_executable (passthrough_test passthrough_test.cpp)
target_link_libraries (passthrough_test ${PCL_LIBRARIES} ${PROJECT_LINK_LIBS})
Cmakelists2.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(passthrough_test)
find_package(PCL 1.2 REQUIRED)
link_directories(${PCL_LIBRARY_DIRS})
include_directories(${PCL_INCLUDE_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (passthrough_test passthrough_test.cpp)
target_link_libraries (passthrough_test ${PCL_LIBRARIES})
List of errors:
Linking CXX executable passthrough_test
/usr/bin/cmake -E cmake_link_script CMakeFiles/passthrough_test.dir/link.txt --verbose=1
/usr/bin/c++ -Wno-deprecated -g CMakeFiles/passthrough_test.dir/passthrough_test.cpp.o -o passthrough_test -L/usr/local/lib -L/usr/local/MATLAB/R2014a/bin/glnxa64 -rdynamic -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -lboost_iostreams -lboost_serialization -lboost_chrono -lpthread /usr/local/lib/libpcl_common.so -Wl,-Bstatic -lflann_cpp_s -Wl,-Bdynamic /usr/local/lib/libpcl_kdtree.so /usr/local/lib/libpcl_octree.so /usr/local/lib/libpcl_search.so /usr/local/lib/libpcl_sample_consensus.so /usr/local/lib/libpcl_filters.so -lOpenNI -lOpenNI2 /usr/lib/libvtkCommon.so.5.8.0 /usr/lib/libvtkFiltering.so.5.8.0 /usr/lib/libvtkImaging.so.5.8.0 /usr/lib/libvtkGraphics.so.5.8.0 /usr/lib/libvtkGenericFiltering.so.5.8.0 /usr/lib/libvtkIO.so.5.8.0 /usr/lib/libvtkRendering.so.5.8.0 /usr/lib/libvtkVolumeRendering.so.5.8.0 /usr/lib/libvtkHybrid.so.5.8.0 /usr/lib/libvtkWidgets.so.5.8.0 /usr/lib/libvtkParallel.so.5.8.0 /usr/lib/libvtkInfovis.so.5.8.0 /usr/lib/libvtkGeovis.so.5.8.0 /usr/lib/libvtkViews.so.5.8.0 /usr/lib/libvtkCharts.so.5.8.0 /usr/local/lib/libpcl_io.so /usr/local/lib/libpcl_features.so /usr/local/lib/libpcl_ml.so /usr/local/lib/libpcl_segmentation.so /usr/local/lib/libpcl_visualization.so /usr/local/lib/libpcl_outofcore.so /usr/local/lib/libpcl_cuda_features.so /usr/local/lib/libpcl_cuda_segmentation.so /usr/local/lib/libpcl_cuda_io.so /usr/local/lib/libpcl_cuda_sample_consensus.so -lqhull /usr/local/lib/libpcl_surface.so /usr/local/lib/libpcl_registration.so /usr/local/lib/libpcl_recognition.so /usr/local/lib/libpcl_keypoints.so /usr/local/lib/libpcl_gpu_containers.so /usr/local/lib/libpcl_gpu_utils.so /usr/local/lib/libpcl_gpu_octree.so /usr/local/lib/libpcl_gpu_features.so /usr/local/lib/libpcl_gpu_segmentation.so /usr/local/lib/libpcl_gpu_surface.so /usr/local/lib/libpcl_gpu_kinfu.so /usr/local/lib/libpcl_gpu_kinfu_large_scale.so /usr/local/lib/libpcl_tracking.so /usr/local/lib/libpcl_stereo.so /usr/local/lib/libpcl_people.so /usr/local/lib/libpcl_apps.so /usr/local/lib/libpcl_3d_rec_framework.so -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -lboost_iostreams -lboost_serialization -lboost_chrono -lpthread -lqhull -lOpenNI -lOpenNI2 -Wl,-Bstatic -lflann_cpp_s -Wl,-Bdynamic /usr/lib/libvtkCommon.so.5.8.0 /usr/lib/libvtkFiltering.so.5.8.0 /usr/lib/libvtkImaging.so.5.8.0 /usr/lib/libvtkGraphics.so.5.8.0 /usr/lib/libvtkGenericFiltering.so.5.8.0 /usr/lib/libvtkIO.so.5.8.0 /usr/lib/libvtkRendering.so.5.8.0 /usr/lib/libvtkVolumeRendering.so.5.8.0 /usr/lib/libvtkHybrid.so.5.8.0 /usr/lib/libvtkWidgets.so.5.8.0 /usr/lib/libvtkParallel.so.5.8.0 /usr/lib/libvtkInfovis.so.5.8.0 /usr/lib/libvtkGeovis.so.5.8.0 /usr/lib/libvtkViews.so.5.8.0 /usr/lib/libvtkCharts.so.5.8.0 -leng -lmat -lmx -lut /usr/local/lib/libpcl_common.so /usr/local/lib/libpcl_kdtree.so /usr/local/lib/libpcl_octree.so /usr/local/lib/libpcl_search.so /usr/local/lib/libpcl_sample_consensus.so /usr/local/lib/libpcl_filters.so /usr/local/lib/libpcl_io.so /usr/local/lib/libpcl_features.so /usr/local/lib/libpcl_ml.so /usr/local/lib/libpcl_segmentation.so /usr/local/lib/libpcl_visualization.so /usr/local/lib/libpcl_outofcore.so /usr/local/lib/libpcl_cuda_features.so /usr/local/lib/libpcl_cuda_segmentation.so /usr/local/lib/libpcl_cuda_io.so /usr/local/lib/libpcl_cuda_sample_consensus.so /usr/local/lib/libpcl_surface.so /usr/local/lib/libpcl_registration.so /usr/local/lib/libpcl_recognition.so /usr/local/lib/libpcl_keypoints.so /usr/local/lib/libpcl_gpu_containers.so /usr/local/lib/libpcl_gpu_utils.so /usr/local/lib/libpcl_gpu_octree.so /usr/local/lib/libpcl_gpu_features.so /usr/local/lib/libpcl_gpu_segmentation.so /usr/local/lib/libpcl_gpu_surface.so /usr/local/lib/libpcl_gpu_kinfu.so /usr/local/lib/libpcl_gpu_kinfu_large_scale.so /usr/local/lib/libpcl_tracking.so /usr/local/lib/libpcl_stereo.so /usr/local/lib/libpcl_people.so /usr/local/lib/libpcl_apps.so /usr/local/lib/libpcl_3d_rec_framework.so -leng -lmat -lmx -lut /usr/lib/libvtkViews.so.5.8.0 /usr/lib/libvtkInfovis.so.5.8.0 /usr/lib/libvtkWidgets.so.5.8.0 /usr/lib/libvtkVolumeRendering.so.5.8.0 /usr/lib/libvtkHybrid.so.5.8.0 /usr/lib/libvtkParallel.so.5.8.0 /usr/lib/libvtkRendering.so.5.8.0 /usr/lib/libvtkImaging.so.5.8.0 /usr/lib/libvtkGraphics.so.5.8.0 /usr/lib/libvtkIO.so.5.8.0 /usr/lib/libvtkFiltering.so.5.8.0 /usr/lib/libvtkCommon.so.5.8.0 -lm /usr/lib/libvtksys.so.5.8.0 -ldl -Wl,-rpath,/usr/local/lib:/usr/local/MATLAB/R2014a/bin/glnxa64
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFReadDirectory#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_CTX_use_certificate_chain_file#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFIsTiled#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_get_error#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_use_PrivateKey_file#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_set_ex_data#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFScanlineSize#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `X509_STORE_set_flags#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `X509_get_subject_name#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `ENGINE_load_private_key#OPENSSL_1.0.0'
make[2]: Leaving directory `/home/shome/temp_codes/passthrough_test/build'
//usr/lib/libpq.so.5: undefined reference to `CRYPTO_set_id_callback#OPENSSL_1.0.0'
make[1]: Leaving directory `/home/shome/temp_codes/passthrough_test/build'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFClose#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_CTX_get_cert_store#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFGetFieldDefaulted#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_check_private_key#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `ENGINE_by_id#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `CRYPTO_set_locking_callback#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `X509_NAME_get_text_by_NID#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_write#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `X509_free#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_free#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_ctrl#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_set_verify#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_set_fd#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_use_PrivateKey#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFSetWarningHandler#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `ENGINE_finish#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `_TIFFmalloc#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_get_peer_certificate#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `CRYPTO_num_locks#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_use_certificate_file#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `ENGINE_free#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `OPENSSL_config#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `X509_STORE_load_locations#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFDefaultStripSize#LIBTIFF_4.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFReadTile#LIBTIFF_4.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFWriteScanline#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_read#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `_TIFFfree#LIBTIFF_4.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFGetField#LIBTIFF_4.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFClientOpen#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_CTX_new#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFNumberOfDirectories#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `ERR_get_error#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `TLSv1_method#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_new#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_load_error_strings#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFOpen#LIBTIFF_4.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFReadRGBAImage#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_CTX_load_verify_locations#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFSetField#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `ENGINE_init#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `ERR_reason_error_string#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_connect#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_CTX_ctrl#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_pending#OPENSSL_1.0.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_library_init#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFSetErrorHandler#LIBTIFF_4.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFSetDirectory#LIBTIFF_4.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFReadScanline#LIBTIFF_4.0'
//usr/lib/libpq.so.5: undefined reference to `SSL_shutdown#OPENSSL_1.0.0'
/usr/lib/libvtkIO.so.5.8.0: undefined reference to `TIFFNumberOfTiles#LIBTIFF_4.0'
collect2: error: ld returned 1 exit status
make[2]: *** [passthrough_test] Error 1
make[1]: *** [CMakeFiles/passthrough_test.dir/all] Error 2
make: *** [all] Error 2

How to link to opencv 3.0 when compiled from source on Ubuntu 14.04?

I'm trying to compile and link the following opencv program that I found online:
main.cpp:
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{
VideoCapture capture(0);
while(capture.isOpened() )
{
Mat frame;
if (! capture.read(frame))
continue;
imshow("lalala", frame);
if(waitKey(10) == 27)
break;
}
return 0;
}
My filestructure is as follows:
~/dev/opencv-1
~/dev/opencv-example
The opencv-1 is a git clone of: https://github.com/Itseez/opencv
I followed the instructions located at: http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html
My goal was to debug into the opencv code, so I used the CMAKE_BUILD_TYPE=Debug
I was able to get the opencv code to compile sucessfuly. I wrote the following makefile to compile this sample:
INCPATH =-I../opencv-1/modules/objdetect/include \
-I../opencv-1/modules/highgui/include \
-I../opencv-1/modules/imgproc/include \
-I../opencv-1/modules/core/include \
-I../opencv-1/modules/imgcodecs/include \
-I../opencv-1/modules/videoio/include \
LIBPATH =-L../opencv-1/debug/lib
LIBS =-lopencv_core -lopencv_videoio -lopencv_highgui -lopencv_imgproc -lopencv_video -lopencv_objdetect
%:%.cpp
g++ $(INCPATH) $(LIBS) $(LIBPATH) $^ -o $#
To compile I ran: make main
When this happens, I get the following linking errors:
g++ -I../opencv-1/modules/objdetect/include -I../opencv-1/modules/highgui/include -I../opencv-1/module s/imgproc/include -I../opencv-1/modules/core/include -I../opencv-1/modules/imgcodecs/include -I../open cv-1/modules/videoio/include -lopencv_core -lopencv_videoio -lopencv_highgui -lopencv_imgproc -lopenc v_video -lopencv_objdetect -L../opencv-1/debug/lib main.cpp -o main
/tmp/cc0PMDdW.o: In function `main':
main.cpp:(.text+0x29): undefined reference to `cv::VideoCapture::VideoCapture(int)'
main.cpp:(.text+0x69): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
main.cpp:(.text+0xce): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
main.cpp:(.text+0xf6): undefined reference to `cv::waitKey(int)'
main.cpp:(.text+0x131): undefined reference to `cv::VideoCapture::isOpened() const'
main.cpp:(.text+0x14d): undefined reference to `cv::VideoCapture::~VideoCapture()'
main.cpp:(.text+0x1b0): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/cc0PMDdW.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to `cv::String::al locate(unsigned long)'
/tmp/cc0PMDdW.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallo cate()'
/tmp/cc0PMDdW.o: In function `cv::_InputArray::_InputArray()':
main.cpp:(.text._ZN2cv11_InputArrayC2Ev[_ZN2cv11_InputArrayC5Ev]+0x13): undefined reference to `vtable for cv::_InputArray'
/tmp/cc0PMDdW.o: In function `cv::_InputArray::_InputArray(cv::Mat const&)':
main.cpp:(.text._ZN2cv11_InputArrayC2ERKNS_3MatE[_ZN2cv11_InputArrayC5ERKNS_3MatE]+0x17): undefined re ference to `vtable for cv::_InputArray'
/tmp/cc0PMDdW.o: In function `cv::_InputArray::~_InputArray()':
main.cpp:(.text._ZN2cv11_InputArrayD2Ev[_ZN2cv11_InputArrayD5Ev]+0x13): undefined reference to `vtable for cv::_InputArray'
/tmp/cc0PMDdW.o: In function `cv::_OutputArray::_OutputArray(cv::Mat&)':
main.cpp:(.text._ZN2cv12_OutputArrayC2ERNS_3MatE[_ZN2cv12_OutputArrayC5ERNS_3MatE]+0x23): undefined re ference to `vtable for cv::_OutputArray'
/tmp/cc0PMDdW.o: In function `cv::_OutputArray::~_OutputArray()':
main.cpp:(.text._ZN2cv12_OutputArrayD2Ev[_ZN2cv12_OutputArrayD5Ev]+0x13): undefined reference to `vtab le for cv::_OutputArray'
/tmp/cc0PMDdW.o: In function `cv::Mat::~Mat()':
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cc0PMDdW.o: In function `cv::Mat::release()':
main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::dea llocate()'
collect2: error: ld returned 1 exit status
make: *** [main] Error 1
I'm not sure what I'm missing. I've included all of the libraries that this simple program should need to compile. I've searched online for similar errors and all of the answers I've seen suggest adding the libraries that are already in my makefile.
Your problem is that this line:
g++ $(INCPATH) $(LIBS) $(LIBPATH) $^ -o $#
Should be re-written like this:
$(CXX) $(INCPATH) $(LIBPATH) $^ $(LIBS) -o $#
The variable containing -l flags should always go after the .cpp or .o files in the command line.
But you can do better. Your Makefile should ultimately look like this:
CPPFLAGS := -I../opencv-1/modules/objdetect/include \
-I../opencv-1/modules/highgui/include \
-I../opencv-1/modules/imgproc/include \
-I../opencv-1/modules/core/include \
-I../opencv-1/modules/imgcodecs/include \
-I../opencv-1/modules/videoio/include
LDFLAGS := -L../opencv-1/debug/lib
LDLIBS := -lopencv_core -lopencv_videoio -lopencv_highgui \
-lopencv_imgproc -lopencv_video -lopencv_objdetect
Nothing more, nothing less. GNU Make already has an implicit rule to compile a .cpp file into an executable, just rely on it by using the built-in variables.
Note: CPPFLAGS stands for preprocessor flags, not c++ flags. Use CXXFLAGS to provide flags such as -std or -g flags.