How do I tell cmake I want my project to link libraries statically?
You build static OpenCV libraries by just setting the BUILD_SHARED_LIBS
flag to false in CMake. Then all you need to do to build your own application with those static libraries is to add a dependency on OpenCV in your CMakeLists.txt
:
FIND_PACKAGE (OpenCV REQUIRED)
...
TARGET_LINK_LIBRARIES (your-application ${OpenCV_LIBS})
and CMake will take care of everything.
How do I tell CMake to link in a static library in the source directory?
CMake favours passing the full path to link libraries, so assuming libbingitup.a is in ${CMAKE_SOURCE_DIR}
, doing the following should succeed:
add_executable(main main.cpp)
target_link_libraries(main ${CMAKE_SOURCE_DIR}/libbingitup.a)
How to link static libraries in cmake
Here is some github example.
Here is some SO question you are duplicating.
Based on that this should look like this:
cmake_minimum_required(VERSION 3.15)
project(testo)
set(CMAKE_CXX_STANDARD 17)
find_package(GLEW REQUIRED)
add_executable(testo main.cpp)
target_link_libraries(testo PUBLIC ${GLEW_LIBRARIES})
target_include_directories(testo PUBLIC ${GLEW_INCLUDE_DIRS})
How to add prebuilt static library in project using CMake?
You're probably asking about how to link your project to the pre-built static library. If so, you can do like this by calling target_link_libraries
.
Assume your project called myProj
and the pre-built library myLib.lib
, you can do like this:
target_link_libraries(myProj myLib)
Related Topics
Run Bash Command on Jenkins Pipeline
Location of .Bashrc for "Bash on Ubuntu on Windows" in Windows 10
Can You Prevent a Command from Going into the Bash Shell Command History
How to Tell Whether I'm in a Screen
Replace Whitespaces with Tabs in Linux
Which Signal Does Ctrl-X Send When Used in a Terminal
What Is Raw Socket in Socket Programming
Using Putty to Scp from Windows to Linux
Control Mouse by Writing to /Dev/Input/Mice
How Set Multiple Env Variables for a Bash Command
Convert All File Extensions to Lower-Case
How to Check the Version of Openmp on Linux
How to Read a .Properties File Which Contains Keys That Have a Period Character Using Shell Script
How to Continue One Thread at a Time When Debugging a Multithreaded Program in Gdb
Is There an Equivalent to Com on *Nix Systems ? If Not, What Was the *Nix Approach to Re-Usability
Perf_Event_Open Overflow Signal