Why my opencv program failed to compile with static lib
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()':
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] fault 1
The next text is my Makefile:
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 #dynamic lib
LIBDIRS = -L/opt/arm/arm-opencv2.4.11/lib ************************#static 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) *A* -o *B* $@$+ *C* $(OPT) *D*
The fifth line is the location of my static library. These A\B\C\D in the bottom of text 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)?
[edit] new problems showing up:
/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain ...
Sorry, this is my first time to ask question in this website. I have replaced those pictures with text.
nvm, thanks thanks a lot for complying ! now it can be properly indexed for search, etc.