I am trying to build the hello world gtkmm example from the docs using the command
-DLIBDEFLATE_DLL -IC:/msys64/mingw64/include/gtkmm-4.0 -IC:/msys64/mingw64/lib/gtkmm-4.0/include -IC:/msys64/mingw64/include/gtk-4.0 \
-IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/graphene-1.0 \
-IC:/msys64/mingw64/lib/graphene-1.0/include -IC:/msys64/mingw64/include/pangomm-2.48 \
-IC:/msys64/mingw64/lib/pangomm-2.48/include -IC:/msys64/mingw64/include/giomm-2.68 \
-IC:/msys64/mingw64/lib/giomm-2.68/include -IC:/msys64/mingw64/include/glibmm-2.68 \
-IC:/msys64/mingw64/lib/glibmm-2.68/include -IC:/msys64/mingw64/include/cairomm-1.16 \
-IC:/msys64/mingw64/lib/cairomm-1.16/include -IC:/msys64/mingw64/include/sigc++-3.0 \
-IC:/msys64/mingw64/lib/sigc++-3.0/include -IC:/msys64/mingw64/include/pango-1.0 \
-IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/pango-1.0 \
-IC:/msys64/mingw64/include/fribidi -IC:/msys64/mingw64/include/cairo \
-IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include/harfbuzz \
-IC:/msys64/mingw64/include/pixman-1 -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 \
-IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/webp \
-IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include \
-lgtkmm-4.0 -lgtk-4.0 -lpangowin32-1.0 -lcairo-gobject -lgraphene-1.0 -lpangomm-2.48 \
-lgiomm-2.68 -lgio-2.0 -lglibmm-2.68 -lcairomm-1.16 -lsigc-3.0 -lpangocairo-1.0 -lpango-1.0 \
-lharfbuzz -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lintl
or
g++ -static -static-libgcc `pkg-config gtkmm-4 --cflags --libs`
this resutls in the following errors
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgtk-4: No such file or directory
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgraphene-1.0: No such file or directory
collect2.exe: error: ld returned 1 exit status
according to this question I should add the path C:\msys64\mingw64\bin so i did but it did not help
I am using msys2 to compile this example
#include <gtkmm.h>
class Win : public Gtk::Window
{
public:
Win();
};
Win::Win()
{
set_title("Hello world");
set_default_size(500,500);
}
int main (int argc, char * argv[])
{
auto app = Gtk::Application::create("org.gtkmm.examples.base");
return app->make_window_and_run<Win>(argc, argv);
}
I did verify that gtk-4 and graphene are both installed and located the include and lib folders
I am using OpenCV 3.2.0 on Ubuntu 64-bit and have the written following code which I call WebImageIO.cpp
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cv.h"
#include "highgui.h"
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <math.h>
#include <windows.h>
#include "Generic.h"
#include "Palette.h"
#include "CWebImageIO.h"
using namespace cv;
ERROR_NUMBER CWebImageIO::WriteColourImageToPNGFile(BytePlane bytePlane, BYTE *bpOutputImage,
TCHAR *outputFileName)
{
int iNumBands=3;
int row, col, inputInc, inc;
BytePlane bpBufferPlane;
// Make real colour output plane
bpBufferPlane=MakeBytePlane(bytePlane.iRows, iNumBands*bytePlane.iColumns, NULL);
if (!(bpBufferPlane.Data))
return ERROR_MEMORY_ALLOCATION;
// Fill buffer plane with test values
cv::Mat outputImage=cv::Mat(bytePlane.iRows, bytePlane.iColumns, CV_8UC3);
if (!(outputImage.data))
{
FreeBytePlane(bpBufferPlane);
return ERROR_MEMORY_ALLOCATION;
}
memcpy((void *)(outputImage.data), (void *)(bpOutputImage),
bytePlane.iRows*bytePlane.iColumns*3);
if (!(imwrite((char *)outputFileName, outputImage)))
{
free(bpOutputImage);
return ErrorWritingFile(outputFileName);
}
// Cleanup
FreeBytePlane(bpBufferPlane);
return ERROR_NONE;
}
I then try to build it with the following.
g++ `pkg-config opencv --libs` -o dist/Debug/GNU-Linux/progName build/Debug/GNU-Linux/_ext/73c876dd/WebImageIO.o build/Debug/GNU-Linux/main.o /usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lpng
I get the following error message.
/home/peter/NetBeansProjects/ApplyModelToSet/../../DraculaFiles/CWebImageIO.cpp:247: undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
I have read that cv::imread (at least) uses the imgcodecs library but
sudo find / -name '*imgcodecs*.so' -print
returns no results after my having installed opencv 3.2 on my system
EDIT:
pkg-config opencv --libs
returns
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d /usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib /usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core /usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d /usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann /usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu /usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc /usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy /usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect /usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl /usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo /usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching /usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres /usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts /usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab
I am trying to setup opencv in eclipse Luna. I have written a sample application as follows :
#include <cv.h>
#include <highgui.h>
#include<iostream>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
In my project properties i have included /usr/local/include/opencv in (Project->Properties->C/C++ Build->Settings->Tool Settings -> GCC C++ Compiler -> Includes -> Include Paths. )
and /usr/local/lib in (Project->Properties->C/C++ Build->Settings->Tool Settings -> GCC C++ Linker -> Libraries -> Library Search Path. )
My output of the command pkg-config --cflags opencv is -I/usr/local/include/opencv -I/usr/local/include
and the output of pkg-config --libs opencv is
-L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_viz -lopencv_adas -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_face -lopencv_latentsvm -lopencv_objdetect -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_ml -lopencv_flann -lopencv_xobjdetect -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core -lopencv_hal
When I tried building my project i got the following errors.
‘imread’ was not declared in this scope
‘imshow’ was not declared in this scope
‘namedWindow’ was not declared in this scope
‘waitKey’ was not declared in this scope
Function 'imread' could not be resolved
Function 'imshow' could not be resolved
Function 'namedWindow' could not be resolved
Function 'waitKey' could not be resolved
Can anyone help me fixing the problem and explain what is that I was missing.
Try to change:
#include <cv.h>
#include <highgui.h>
To this:
#include <opencv2/opencv.hpp>
You also need to link the Libraries (GCC C++ Linker » Libraries):
opencv_core
opencv_imgcodecs
opencv_highgui
You didn't say which version you are using, but as you have -lopencv_imgcodecs, you are probably using OpenCV 3. If you prefer, follow the instructions here. Also change from CV_WINDOW_AUTOSIZE to WINDOW_AUTOSIZE.
For some reason I am getting undefined symbols for MD5 and RAND_bytes in this one particular C++ file. OpenSSL has installed itself (libssl and libcrypto) to /usr/lib and /usr/include/openssl/.
libtool: link: (cd ".libs" && rm -f "libeapgpsk.so.1" && ln -s "libeapgpsk.so.1.0.0" "libeapgpsk.so.1")
libtool: link: (cd ".libs" && rm -f "libeapgpsk.so" && ln -s "libeapgpsk.so.1.0.0" "libeapgpsk.so")
libtool: link: ar cru .libs/libeapgpsk.a eap-gpsk/eap_gpsk_fsm.o
libtool: link: ranlib .libs/libeapgpsk.a
libtool: link: ( cd ".libs" && rm -f "libeapgpsk.la" && ln -s "../libeapgpsk.la" "libeapgpsk.la" )
depbase=`echo tests/md5_test.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
g++ -DPACKAGE_NAME=\"OpenDiameter\" -DPACKAGE_TARNAME=\"opendiameter\" -DPACKAGE_VERSION=\"1.0.7-i\" -DPACKAGE_STRING=\"OpenDiameter\ 1.0.7-i\" -DPACKAGE_BUGREPORT=\"vfajardo#tari.toshiba.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"opendiameter\" -DVERSION=\"1.0.7-i\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_IFADDRS_H=1 -DHAVE_SHADOW_H=1 -DHAVE__BOOL=1 -DHAVE_STDBOOL_H=1 -DHAVE_GETIFADDRS=1 -I. -Wall -I/usr -I/usr -fno-strict-aliasing -I../include -I../libeap/include -DOS_LINUX -I/usr/include/openssl -I/usr/include/openssl -MT tests/md5_test.o -MD -MP -MF $depbase.Tpo -c -o tests/md5_test.o tests/md5_test.cxx &&\
mv -f $depbase.Tpo $depbase.Po
In file included from ../include/aaa_dictionary_api.h:45:0,
from ../include/aaa_parser_api.h:38,
from ../libeap/include/eap.hxx:54,
from tests/md5_test.cxx:45:
../include/framework.h:1653:7: warning: ‘typedef’ was ignored in this declaration [enabled by default]
In file included from ../include/aaa_parser_api.h:38:0,
from ../libeap/include/eap.hxx:54,
from tests/md5_test.cxx:45:
../include/aaa_dictionary_api.h:58:1: warning: ‘typedef’ was ignored in this declaration [enabled by default]
tests/md5_test.cxx: In constructor ‘EapTask::EapTask()’:
tests/md5_test.cxx:71:45: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘PeerApplication::PeerApplication(EapTask&, ACE_Semaphore&)’:
tests/md5_test.cxx:418:72: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘StandAloneAuthApplication::StandAloneAuthApplication(EapTask&, ACE_Semaphore&)’:
tests/md5_test.cxx:460:80: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘BackendAuthApplication::BackendAuthApplication(EapTask&, ACE_Semaphore&, bool)’:
tests/md5_test.cxx:514:58: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘PassThroughAuthApplication::PassThroughAuthApplication(EapTask&, ACE_Semaphore&, bool)’:
tests/md5_test.cxx:576:62: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
/bin/bash ../libtool --tag=CXX --mode=link g++ -I/usr/include/openssl -L/usr/lib -o md5_test tests/md5_test.o -ldl -lssl -lcrypto -lACE_SSL -lACE -lACEXML_Parser -lACEXML -lpthread -lboost_system -lboost_thread -lboost_system -lboost_thread -lACEXML -lACEXML_Parser -ldl -lssl -lcrypto ../libeap/libeap.la ../libeap/libeaparchie.la ../libeap/libeapgpsk.la -lboost_system -lboost_thread -lACEXML -lACEXML_Parser -ldl -lssl -lcrypto
libtool: link: g++ -I/usr/include/openssl -o .libs/md5_test tests/md5_test.o -L/usr/lib /usr/lib/libACE_SSL.so /usr/lib/libACE.so -lpthread ../libeap/.libs/libeap.so ../libeap/.libs/libeaparchie.so ../libeap/.libs/libeapgpsk.so -lboost_system -lboost_thread /usr/lib/libACEXML.so /usr/lib/libACEXML_Parser.so -ldl -lssl -lcrypto
../libeap/.libs/libeap.so: undefined reference to `MD5#OPENSSL_1.0.0'
../libeap/.libs/libeap.so: undefined reference to `RAND_bytes#OPENSSL_1.0.0'
collect2: ld returned 1 exit status
Here is the Makefile.am responsible for this:
## Process this file with automake to produce Makefile.in
srcdir = #srcdir#
VPATH = #srcdir#
AM_CPPFLAGS = #L_CPPFLAGS# \
-I#top_srcdir#/include \
-I#top_srcdir#/libeap/include \
-D#HOST_OS#
AM_LDFLAGS = #L_LDFLAGS#
if compile_EAPTLS
CORE_SRC = eapcore/eap_fsm.cxx \
eapcore/eap_peerfsm.cxx \
eapcore/eap_authfsm.cxx \
eapcore/eap_standalone_authfsm.cxx \
eapcore/eap_backend_authfsm.cxx \
eapcore/eap_passthrough_authfsm.cxx \
eapcore/eap_identity.cxx \
eapcore/eap_method_registrar.cxx \
eapcore/eap_policy.cxx \
eapcore/eap_notification.cxx \
eapcore/eap_md5.cxx
CORE_HDR = include/eap_api.h \
include/eap.hxx \
include/eap_authfsm.hxx \
include/eap_fsm.hxx \
include/eap_identity.hxx \
include/eap_log.hxx \
include/eap_md5.hxx \
include/eap_method_registrar.hxx \
include/eap_notification.hxx \
include/eap_parser.hxx \
include/eap_peerfsm.hxx \
include/eap_policy.hxx \
include/eap_archie_crypto.hxx \
include/eap_archie_fsm.hxx \
include/eap_archie_parser.hxx \
include/eap_archie.hxx \
include/eap_gpsk_crypto.hxx \
include/eap_gpsk_fsm.hxx \
include/eap_gpsk_parser.hxx \
include/eap_gpsk.hxx \
include/eap_tls.hxx \
include/eap_tls_mng.hxx \
include/eap_tls_session.hxx \
include/eap_tls_parser.hxx \
include/eap_tls_fsm.hxx \
include/eap_tls_xml_data.hxx \
include/eap_tls_xml_parser.hxx \
include/eap_tls_data_defs.hxx
else
CORE_SRC = eapcore/eap_fsm.cxx \
eapcore/eap_peerfsm.cxx \
eapcore/eap_authfsm.cxx \
eapcore/eap_standalone_authfsm.cxx \
eapcore/eap_backend_authfsm.cxx \
eapcore/eap_passthrough_authfsm.cxx \
eapcore/eap_identity.cxx \
eapcore/eap_method_registrar.cxx \
eapcore/eap_policy.cxx \
eapcore/eap_notification.cxx \
eapcore/eap_md5.cxx
CORE_HDR = include/eap_api.h \
include/eap.hxx \
include/eap_authfsm.hxx \
include/eap_fsm.hxx \
include/eap_identity.hxx \
include/eap_log.hxx \
include/eap_md5.hxx \
include/eap_method_registrar.hxx \
include/eap_notification.hxx \
include/eap_parser.hxx \
include/eap_peerfsm.hxx \
include/eap_policy.hxx \
include/eap_archie_crypto.hxx \
include/eap_archie_fsm.hxx \
include/eap_archie_parser.hxx \
include/eap_archie.hxx \
include/eap_gpsk_crypto.hxx \
include/eap_gpsk_fsm.hxx \
include/eap_gpsk_parser.hxx \
include/eap_gpsk.hxx
endif
ARCHIE_SRC = eap-archie/eap_archie_fsm.cxx
GPSK_SRC = eap-gpsk/eap_gpsk_fsm.cxx
if compile_EAPTLS
TLS_SRC = eap-tls/eap_tls_mng.cxx \
eap-tls/eap_tls_crypto.cxx \
eap-tls/eap_tls_fsm.cxx \
eap-tls/eap_tls_xml_data.cxx \
eap-tls/eap_tls_xml_parser.cxx
endif
includedir = $(prefix)/include/opendiameter/eap
include_HEADERS = $(CORE_HDR)
sysconfdir = $(prefix)/etc/opendiameter/eap
sysconf_DATA = config/client.eap-tls.xml \
config/server.eap-tls.xml
if compile_EAPTLS
lib_LTLIBRARIES = libeap.la libeaparchie.la libeapgpsk.la libeaptls.la
else
lib_LTLIBRARIES = libeap.la libeaparchie.la libeapgpsk.la
endif
libeap_la_SOURCES = $(CORE_SRC) $(CORE_HDR)
libeaparchie_la_SOURCES = $(ARCHIE_SRC)
libeapgpsk_la_SOURCES = $(GPSK_SRC)
if compile_EAPTLS
libeaptls_la_SOURCES = $(TLS_SRC)
endif
libeap_la_LIBADD = -ldl -lssl -lcrypto
libeap_la_LDFLAGS = -version-info 1:0:0 -lssl -lcrypto
libeap_la_AR = $(AR) -qcs
libeaparchie_la_LDFLAGS = -version-info 1:0:0
libeaparchie_la_AR = $(AR) -qcs
libeapgpsk_la_LDFLAGS = -version-info 1:0:0
libeapgpsk_la_AR = $(AR) -qcs
if compile_EAPTLS
libeaptls_la_LDFLAGS = -version-info 1:0:0
libeaptls_la_AR = $(AR) -qcs
LDADD = #L_LIBS# \
$(top_builddir)/libeap/libeap.la \
$(top_builddir)/libeap/libeaparchie.la \
$(top_builddir)/libeap/libeapgpsk.la \
$(top_builddir)/libeap/libeaptls.la \
$(top_builddir)/libdiamparser/libdiamparser.la
else
LDADD = #L_LIBS# \
$(top_builddir)/libeap/libeap.la \
$(top_builddir)/libeap/libeaparchie.la \
$(top_builddir)/libeap/libeapgpsk.la
endif
if compile_EAPTLS
noinst_PROGRAMS = md5_test archie_test gpsk_test tls_test
else
noinst_PROGRAMS = md5_test archie_test gpsk_test
endif
md5_test_SOURCES = tests/md5_test.cxx -lssl -lcrypto
archie_test_SOURCES = tests/archie_test.cxx
gpsk_test_SOURCES = tests/gpsk_test.cxx
if compile_EAPTLS
tls_test_SOURCES = tests/tls_test.cxx
endif
EXTRA_DIST = config
I suspect autotools isn't doing something because I haven't specified it to do so. Inside of the file md5_test.c, but it still errors.
#include <openssl/md5.h>
#include <openssl/rand.h>
Any help would be greatly appreciated.
Edit:
I dug into the libraries to see if there was versioning information and it led me to this very interesting predicament - openssl 1.0.0m when compiled with this command: ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib shared
Generates two sets of shared objects located in:
/usr/lib/x86_64-linux-gnu/
/usr/lib
The shared objects in /usr/lib/x86_64-linux-gnu/ Produce a version (used objdump -T)
00000000001546b0 g DF .text 0000000000000108 OPENSSL_1.0.0 PKCS7_to_TS_TST_INFO
The shared objects in /usr/lib produce this:
000000000012ee20 g DF .text 000000000000000c Base BIO_new_CMS
How would one fix this because this seems highly unstandard....?
Remove -lssl -lcrypto from the LDFLAGS for your libraries; the way the link editor works, LDFLAGS are passed before the object files, and that means they are discarded; in at least some version of the link editor, the libraries passed before object files are also "blacklisted", or to be precise, they get ignored when passed again.
You're passing -lssl -lcrypto twice in both LDFLAGS and LIBADD so you may be triggering that behaviour.
EDIT
Hey,
For anyone else having a similar issue, I figured something of a work around out. If you just compile this using :
gcc `pkg-config --cflags opencv` CameraMotionTest.cpp `pkg-config --libs opencv` -o cammotion
instead of the makefile that I used, it compiles correctly. I'm not exactly sure what was wrong with the method I was using before still so if someone still wants to comment on that go ahead.
After doing this i found some other issues in the code that needed fixed as well but those didn't have anything to do with this question so I won't go into them here.
Thanks!
ORIGINAL
I am trying to compile a short code for camera motion estimation on Ubuntu using openCV but am running into and "undefined reference" error for one of the openCV functions (and only one). The error I get when I try to compile is as follows:
g++ CameraMotionTest.cpp -lopencv_video -lopencv_calib3d -lopencv_imgproc -lopencv_objdetect -lopencv_features2d -lopencv_core -lopencv_highgui -lopencv_videostab -lopencv_contrib -lopencv_flann -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_gpu -lopencv_ocl -o CameraMotion
/tmp/ccdHB3Pr.o: In function `main':
CameraMotionTest.cpp:(.text+0x77f): undefined reference to `cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray
const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::Size_<int>, int, cv::TermCriteria, int, double)'
collect2: ld returned 1 exit status
make: *** [CameraMotion] Error 1
I am using this makefile to try and compile and run the program:
all: run
run: CameraMotion
./CameraMotion *.jpg
CameraMotion: CameraMotionTest.cpp
g++ CameraMotionTest.cpp -lopencv_video -lopencv_calib3d -lopencv_imgproc -lopencv_objdetect -lopencv_features2d -lopencv_core -lopencv_highgui -lopencv_videostab -lopencv_contrib -lopencv_flann -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_gpu -lopencv_ocl -o CameraMotion
Finally, the code I am trying to compile is:
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/tracking.hpp>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#include <iostream>
#include <stdio.h>
#include <fstream>
using namespace std;
using namespace cv;
int main(int argc, const char** argv){
//storing the image in a temporary variable
vector<Mat> img;
int noi=5;
for( int index=0; index<noi;index++){
img.push_back(imread(argv[index+1]));
}
Mat im1=img[0];
//converting image to grayscale
cvtColor(im1,im1,CV_RGB2GRAY);
//initializing variable
vector<Point2f> corners1, corners2;
//setting parameters for corner detection
int maxCorner=200;
double quality=0.01;
double minDist=20;
int blockSize=3;
double k=0.04;
Mat mask;
vector<uchar> status;
vector<float> track_err;
int maxlevel=3;
Mat im2=img[1];
TermCriteria termcrit(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS,20,.03);
vector<Point2f> pointskept1,pointskept2;
vector<int>pointskeptindex;
Mat F,E,R,tran;
Matx33d W(0,-1,0,
1,0,0,
0,0,1);
Matx33d Winv(0,1,0,
-1,0,0,
0,0,1);
OutputArray statF=noArray();
float fx=951.302687761842550;
float fy=951.135570101293520;
float cx=484.046807724895250;
float cy=356.325026020307800;
float alpha=0;
float kmatdata[3][3]={{fx,fy*tan(alpha),cx},{0,fy,cy},{0,0,1}};
Mat K(3,3,CV_32FC1,kmatdata);
cout<<K<<endl;
ofstream myfile;
//collecting new images, determining corners, and calculating optical flow
for (int i=1; i<noi-1; i++) {
//capturing next image
//converting new image to grayscale
cvtColor(im2,im2,CV_RGB2GRAY);
//determining corner features
goodFeaturesToTrack(im1,corners1, maxCorner, quality, minDist, mask, blockSize, false,k);
goodFeaturesToTrack(im2,corners2, maxCorner, quality, minDist, mask, blockSize, false,k);
//calculating optical flow
calcOpticalFlowPyrLK(im1,im2,corners1,corners2,status,track_err,Size(10,10),maxlevel,termcrit,0.0001);
//filtering points
for(int t=0; t<status.size();i++){
if(status[t] && track_err[i]<12.0){
pointskeptindex.push_back(i);
pointskept1.push_back(corners1[i]);
pointskept2.push_back(corners2[i]);
} else {
status[i]=0;
}
}
F=findFundamentalMat(pointskept1,pointskept2,FM_RANSAC,1,0.99,statF);
E=K.t()*F*K;
SVD svd(E);
R=svd.u*Mat(W)*svd.vt;
tran=svd.u.col(2);
//renaming new image to image 1
im2.copyTo(im1);
im2=img[i+1];
myfile.open("output.txt", ios_base::app);
myfile<<"Rotation mat: ";
for(int l=0;l<R.rows;l++){
for(int m=0; m<R.cols; m++){
myfile<<R.at<float>(i,m)<<", ";
}
}
myfile<<"Translation vector: ";
for(int l=0; l<tran.rows;l++){
myfile<<tran.at<float>(l,1)<<", ";
}
myfile<<"\n";
myfile.close();
}
return 0;
}
Has anyone else run into a problem like this? I am assuming that there is just a linking error somewhere but I am quite frankly pretty new to opencv and c++ in general and i haven't been able to figure out what is wrong yet.
Thanks!
Andrew
For anyone else having a similar issue, I figured something of a work around out. If you just compile this using :
gcc `pkg-config --cflags opencv` CameraMotionTest.cpp `pkg-config --libs opencv` -o cammotion
instead of the makefile that I used, it compiles correctly. I'm not exactly sure what was wrong with the method I was using before still so if someone still wants to comment on that go ahead.
After doing this i found some other issues in the code that needed fixed as well but those didn't have anything to do with this question so I won't go into them here.
Thanks!
It seems that You have some problem with Your OpenCV instalation. To compile Your code, on OpenCV 2.4.9, it was enough to use
g++ t1.cpp -lopencv_video -lopencv_core -lopencv_objdetect -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -o CameraMotion
You can also try using nm -g <library> | grep -i <function_name> to check if Your libopencv_video.so contains calcOpticalFlowPyrLK... (based on this answer).