Ask Your Question

cyhaolihai's profile - activity

2020-03-11 03:32:50 -0600 received badge  Popular Question (source)
2017-09-21 05:34:48 -0600 marked best answer 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 ...
(more)
2017-09-21 05:34:48 -0600 received badge  Scholar (source)
2017-09-21 04:38:23 -0600 received badge  Student (source)
2017-09-21 03:56:57 -0600 commented answer Why my opencv program failed to compile with static lib

I have tried your solution, but there have more faults. Please look at my answer(there have too many words, so I cannot

2017-09-21 03:47:49 -0600 edited question Why my opencv program failed to compile with static lib

Why my opencv program failed to compile with static lib I intend to use opencv2.4.11 static library for compilation, I h

2017-09-21 03:44:11 -0600 edited question Why my opencv program failed to compile with static lib

Why my opencv program failed to compile with static lib I intend to use opencv2.4.11 static library for compilation, I h

2017-09-21 03:39:28 -0600 commented question Why my opencv program failed to compile with static lib

Sorry, this is my first time to ask question in this website. I have replaced those pictures with text.

2017-09-21 03:37:02 -0600 received badge  Editor (source)
2017-09-21 03:37:02 -0600 edited question Why my opencv program failed to compile with static lib

Why my opencv program failed to compile with static lib I intend to use opencv2.4.11 static library for compilation, I h

2017-09-21 03:29:16 -0600 asked a question Why my opencv program failed to compile with static lib

Why my opencv program failed to compile with static lib I intend to use opencv2.4.11 static library for compilation, I h