当前位置:网站首页>Cmake actual combat record (I)
Cmake actual combat record (I)
2022-06-10 14:54:00 【CV-deeplearning】
One . A simple example
The project catalogue is as follows :
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── libmy_add.so
│ ├── Makefile
│ └── my_test
├── CMakeLists.txt
├── include
│ └── my_add.h
├── my_test.cpp
└── src
└── my_add.cpp
my_add.h
#include <iostream>
int my_add(int x, int y);
my_add.cpp
#include "my_add.h"
int my_add(int x, int y)
{
return x+y;
}
my_test.cpp
#include<iostream>
#include "my_add.h"
int main()
{
int c;
c = my_add(2,3);
std::cout << "test my_add:" << c << std::endl;
std::cout << "success" << std::endl;
}
CMakeLists.txt
# Required Cmake Minimum version
cmake_minimum_required(VERSION 3.18)
# Project name
project(my_test)
set(CMAKE_CXX_STANDARD 11)
set(my_add ${
PROJECT_SOURCE_DIR}/src/my_add.cpp)
include_directories("${PROJECT_SOURCE_DIR}/include")
# Generating shared libraries
add_library(my_add SHARED ${
my_add})
# Generate executable files
add_executable(my_test my_test.cpp)
# Connect to shared library
target_link_libraries(my_test my_add)
compile
mkdir build
cd build
cmake ..
make
build There is a shared library under the folder libmy_add.so, Executable file my_test
Two . Call your own shared library file
All external dependent libraries are like this , such as opencv ,openni, eigen wait , The principle is the same , But they have been installed in the system , Can find , This one needs to be configured by ourselves .
That is, the shared library file I generated above is essentially the same as opencv The library is the same . But this shared library needs to be manually configured .
For example, I have built a new project , You need to call the above shared library libmy_add.so.
The project catalogue is as follows :
.
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── Makefile
│ └── my_test
├── CMakeLists.txt
├── include
│ └── my_add.h
├── lib
│ └── libmy_add.so
├── my_test.cpp
└── src
└── my_add.cpp
CMakeLists.txt
# Required Cmake Minimum version
cmake_minimum_required(VERSION 3.18)
# Project name
project(my_test)
set(CMAKE_CXX_STANDARD 11)
include_directories("${PROJECT_SOURCE_DIR}/include")
set(ADD_SO "${PROJECT_SOURCE_DIR}/lib/libmy_add.so")
# Generate executable files
add_executable(my_test my_test.cpp)
# Connect to shared library
target_link_libraries(my_test ${ADD_SO})
In fact, the main thing is to specify when the shared library is called , The header file used , And the location of the shared library itself , Then include the link .
3、 ... and . Call the installed shared library
Opencv Add dependencies for
such as Opencv, Its header file and .so The files have been placed in the system variables , Don't define yourself to the above ( The addresses of the header file and the shared library file in the above example are set by myself )
its CMakeLists.txt as follows :
find_package(OpenCV REQUIRED)
include_directories(${OPENCV_INCLUDE_DIRS})
target_link_libraries(MAIN ${OpenCV_LIBS})
Just look it up ,OpenCV_LIBS and OPENCV_INCLUDE_DIRS All are defined by the system , So it's easier
The project catalogue is as follows :
.
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── cv_example
│ └── Makefile
├── CMakeLists.txt
├── cv_example.cpp
└── test.jpg
cv_example.cpp
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
int main() {
std::string img_path = "../test.jgp";
cv::Mat M = cv::imread(img_path);
std::cout << "load img success" << std::endl;
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(cv_example)
set(CMAKE_CXX_STANDARD 14)
add_executable(cv_example cv_example.cpp)
find_package(OpenCV REQUIRED)
include_directories(${
OPENCV_INCLUDE_DIRS})
target_link_libraries(cv_example ${
OpenCV_LIBS})
Compile implementation :
mkdir build
cd build
cmake ..
make
./cv_example
Four . A complete project CMakeLists.txt
# Project name
project(Camera_sugan)
# Compile minimum cmake edition
cmake_minimum_required(VERSION 2.6)
# Set up c++ compiler
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
# Look all over the computer opencv package
find_package(OpenCV REQUIRED)
# Include header file path
include_directories(
./include/inudev/
./src/
)
# List all source files as a collection , The collection name is SRC_LISTS
set(SRC_LISTS
./src/inuitive.cpp
./src/runCamera_Qfeeltech.cpp
)
# Generate a static library from all the source files in the collection , The name of the static library libsugan,
# Be careful , Throughout CmakeLists Use it all in libsugan This
add_library(libsugan ${
SRC_LISTS})
# Name to replace the library generated by the previous collection .
target_link_libraries(libsugan # The dependent libraries needed to link the static libraries
${
OpenCV_LIBS}
${
PROJECT_SOURCE_DIR}/lib/libCommonUtilities.so
${
PROJECT_SOURCE_DIR}/lib/libInuStreams.so
)
5、 ... and . CMake Appoint g++ Version compilation
stay CMakeLists.txt Add... Before calling the compiler in :
SET(CMAKE_C_COMPILER "/usr/local/bin/gcc")
perform cmake Before the command , stay shell The terminal first sets the following two variables :
export CXX=/usr/local/bin/g++
# /usr/local/gcc-xxx/lib It's your new gcc Of lib Location
export LD_LIBRARY_PATH=/usr/local/gcc-xxx/lib:$LD_LIBRARY_PATH
6、 ... and . Set the directory to find the dynamic library when compiling and when the program is running
Program runtime , The order in which dynamic libraries are searched ( priority ) The priority is :
- RPATH , Add... When compiling links -rpath Parameters Specified directory
- LD_LIBRARY_PATH The directory specified by this environment variable
- /etc/ld.so.conf The configuration file .
- /usr/lib 、 /lib and /usr/local/lib , System default path .
So we set up RPATH , also RPATH There is a dynamic library to be found under , The program loads it first
Be careful :
You can see ,RPATH And RUNPATH In the middle LD_LIBRARY_PATH. To allow users to modify LD_LIBRARY_PATH To specify the .so file , Most compilers will output RPATH leave a blank , And use RUNPATH Instead of RPATH.
7、 ... and . other
# Put the current directory /src The files under the , Specify in variable SRC_LIST in
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/ SRC_LIST)
add_subdirectory(my-sdk)
# Add local so
set_target_properties(decode PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib/fastertransformer.so)
Reference resources :https://blog.csdn.net/bandaoyu/article/details/115165199
https://blog.csdn.net/Guo_Python/article/details/124846646?spm=1001.2014.3001.5501
边栏推荐
- 小程序网络请求Promise化
- Gin blog summary 1
- JS get the maximum value in the array
- Kubernetes 1.24: 防止未经授权的卷模式转换
- [discrete mathematics review series] v. some special charts
- Blogger Confessions
- Basic concept of data warehouse
- Euclidean algorithm for finding the greatest common factor
- Flutter drawer learning summary 6
- STM8S103f单片机的开发(1)LED灯的点亮
猜你喜欢

2022第十五届南京国际工业自动化展览会

如何实现erp外网连接?
![[logodetection data set processing] (1) divide the data set into training set and verification set](/img/f9/422cd4b710cd57f0ebb3abd7e01c29.png)
[logodetection data set processing] (1) divide the data set into training set and verification set

2022第十五届南京国际数字化工业博览会

SIGIR 2022 | HKU and Wuhan University put forward kgcl: a recommendation system based on knowledge map comparative learning

4、再遇Panuon.UI.Silver之窗体标题栏

数据库创建触发器的问题
![[logodetection data set processing] (3) divide the training set into multiple folders by category](/img/eb/49c65f9af4c899b8cffaeec630be79.png)
[logodetection data set processing] (3) divide the training set into multiple folders by category

洞見科技入選「愛分析· 隱私計算廠商全景報告」,獲評金融解决方案代錶廠商

初试c语言之第二次笔记
随机推荐
详解OpenCV的函数filter2D(),并提醒大家它做的运算并不是卷积运算而是相关运算
[logodetection dataset processing] (4) extract the logo area of each picture
orgin框架 笔记
2022 Nanjing International Smart site equipment exhibition
CVPR 2022 oral | SCI: fast, flexible and robust low light image enhancement
超强实操!手把手教学Kinect深度图与RGB摄像头的标定与配准
KaTeX问题 —— csdn编辑时中打出等号对齐的样式
Cell asynchronously invokes method change records
One-way hash function
2022 the 14th Nanjing International artificial intelligence product exhibition
Applet network request promise
如何构建以客户为中心的产品蓝图:来自首席技术官的建议
Shutter wrap button bottomnavigationbar learning summary 4
【奖励公示】【内容共创】第16期 五月絮升华,共创好时光!签约华为云小编,还可赢高达500元礼包!
KAtex problem - the style of equal sign alignment in CSDN editing
消息中间件的消费模式
Binary tree and figure 1
产品开发的早期阶段,是选择开发app还是小程序?
2022第十五届南京国际工业自动化展览会
My first go program