-
-
Notifications
You must be signed in to change notification settings - Fork 55.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't link OpenCV statically - attempt static link of dynamic object #14825
Comments
Why did you add |
I need to link opencv statically as I want to have to contained within my binary. It is one of the requirements for my project. |
is enough. Remove |
Thank you for the answer @alalek , and I would like to follow up. So I removed the -static option and the executable compiles and runs as desired. My ultimate goal is to create a static library of my own which I can share with others and makes use of opencv (without the recipient having opencv installed on their device). I am using the following CMakeLists.txt to generate the static library. Note that the
The issue is that when I use my Do you know what could be causing this problem. When I inspect I am therefore not sure what is causing this error. Thanks again for the help |
Just some more information for context:
And when I link
|
For static linkage you need all .a files including dependencies and dependencies of dependencies (with infinite recursion). Proper packaging of "static" bundles is very complex task. Alternatively you can try using single CMake file (project) for both your library and your app:
|
Ok, thank you for the help @alalek |
@alalek Is there a way i would need small set of libraries and want my library to by small in size? |
First off, I apologize if the answer is obvious, I am still learning.
Really appreciate the help!
System information (version)
Detailed description
I am trying to link opencv statically. When I link opencv dynamically, my program compiles and links fine. However, when I try to link statically, the get the following error:
When I go to the directory
/usr/lib/x86_64-linux-gnu/
I can see that there is indeed alibpng.a
. I am therefore confused as to why it is trying to choose the shared library instead.Note that when compiling OpenCV, I did set the following flags
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=OFF ..
Steps to reproduce
For compiling opencv:
I started on a fresh Ubuntu 18.04 VM
main.cpp
CMakeLists.txt
To compile my program
Makefile
The text was updated successfully, but these errors were encountered: