Ask Your Question

Revision history [back]

Compile static application

I want to make my openCV application portable somehow. So far i have compiled opencv with the BUILD_SHARED_LIBS=OFF command successfully, and the resulting folder containes the precious ".a" files. when i compile my application with the following command:

g++ -o atafut -std=c++11 -I /home/moritz/opencv/opencv-4.1.0-built/include/opencv4 --static -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_videoio -O0 -g -pthread main.cpp

i get the errors

/usr/bin/ld: cannot find -lopencv_core

/usr/bin/ld: cannot find -lopencv_imgproc

/usr/bin/ld: cannot find -lopencv_highgui

/usr/bin/ld: cannot find -lopencv_imgcodecs

/usr/bin/ld: cannot find -lopencv_videoio

collect2: error: ld returned 1 exit status

when i leave out the --static flag, everything works fine, but my application is not portable.

I am a bit of a noob, so hopefully i am forgetting something obvious.