本帖最后由 348第二帅 于 2017-9-21 10:55 编辑
如题,本人要在IMX6Q-SDB板子上进行嵌入式开发,现在打算用opencv2.4.11的静态库进行编译, 我用交叉编译链(arm-fsl-linux-gnueabi-)(4.6.2)编译了动态库和静态库。但是当我在主机上进行静态编译时,程序报错,问题如下:chenyao@chenyao-OptiPlex-3020:~/code/test-arm$ make all
/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-g++ -c -I/opt/arm/arm-opencv2.4.11/include test.cpp -O3 -Wno-deprecated
In file included from /opt/arm/arm-opencv2.4.11/include/opencv2/flann/kmeans_index.h:50:0,
from /opt/arm/arm-opencv2.4.11/include/opencv2/flann/all_indices.h:38,
from /opt/arm/arm-opencv2.4.11/include/opencv2/flann/flann_base.hpp:44,
from /opt/arm/arm-opencv2.4.11/include/opencv2/flann/flann.hpp:50,
from /opt/arm/arm-opencv2.4.11/include/opencv/cv.h:69,
from test.cpp:3:
/opt/arm/arm-opencv2.4.11/include/opencv2/flann/logger.h:73:9: note: the mangling of 'va_list' has changed in GCC 4.4
/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-g++ -L/opt/arm/arm-opencv2.4.11/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lpthread -lrt -ldl -o test test.o -O3 -Wno-deprecated
test.o: In function `cv::Mat::~Mat()':
test.cpp.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x78): undefined reference to `cv::fastFree(void*)'
test.cpp.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x88): undefined reference to `cv::Mat::deallocate()'
test.o: In function `main':
test.cpp.text.startup+0x24): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp.text.startup+0x94): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test.cpp.text.startup+0xa0): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
test.cpp.text.startup+0xb0): undefined reference to `cv::waitKey(int)'
collect2: ld returned 1 exit status
make: *** [test] 错误 1
上面是具体的报错。下面给大家看我的Makefile:
#这里需要根据自己在linux上配置的opencv路径修改
APPNAME = test
#INCLUDES = -I/home/chenyao/opencv-arm/opencv-2.4.11/build/install/include
INCLUDES = -I/opt/arm/arm-opencv2.4.11/include
#LIBDIRS = -L/home/chenyao/opencv-arm/opencv-2.4.11/build/install/lib #动态
LIBDIRS = -L/opt/arm/arm-opencv2.4.11/lib #静态
LIBS = -lopencv_core -lopencv_imgproc -lopencv_highgui -lpthread -lrt -ldl
OPT = -O3 -Wno-deprecated
CC = /opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-g++
.PHONY: all clean
OBJS = $(APPNAME).o
clean:
rm -f *.o *~ $(APPNAME)
all(APPNAME)
echo all:make complete
%.o:%.cpp
$(CC) -c $(INCLUDES) $+ $(OPT)
$(APPNAME)(OBJS)
$(CC) $(LIBDIRS) $(LIBS) -o A $@ B $+ C $(OPT) D
红色的就是我静态库的位置,最下方红色的ABCD是我曾经插入“-static”的位置。而且当我用动态库编译的时候,是可以生成可执行文件的。下面是我的程序:
#include <iostream>
#include <stdio.h>
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
const char* imagename = "lena.jpg";
//从文件中读入图像
Mat img = imread(imagename);
//如果读入图像失败
if(img.empty())
{
cout<<"Can not load image"<<endl;
return -1;
}
//显示图像
imshow("image", img);
//此函数等待按键,按键盘任意键就返回
waitKey();
return 0;
}
我想请问大家这是什么原因造成了我静态库编译出问题了(动态库是可以的)?
|