Can't include OpenCV functions in Matlab in Linux - linux

I have a .cpp that I'm trying to mex using MATLAB R2011a in Ubuntu 14.04. The file uses some OpenCV functions and imports the correponding library:
#include <opencv/cv.h>
I'm mexing using the following command in Matlab:
mex -I/usr/local/include FaceDetect.cpp
As the opencv libraries are installed in /usr/local/include/opencv. The crash result is as follows:
Warning: You are using gcc version "4.8.2-19ubuntu1)". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
FaceDetect.o: In function `mexFunction':
FaceDetect.cpp:(.text+0xc6): undefined reference to `cvLoad'
FaceDetect.cpp:(.text+0x132): undefined reference to `cvCreateMemStorage'
FaceDetect.cpp:(.text+0x155): undefined reference to `cvCreateImage'
FaceDetect.cpp:(.text+0x23a): undefined reference to `cvHaarDetectObjects'
FaceDetect.cpp:(.text+0x285): undefined reference to `cvGetSeqElem'
FaceDetect.cpp:(.text+0x354): undefined reference to `cvReleaseImage'
FaceDetect.cpp:(.text+0x393): undefined reference to `cvClearMemStorage'
FaceDetect.cpp:(.text+0x39f): undefined reference to `cvReleaseHaarClassifierCascade'
collect2: error: ld returned 1 exit status
mex: link of ' "FaceDetect.mexa64"' failed.
??? Error using ==> mex at 208
Unable to complete successfully
I have tried compiling with -L and -lcv and it still crashes. What I am doing wrong?

The Computer Vision System Toolbox now includes a support package for OpenCV interface. It includes a library of conversion routines between MATLAB and OpenCV data types, and an easy way to compile mex functions, which use OpenCV.

Related

Embeding V8 engine in a Hello_World console application on Linux - GCC 7 linker errors (undefined references)

Here are some details:
Host/Test OS, Toolchain:
Linux Mint 19.3 Tricia (Ubuntu 18.04), GCC 7
V8 GN build arguments:
is_debug=true
target_os="linux"
target_cpu="x64"
is_clang = false
is_component_build=false
use_glib=false
use_custom_libcxx = false
v8_static_library=true
v8_enable_i18n_support=false
v8_use_external_startup_data=false
The v8 engine is successfully built and I got all expected static libraries. Then I tried to build Hello_World app (provided in v8 source), linking with generated static libs. I got the following linking errors:
/usr/bin/g++-7 -o ./build-Debug/bin/Hello_World #./build-Debug//ObjectsList.txt -L. -L../../out.gn/linux.x86_64.Debug -L../../out.gn/linux.x86_64.Debug/obj -L../../out.gn/linux.x86_64.Debug/obj/tools/debug_helper -L../../out.gn/linux.x86_64.Debug/obj/third_party/zlib -L../../out.gn/linux.x86_64.Debug/obj/third_party/zlib/google -lv8_libbase -lv8_libplatform -lv8_base_without_compiler -lv8_bigint -lv8_compiler_opt -lv8_compiler -lv8_cppgc_shared -lv8_debug_helper -lv8_init -lv8_initializers -lv8_snapshot -lchrome_zlib -ltorque_base -ltorque_ls_base -ltorque_generated_initializers -ltorque_generated_definitions -lwee8 -lcompression_utils_portable -lpthread
../../out.gn/linux.x86_64.Debug/obj/torque_generated_initializers/promise-misc-tq-csa.o: In function `v8::internal::PromiseInit_0(v8::internal::compiler::CodeAssemblerState*, v8::internal::TNode<v8::internal::JSPromise>)':
/media/hongkun/Windows/Users/hongkun/v8/v8/out.gn/linux.x86_64.Debug/gen/torque-generated/src/builtins/promise-misc-tq-csa.cc:297: undefined reference to `v8::internal::PromiseBuiltinsAssembler::ZeroOutEmbedderOffsets(v8::internal::TNode<v8::internal::JSPromise>)'
../../out.gn/linux.x86_64.Debug/obj/torque_generated_initializers/promise-misc-tq-csa.o: In function `v8::internal::InnerNewJSPromise_0(v8::internal::compiler::CodeAssemblerState*, v8::internal::TNode<v8::internal::Context>)':
/media/hongkun/Windows/Users/hongkun/v8/v8/out.gn/linux.x86_64.Debug/gen/torque-generated/src/builtins/promise-misc-tq-csa.cc:377: undefined reference to `v8::internal::PromiseBuiltinsAssembler::AllocateJSPromise(v8::internal::TNode<v8::internal::Context>)'
../../out.gn/linux.x86_64.Debug/obj/torque_generated_initializers/promise-misc-tq-csa.o: In function `v8::internal::NewJSPromise_2(v8::internal::compiler::CodeAssemblerState*, v8::internal::TNode<v8::internal::Context>, v8::Promise::PromiseState, v8::internal::TNode<v8::internal::Object>)':
/media/hongkun/Windows/Users/hongkun/v8/v8/out.gn/linux.x86_64.Debug/gen/torque-generated/src/builtins/promise-misc-tq-csa.cc:1143: undefined reference to `v8::internal::PromiseBuiltinsAssembler::ZeroOutEmbedderOffsets(v8::internal::TNode<v8::internal::JSPromise>)'
Obviously, linker cannot find the class v8::internal::PromiseBuiltinsAssembler in any of the provided libraries. I have added all generated v8 libraries in the linker options.
How can I fix this error? Thanks for any suggestions.
Neither PromiseBuiltinsAssembler nor promise-misc-tq-csa.o should go into final binaries, both are only used by mksnapshot.
Have you tried following the official documentation?

undefined reference to `__gcov_exit'?

while I am building glibc library using yocto project it is giving
error: missing attribute ((constructor)) support??
after adding the coverage flags:
TARGET_CFLAGS += "-fprofile-arcs -ftest-coverage"
TARGET_LDFLAGS += "-lgcov -fprofile-arcs -ftest-coverage"
still, I am getting an error for glibc.
Please find the link of config log file : https://drive.google.com/file/d/14tiQJ8JIFE_tDWt3H9tS8zBBQROcZDNa/view
It is not working even after adding the following line in conf/local.conf :
EXTRA_OECONF = "libc_cv_ctors_header=yes"
Even i tried this
EXTRA_OECONF_append = "libc_cv_ctors_header=yes"
please find the config log file generated during compilation : https://drive.google.com/open?id=1kxTu8pt7h_9ty55OywP9Ilmmp04T61Rr
So, How to resolve this error?
Log file error Point
poky-linux/gcc/i586-poky-linux/8.2.0/ld: /tmp/ccxetEc1.o: in function `_GLOBAL__sub_D_00100_1__start':
conftest.c:(.text.exit+0x40): undefined reference to `__gcov_exit'<br>
collect2: error: ld returned 1 exit status<br>
configure:5682: $? = 1<br>
configure:5702: error: missing __attribute__ ((constructor)) support??
You are trying to build glibc with -fprofile-arcs -ftest-coverage in CFLAGS. That will not work. The errors you see are a result of these incorrect compiler flags.
A profiling glibc requires fairly substantial changes throughout the library and needs to be created by building with --enable-profile (which is not the default).
I had this error while I tried to enable coverage on a C project using a C++ test harness (CppUTest). Build system was handled by CMake.
Compilers and gcov were aligned on the same version (gcc --version, g++ --version and gcov --version gave the same version) but it seems that my build system was generated with a gcc 5 (resulting to an additional included directory by the linker: usr/lib/gcc/x86_64-linux-gnu/5). I clean the build tree and generated it again thanks to CMake which fixed the error.

how to install xerces on linux as static library

I am using xerces for parsing the xml files.I want to make it static and use it directly in my project.so I downloaded the source and built it.which gave me all .o files and built all those .o files with my project .o files using a makefile and g++ as linker but when i did compilation i am getting liking errors like the following
/home/harsha/Desktop/xerces-c-3.1.1/src/xercesc/util/PlatformUtils.cpp:523: undefined reference to `_cxa_allocate_exception'
/home/harsha/Desktop/xerces-c-3.1.1/src/xercesc/util/PlatformUtils.cpp:523: undefined reference to `_cxa_throw'
/home/harsha/Desktop/xerces-c-3.1.1/src/xercesc/util/PlatformUtils.cpp:523: undefined reference to `_cxa_free_exception'
How can i clear these errors ?
and is -lnsl is required ?
how to install it ?

How to link to VTK library on Windows using g++

I want to use the command line to compile a simple program using the VTK library:
g++ -IC:\VTK\Install\includes\vtk-5.10 SimpleTest.cpp -LC:\VTK\Install\lib
\vtk_5.10 -lvtkCommon -lvtkGraphics
SimpleTest.cpp
#include "vtkConeSource.h"
int main()
{
vtkConeSource* cone = vtkConeSource::New();
cone->SetHeight(5.0);
return 1;
}
but I always get many errors about "undefined references". For example:
C:\VTK\Install\lib\vtk_5.10/libvtkGraphics.a(vtkConeSource.cxx.obj):vtkConeSource.cxx:(.text+0x1c): undefined reference to `vtkInformationVector::GetInformationObject(int)'
C:\VTK\Install\lib\vtk_5.10/libvtkGraphics.a(vtkConeSource.cxx.obj):vtkConeSource.cxx:(.text+0x24): undefined reference to `vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES()'
C:\VTK\Install\lib\vtk_5.10/libvtkGraphics.a(vtkConeSource.cxx.obj):vtkConeSource.cxx:(.text+0x36): undefined reference to `vtkInformation::Set(vtkInformationIntegerKey*, int)'
C:\VTK\Install\lib\vtk_5.10/libvtkGraphics.a(vtkConeSource.cxx.obj):vtkConeSource.cxx:(.text+0x85): undefined reference to `vtkPolyDataAlgorithm::PrintSelf(std::ostream&, vtkIndent)'
C:\VTK\Install\lib\vtk_5.10/libvtkGraphics.a(vtkConeSource.cxx.obj):vtkConeSource.cxx:(.text+0x9f): undefined reference to `operator<<(std::ostream&, vtkIndent const&)'
and many more ...
I can't tell if I am using wrong syntax for g++ or if there is something wrong with my VTK library.
I am using:
VTK 5.10.1
minGW 4.7.2, 32 bit
VTK was compiled from source with minGW using CMake 2.8.11.2
update:
I did find this tutorial http://vtkblog.blogspot.com/2008/05/build-vtk-from-source-using-mingwmsys.html about this. However I used minGW32-make instead of installing MSYS and using it's "make". Could this be part of the problem?
As a very first test, try explicitly including all vtk libraries contained in Install\lib\vtk_5.10 - to ensure those undefined references are not coming from those missing libraries.

Undefined reference errors when including external library libxml2 in android ndk

I'm trying to use libxml2 with android ndk. When I run the make file, I got errors saying that file 'unicode/ucnv.h' does not exist. I've seen 'unicode/ucnv.h' is included in one of the files and no such header file is present. So I downloaded unicode header files from http://site.icu-project.org/ and placed them in include folder.
Now the previous error is gone but I've got these errors.
SharedLibrary : libxml2.so
./obj/local/armeabi/objs-debug/xml2/encoding.o: In function `openIcuConverter':
C:\test\hello-jni/jni/encoding.c:109: undefined reference to `ucnv_open_49'
C:\test\hello-jni/jni/encoding.c:115: undefined reference to `ucnv_setToUCallBack_49'
C:\test\hello-jni/jni/encoding.c:119: undefined reference to `ucnv_setFromUCallBack_49'
C:\test\hello-jni/jni/encoding.c:126: undefined reference to `ucnv_open_49'
C:\test\hello-jni/jni/encoding.c:132: undefined reference to `ucnv_close_49'
C:\test\hello-jni/jni/encoding.c:135: undefined reference to `UCNV_TO_U_CALLBACK_STOP_49'
C:\test\hello-jni/jni/encoding.c:135: undefined reference to `UCNV_FROM_U_CALLBACK_STOP_49'
./obj/local/armeabi/objs-debug/xml2/encoding.o: In function `closeIcuConverter':
C:\test\hello-jni/jni/encoding.c:141: undefined reference to `ucnv_close_49'
C:\test\hello-jni/jni/encoding.c:142: undefined reference to `ucnv_close_49'
./obj/local/armeabi/objs-debug/xml2/encoding.o: In function `xmlUconvWrapper':
C:\test\hello-jni/jni/encoding.c:1865: undefined reference to `ucnv_convertEx_49'
C:\test\hello-jni/jni/encoding.c:1870: undefined reference to `ucnv_convertEx_49'
collect2: ld returned 1 exit status
make: * [obj/local/armeabi/libxml2.so] Error 1
I didn't find function ucnv_open_49 in any of the files.
Am I the only one who is facing this problem?
Build unicode library (icu) along with libxml2 and mention in LOCAL_SHARED_LIBRARIES.
That's it!
Are you intending to link libxml2 against ICU (e.g. use it for conversion)? It's optional but currently you have it enabled. With such you'll need ICU to be linked in as well rather static or dynamic. See the libxml2's configure script for options. Some of which are iconv or even no converters if you intend to work with UTF-8 only.

Resources