问题描述
大家好,我正在为 ARM 编写一个 C++ 应用程序.我有一个应用程序原型,我用交叉编译编译了它,它在 ARM 中运行得非常好.我所做的是这样的:
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:
首先我得到了这样的 .o 文件
First I got the .o file like this
arm-linux-g++ -c PrototipoTRU.cpp
然后我得到了这样的 .exe(我的应用程序使用线程)
Then I got the .exe like this (My application use thread)
arm-linux-g++ PrototipoTRU.o -o tru2 -pthread
一切都很完美.
我的问题是当我试图编译一个使用 OpenCV 的 .cpp 文件时.我试过了:
My problem is when I tried to compile an .cpp file which use OpenCV. I tried that:
首先我尝试获取 .o:
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
我得到了 .o 文件,但很明显,当我得到 .exe 时,它在 ARM 中不起作用.我不明白的是为什么如果我在没有 opencv 的情况下编译应用程序,就像第一个示例一样,arm-linux-g++ 可以正常工作,并且当我尝试编译 openCV 应用程序时没有.
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.
我也试过这样编译:
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.
有人可以帮助我吗??
谢谢大家
dennisfen,这是 mi 文件的内容:
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}")
推荐答案
看来你需要设置你的跨 OpenCV 安装的包含路径:
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
当您调用 pkg-config 时,它会报告您的主机系统的设置,而不是您的 arm 交叉工具链.
When you call pkg-config it reports settings for you host system not for your arm cross toolchain.
这篇关于交叉编译openCV应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!