Cross compile Opencv for ARM [duplicate] - c++

Hi guys I am doing an application in c++ for ARM. I have a application prototype which I compiled with cross compilation and it works very nice in the ARM. What I did was this:
First I got the .o file like this
arm-linux-g++ -c PrototipoTRU.cpp
Then I got the .exe like this (My application use thread)
arm-linux-g++ PrototipoTRU.o -o tru2 -pthread
and everything works perfect.
My problem is when I tried to compile an .cpp file which use OpenCV. I tried that:
First I tried to got the .o:
arm-linux-g++ -c camera.cpp
That does not work, I got this output:
IPCamera.cpp:5:30: error: opencv2/opencv.hpp: No such file or directory
IPCamera.cpp:6:39: error: opencv2/highgui/highgui.hpp: No such file or directory
IPCamera.cpp:7:39: error: opencv2/imgproc/imgproc.hpp: No such file or directory
IPCamera.cpp:11:22: error: X11/Xlib.h: No such file or directory
IPCamera.cpp:16: error: 'cv' is not a namespace-name
IPCamera.cpp:16: error: expected namespace-name before ';' token
IPCamera.cpp: In function 'int main(int, char**)':
IPCamera.cpp:46: error: 'cv' has not been declared
IPCamera.cpp:46: error: expected ';' before 'cap'
IPCamera.cpp:52: error: 'Display' was not declared in this scope
IPCamera.cpp:52: error: 'disp' was not declared in this scope
IPCamera.cpp:52: error: 'XOpenDisplay' was not declared in this scope
IPCamera.cpp:53: error: 'Screen' was not declared in this scope
IPCamera.cpp:53: error: 'scrn' was not declared in this scope
IPCamera.cpp:53: error: 'DefaultScreenOfDisplay' was not declared in this scope
IPCamera.cpp:63: error: 'cv' has not been declared
IPCamera.cpp:63: error: expected ';' before 'frame'
IPCamera.cpp:66: error: 'cv' has not been declared
IPCamera.cpp:66: error: 'CV_WINDOW_NORMAL' was not declared in this scope
IPCamera.cpp:68: error: 'cvMoveWindow' was not declared in this scope
IPCamera.cpp:73: error: 'CV_WND_PROP_FULLSCREEN' was not declared in this scope
IPCamera.cpp:73: error: 'CV_WINDOW_FULLSCREEN' was not declared in this scope
IPCamera.cpp:73: error: 'cvSetWindowProperty' was not declared in this scope
IPCamera.cpp:79: error: 'cap' was not declared in this scope
IPCamera.cpp:82: error: 'frame' was not declared in this scope
IPCamera.cpp:89: error: 'cv' has not been declared
IPCamera.cpp:92: error: 'cv' has not been declared
So it seem that there is some problem with the link, however if do this:
g++ -c IPCamera.cpp
I got the .o file, but obviously when I get the .exe it does not work in the ARM . What I do not undestand is why if I compile an application without opencv, like the first example, the arm-linux-g++ works propertly and when I try to compile the openCV application no.
I tried to compiler also like this:
arm-linux-g++ -c IPCamera.cpp `pkg-config opencv --libs --cflags`
but is the same result, however if I do this:
g++ -c IPCamera.cpp `pkg-config opencv --libs --cflags`
It works. So I guess that is a path problem but I do not have idea how I can solved it.
Someone can help me??
Thank you guys
Hi dennisfen this is the content of mi file:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(GCC_COMPILER_VERSION "4.6" CACHE STRING "GCC Compiler version")
set(FLOAT_ABI_SUFFIX "")
if (NOT SOFTFP)
set(FLOAT_ABI_SUFFIX "hf")
endif()
set(CMAKE_C_COMPILER arm-linux-
gnueabi${FLOAT_ABI_SUFFIX}-gcc-${GCC_COMPILER_VERSION})
set(CMAKE_CXX_COMPILER arm-linux-
gnueabi${FLOAT_ABI_SUFFIX}-g++-${GCC_COMPILER_VERSION})
set(ARM_LINUX_SYSROOT /usr/arm-linux-gnueabi${FLOAT_ABI_SUFFIX} CACHE PATH "ARM cross
compilation system root")
set(CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS "" CACHE STRING "c flags")
set(CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags")
set(CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker
flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb -fdata-sections -Wa,--noexecstack
-fsigned-char -Wno-psabi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb -fdata-sections -Wa,--noexecstack
-fsigned-char -Wno-psabi")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-
sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-
sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-
sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_EXE_LINKER_FLAGS}")

It seems that you need to set include path to your cross OpenCV installation:
arm-linux-g++ -I/path/to/opencv/include IPCamera.cpp -o tru2
When you call pkg-config it reports settings for you host system not for your arm cross toolchain.

As #dennisfen suggest you may need to set include path as well as the library path to your cross OpenCV with the libraries you are using as follows:
arm-linux-g++ -I/path/to/opencv/include -L/path/to/library IPCamera.cpp -o tru2 -lopencv_core -pthread

Related

error: command 'gcc' failed with exit status 1 while installing matplotlib

When installing matplotlib 1.3.0, getting below error
building 'matplotlib._png' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib__png_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/local/include -I/usr/include -I. -I/usr/include/libpng12 -I/usr/local/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include/python2.7 -c src/_png.cpp -o build/temp.linux-x86_64-2.7/src/_png.o
In file included from /usr/local/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1781,
from /usr/local/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
from /usr/local/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
from src/_png.cpp:28:
/usr/local/lib/python2.7/site-enter code herepackages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
src/_png.cpp: In member function ‘Py::Object _png_module::write_png(const Py::Tuple&)’:
src/_png.cpp:147: error: ‘npy_PyFile_Dup’ was not declared in this scope
src/_png.cpp:243: error: ‘npy_PyFile_DupClose’ was not declared in this scope
src/_png.cpp:264: error: ‘npy_PyFile_DupClose’ was not declared in this scope
src/_png.cpp: In member function ‘PyObject* _png_module::_read_png(const Py::Object&, bool, int)’:
src/_png.cpp:329: error: ‘npy_PyFile_Dup’ was not declared in this scope
src/_png.cpp:577: error: ‘npy_PyFile_DupClose’ was not declared in this scope
error: command 'gcc' failed with exit status 1
In other post suggested to install python-dev and it is already installed on my server.
Thank you in advance
Krishna

Error in boost library

I'm trying to compile my project, it contains many files and it need 3 libraries gsl,libxml,boost
when i give the terminal the g++ command on ubuntu 14.04LTS
g++ -Wall -I/usr/include/libxml2 -I/usr/include/gsl main.cpp YUNucNet.cpp src/*.cpp -lxml2 -lgsl -lm -lgslcblas -lboost_system -lboost_filesystem
it gives me these error
In file included from /usr/include/boost/lexical_cast.hpp:34:0,
/usr/include/c++/4.8/typeinfo:39:37: error: expected ‘}’ before end of line
#pragma GCC visibility push(default)
^
/usr/include/c++/4.8/typeinfo:39:37: error: expected unqualified-id before end of line
/usr/include/c++/4.8/typeinfo:39:37: error: expected declaration before end of line
what would be the problem ???? I can't get it .
thanx
default is a c++11 token.
You need to compile with -std=c++0x or something similar. Make sure your gcc is new enough to support such things.

Cross compilation openCV application

Hi guys I am doing an application in c++ for ARM. I have a application prototype which I compiled with cross compilation and it works very nice in the ARM. What I did was this:
First I got the .o file like this
arm-linux-g++ -c PrototipoTRU.cpp
Then I got the .exe like this (My application use thread)
arm-linux-g++ PrototipoTRU.o -o tru2 -pthread
and everything works perfect.
My problem is when I tried to compile an .cpp file which use OpenCV. I tried that:
First I tried to got the .o:
arm-linux-g++ -c camera.cpp
That does not work, I got this output:
IPCamera.cpp:5:30: error: opencv2/opencv.hpp: No such file or directory
IPCamera.cpp:6:39: error: opencv2/highgui/highgui.hpp: No such file or directory
IPCamera.cpp:7:39: error: opencv2/imgproc/imgproc.hpp: No such file or directory
IPCamera.cpp:11:22: error: X11/Xlib.h: No such file or directory
IPCamera.cpp:16: error: 'cv' is not a namespace-name
IPCamera.cpp:16: error: expected namespace-name before ';' token
IPCamera.cpp: In function 'int main(int, char**)':
IPCamera.cpp:46: error: 'cv' has not been declared
IPCamera.cpp:46: error: expected ';' before 'cap'
IPCamera.cpp:52: error: 'Display' was not declared in this scope
IPCamera.cpp:52: error: 'disp' was not declared in this scope
IPCamera.cpp:52: error: 'XOpenDisplay' was not declared in this scope
IPCamera.cpp:53: error: 'Screen' was not declared in this scope
IPCamera.cpp:53: error: 'scrn' was not declared in this scope
IPCamera.cpp:53: error: 'DefaultScreenOfDisplay' was not declared in this scope
IPCamera.cpp:63: error: 'cv' has not been declared
IPCamera.cpp:63: error: expected ';' before 'frame'
IPCamera.cpp:66: error: 'cv' has not been declared
IPCamera.cpp:66: error: 'CV_WINDOW_NORMAL' was not declared in this scope
IPCamera.cpp:68: error: 'cvMoveWindow' was not declared in this scope
IPCamera.cpp:73: error: 'CV_WND_PROP_FULLSCREEN' was not declared in this scope
IPCamera.cpp:73: error: 'CV_WINDOW_FULLSCREEN' was not declared in this scope
IPCamera.cpp:73: error: 'cvSetWindowProperty' was not declared in this scope
IPCamera.cpp:79: error: 'cap' was not declared in this scope
IPCamera.cpp:82: error: 'frame' was not declared in this scope
IPCamera.cpp:89: error: 'cv' has not been declared
IPCamera.cpp:92: error: 'cv' has not been declared
So it seem that there is some problem with the link, however if do this:
g++ -c IPCamera.cpp
I got the .o file, but obviously when I get the .exe it does not work in the ARM . What I do not undestand is why if I compile an application without opencv, like the first example, the arm-linux-g++ works propertly and when I try to compile the openCV application no.
I tried to compiler also like this:
arm-linux-g++ -c IPCamera.cpp `pkg-config opencv --libs --cflags`
but is the same result, however if I do this:
g++ -c IPCamera.cpp `pkg-config opencv --libs --cflags`
It works. So I guess that is a path problem but I do not have idea how I can solved it.
Someone can help me??
Thank you guys
Hi dennisfen this is the content of mi file:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(GCC_COMPILER_VERSION "4.6" CACHE STRING "GCC Compiler version")
set(FLOAT_ABI_SUFFIX "")
if (NOT SOFTFP)
set(FLOAT_ABI_SUFFIX "hf")
endif()
set(CMAKE_C_COMPILER arm-linux-
gnueabi${FLOAT_ABI_SUFFIX}-gcc-${GCC_COMPILER_VERSION})
set(CMAKE_CXX_COMPILER arm-linux-
gnueabi${FLOAT_ABI_SUFFIX}-g++-${GCC_COMPILER_VERSION})
set(ARM_LINUX_SYSROOT /usr/arm-linux-gnueabi${FLOAT_ABI_SUFFIX} CACHE PATH "ARM cross
compilation system root")
set(CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS "" CACHE STRING "c flags")
set(CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags")
set(CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker
flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb -fdata-sections -Wa,--noexecstack
-fsigned-char -Wno-psabi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb -fdata-sections -Wa,--noexecstack
-fsigned-char -Wno-psabi")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-
sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-
sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-
sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${CMAKE_EXE_LINKER_FLAGS}")
It seems that you need to set include path to your cross OpenCV installation:
arm-linux-g++ -I/path/to/opencv/include IPCamera.cpp -o tru2
When you call pkg-config it reports settings for you host system not for your arm cross toolchain.
As #dennisfen suggest you may need to set include path as well as the library path to your cross OpenCV with the libraries you are using as follows:
arm-linux-g++ -I/path/to/opencv/include -L/path/to/library IPCamera.cpp -o tru2 -lopencv_core -pthread

NDK: has not been declared

I am compiling the C++ code using Android native library NDK but I am getting the following errors while trying to include the g729a.h file in g729_jni.cpp:
ERRORS:
Compile++ arm : g729_jni <= g729_jni.cpp
/usr/src/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs/g729_jni/g729_jni.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -O2 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 -I/usr/src/android-ndk-r8/sources/cxx-stl/system/include -Ijni -DANDROID -O3 -Wa,--noexecstack -O2 -DNDEBUG -g -I/usr/src/android-ndk-r8/platforms/android-3/arch-arm/usr/include -c jni/g729_jni.cpp -o ./obj/local/armeabi/objs/g729_jni/g729_jni.o
In file included from jni/g729_jni.cpp:34:
jni/g729/g729a.h:70: error: 'UWord8' has not been declared
jni/g729/g729a.h:126: error: 'UWord8' has not been declared
jni/g729_jni.cpp: In function 'jint Java_org_sipdroid_codecs_G729_open(JNIEnv*, _jobject*)':
jni/g729_jni.cpp:72: error: 'UWord8' was not declared in this scope
jni/g729_jni.cpp: In function 'jint Java_org_sipdroid_codecs_G729_encode(JNIEnv*, _jobject*, _jshortArray*, jint, _jbyteArray*, jint)':
jni/g729_jni.cpp:111: error: 'UWord8' was not declared in this scope
jni/g729_jni.cpp:111: error: expected ';' before 'serial'
jni/g729_jni.cpp:125: error: 'serial' was not declared in this scope
jni/g729_jni.cpp: In function 'jint Java_org_sipdroid_codecs_G729_decode(JNIEnv*, _jobject*, _jbyteArray*, _jshortArray*, jint)':
jni/g729_jni.cpp:156: error: cannot convert 'unsigned char*' to 'int*' for argument '2' to 'void g729a_dec_process(void*, int*, Word16*, Flag)'
make: *** [obj/local/armeabi/objs/g729_jni/g729_jni.o] Error 1
I googled to try and find the reason behind this error. As C++ is case sensitive, if we make a mistake in upper and lower case, then this kind of error occurs. But I didn't make this kind of mistakes.
If you have any idea or suggestion then please guide me through that.
Thanks
UPDATE:
[root#localhost sipdroid-read-only]# /usr/src/android-ndk-r8/ndk-build V=1 APP_ABI=armeabi APP_PROJECT_PATH=. obj/local/armeabi/objs/g729_jni/g729_jni.o
make: `obj/local/armeabi/objs/g729_jni/g729_jni.o' is up to date.
Make sure your typedef.h is similar to http://siphon.googlecode.com/svn/trunk/g729a/Headers/typedef.h
Here are the steps I made to reproduce your problem:
svn checkout http://sipdroid.googlecode.com/svn/trunk/ sipdroid
cd sipdroid
sed "s/^SILK/include $(CLEAR_VARS)\\nSILK/" -i jni/Android.mk
(note that Android.mk needed a fix after line 89).
svn checkout http://siphon.googlecode.com/svn/trunk/ ../siphon
cp -d ../siphon/g729a/Headers/ jni/g729
wget http://pastie.org/pastes/4737332/download -O jni/g729/g729a.h
wget "http://sipdroid.googlecode.com/issues/attachment?aid=7963991223373796529&name=g729_jni.cpp&token=KHEZCoq6ZYSuV_VhsV8fC3uwsSs%3A1348058591979" -O jni/g729_jni.cpp
sed -e "s/g722_jni/g729_jni/" -i jni/Android.mk
ndk-build.cmd V=1 APP_ABI=armeabi APP_PROJECT_PATH=. obj/local/armeabi/objs/g729_jni/g729_jni.o
... and your file compiles with a small warning. What have you done differently?

Make Errors: Missing Includes in C++ Script?

I just got help in how to compile this script a few mintues ago on SO but I have managed to get errors. I am only a beginner in C++ and have no idea what the below erros means or how to fix it.
This is the script in question. I have read the comments from some users suggesting they changed the #include parts but it seems to be exactly what the script has, see this comment.
[root#localhost wkthumb]# qmake-qt4 && make
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -I. -o main.o main.cpp
main.cpp:5:20: error: QWebView: No such file or directory
main.cpp:6:21: error: QWebFrame: No such file or directory
main.cpp:8: error: expected constructor, destructor, or type conversion before ‘*’ token
main.cpp:11: error: ‘QWebView’ has not been declared
main.cpp: In function ‘void loadFinished(bool)’:
main.cpp:18: error: ‘view’ was not declared in this scope
main.cpp:18: error: ‘QWebSettings’ has not been declared
main.cpp:19: error: ‘QWebSettings’ has not been declared
main.cpp:20: error: ‘QWebSettings’ has not been declared
main.cpp: In function ‘int main(int, char**)’:
main.cpp:42: error: ‘view’ was not declared in this scope
main.cpp:42: error: expected type-specifier before ‘QWebView’
main.cpp:42: error: expected `;' before ‘QWebView’
make: *** [main.o] Error 1
I have the web kit on my Fedora Core 10 machine:
qt-4.5.3-9.fc10.i386
qt-devel-4.5.3-9.fc10.i386
Thanks all for any help
The error message indicates that the compiler cannot find what you're trying to include, i.e. <QWebView>. The way to tell the compiler where to look is with the -I flag, to specify include directories (these are not recursive).
Currently, you set the following include dirs:
-I/usr/lib/qt4/mkspecs/linux-g++
-I.
-I/usr/include/QtCore
-I/usr/include/QtGui
-I/usr/include
You need to find where QWebView is located on your system, and add the include path to the commandline (or install QWebView into one of the above dirs).
General note: When you get a lot of errors like this, focus on the first one or two. The later errors (such as ‘QWebView’ has not been declared) will probably be solved by fixing the missing-include error.
main.cpp:18: error: ‘view’ was not declared in this scope
Looks like namespaces have to be provided in the code. Read on namespaces.
main.cpp:20: error: ‘QWebSettings’ has not been declared
No type definition available, can be missing include.