I intend to use opencv2.4.11 static library for compilation, I have cross-compiled to generate a static library and dynamic library. But when I used static lib to compile my test program in the ubuntu operation, there happened errors (there was no problem with the dynamic library ), the problem was as follows:
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()':
`cv::Mat::~Mat()':
test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x78): undefined reference
tocv::fastFree(void)'
to `cv::fastFree(void*)'
test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x88): undefined reference to
cv::Mat::deallocate()'
`cv::Mat::deallocate()'
test.o: In
functionmain':
function `main':
test.cpp:(.text.startup+0x24): undefined reference to
cv::imread(std::basic_string<char,
`cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text.startup+0x94): undefined reference
tocv::_InputArray::_InputArray(cv::Mat to `cv::_InputArray::_InputArray(cv::Mat const&)'
test.cpp:(.text.startup+0xa0): undefined reference to
cv::imshow(std::basic_string<char,
`cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
test.cpp:(.text.startup+0xb0): undefined reference
tocv::waitKey(int)'
to `cv::waitKey(int)'
collect2: ld returned 1 exit status
make:
** *** [test] fault
11
The next text is my Makefile:
APPNAME =
test test
#INCLUDES = -I/home/chenyao/opencv-arm/opencv-2.4.11/build/install/include
INCLUDES =
-I/home/chenyao/opencv-arm/opencv-2.4.11/build/install/include INCLUDES =
-I/opt/arm/arm-opencv2.4.11/include
LIBDIRS
#LIBDIRS = -L/home/chenyao/opencv-arm/opencv-2.4.11/build/install/lib #dynamic
lib lib
LIBDIRS = -L/opt/arm/arm-opencv2.4.11/lib #static lib
LIBS = -lopencv_core -lopencv_imgproc -lopencv_highgui -lpthread -lrt
-ldl -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 $@ $+
$(OPT)$(OPT)
Draw the red horizontal line is the location of my static library, the bottom of a few arrows are where I have inserted "-static" . And when I used the dynamic library compiler, it is possible to generate executable files.
I would like to ask you why my program occurred errors when I used a static library compiler(dynamic library is possible)?