{"id":7993,"date":"2024-06-27T22:01:01","date_gmt":"2024-06-27T14:01:01","guid":{"rendered":""},"modified":"2024-06-27T22:01:01","modified_gmt":"2024-06-27T14:01:01","slug":"\u3010cmake\u3011CMakeList\u6dfb\u52a0\u5e93|\u6dfb\u52a0\u5934\u6587\u4ef6|\u6dfb\u52a0\u8def\u5f84|add_executable\u3001add_library\u3001target_link_libraries|\u6dfb\u52a0\u7f16\u8bd1\u9009\u9879|\u5b8f\u5f00\u5173","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7993.html","title":{"rendered":"\u3010cmake\u3011CMakeList\u6dfb\u52a0\u5e93|\u6dfb\u52a0\u5934\u6587\u4ef6|\u6dfb\u52a0\u8def\u5f84|add_executable\u3001add_library\u3001target_link_libraries|\u6dfb\u52a0\u7f16\u8bd1\u9009\u9879|\u5b8f\u5f00\u5173"},"content":{"rendered":"

\u76ee\u5f55<\/strong><\/p>\n

\u5b98\u7f51\u67e5\u9605<\/p>\n

\u5f00\u80c3\u83dc\u4f8b\u5b50<\/p>\n

CMakeLists\u751f\u6210\u548c\u6dfb\u52a0\u4f9d\u8d56\u5e93<\/p>\n

CMakeLists\u66f4\u591a\u5c0f\u4f8b\u5b50<\/p>\n

\u751f\u6210.so\u5171\u4eab\u5e93\u6587\u4ef6<\/p>\n

\u8c03\u7528.so\u5171\u4eab\u5e93\u6587\u4ef6<\/p>\n

\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\u7684 CMakeList<\/p>\n

\u751f\u6210\u4e00\u4e2a.so\u52a8\u6001\u5e93\u7684 CMakeList <\/p>\n

CMAKE \u6dfb\u52a0\u7f16\u8bd1\u9009\u9879|-g\u7f16\u8bd1\u53c2\u6570\/\u9009\u9879<\/p>\n

\u5305\u542b\u6587\u4ef6\u7684\u7684\u76ee\u5f55include_directories<\/p>\n

\u4f18\u5316\u9879|\u4f18\u5316\u7b49\u7ea7<\/p>\n

Cmake\u8bbe\u7f6e\u4f18\u5316\u7b49\u7ea7| cmake \u751f\u6210 debug\u548c release \u7248<\/p>\n

\u8bbe\u7f6e\u9ed8\u8ba4\u6784\u5efa\u7c7b\u578b<\/p>\n

CMake\u8bbe\u7f6e\u7f16\u8bd1\u53c2\u6570\/\u9009\u9879<\/p>\n

\u5982\u4f55\u5728cmakelists\u4e2d\u52a0\u5165-ldl\u7f16\u8bd1\u9009\u9879<\/p>\n

CMake\u6307\u5b9agcc,g++\u7248\u672c\u7f16\u8bd1<\/p>\n

CMake \u5173\u95ed\u8b66\u544a\u7684\u65b9\u6cd5<\/p>\n

\u5173\u95ed\u7f16\u8bd1\u5668\u4f18\u5316<\/p>\n

CMakeLists \u5b9e\u73b0\u52a8\u6001\u5b8f\u5f00\u5173<\/p>\n

\u53bb\u6389\u7f16\u8bd1\u4f18\u5316<\/p>\n

CMake--List\u7528\u6cd5<\/p>\n

CmakeLists.txt\u5355\u884c\u6ce8\u91ca\u548c\u591a\u884c\u6ce8\u91ca <\/p>\n

CMakeList \u901a\u914d\u7b26<\/p>\n

\u5176\u4ed6\u672a\u5f52\u7c7b<\/p>\n

add_custom_target  \u81ea\u5b9a\u4e49\u547d\u4ee4<\/p>\n

add_dependencies <\/p>\n

Cmake\u6761\u4ef6\u5224\u65ad\u6307\u4ee4|if \u5224\u65ad\u4f18\u5148\u7ea7<\/p>\n

\u8bbe\u7f6e\u7f16\u8bd1\u65f6\u548c\u7a0b\u5e8f\u8fd0\u884c\u65f6\u53bb\u54ea\u4e2a\u76ee\u5f55\u627e\u52a8\u6001\u5e93<\/p>\n

#\u6307\u5b9a\u8fd0\u884c\u65f6\u52a8\u6001\u5e93\u7684\u52a0\u8f7d\u8def\u5f84<\/p>\n

#\u6307\u5b9a\u94fe\u63a5\u65f6\u52a8\u6001\u5e93\u7684\u8def\u5f84<\/p>\n

cmake install \u548c\u6253\u5305\u8bbe\u5b9a<\/p>\n

CMakeLists.txt\u5355\u884c\u6ce8\u91ca\u548c\u591a\u884c\u6ce8\u91ca<\/p>\n


\n

\u4f5c\u8005\uff1abandaoyu\uff0c\u6301\u7eed\u66f4\u65b0\uff0c\u94fe\u63a5:\u3010cmake\u3011CMakeList\u6dfb\u52a0\u5e93|\u6dfb\u52a0\u5934\u6587\u4ef6|\u6dfb\u52a0\u8def\u5f84|add_executable\u3001add_library\u3001target_link_libraries|\u6dfb\u52a0\u7f16\u8bd1\u9009\u9879|\u5b8f\u5f00\u5173_cmake\u6dfb\u52a0\u5934\u6587\u4ef6\u76ee\u5f55_bandaoyu\u7684\u535a\u5ba2-CSDN\u535a\u5ba2<\/p>\n

\u5b98\u7f51\u67e5\u9605<\/h2>\n

CMake 3.22.0-rc1\u6587\u6863\uff1ahttps:\/\/cmake.org\/cmake\/help\/latest\/search.html?q=add_library<\/p>\n

cmake-commands(7) \u2014 CMake 3.23.5 Documentation<\/p>\n

 CMake Cookbook\uff1a\u300aCMake\u83dc\u8c31\uff08CMake Cookbook\u4e2d\u6587\u7248\uff09\u300b \uff1ahttps:\/\/www.bookstack.cn\/read\/CMake-Cookbook\/content-preface-preface-chinese.md<\/p>\n<\/p>\n

\u5f00\u80c3\u83dc\u4f8b\u5b50<\/h2>\n

CMakeLists\u751f\u6210\u548c\u6dfb\u52a0\u4f9d\u8d56\u5e93<\/h3>\n

\u539f\u6587;cmake\u4e4b\u751f\u6210\u52a8\u6001\u5e93\uff1ahttps:\/\/www.cnblogs.com\/pandamohist\/p\/13408455.html<\/p>\n

1\u3001\u76ee\u5f55\u7ed3\u6784<\/strong><\/p>\n

\u2502 CMakeLists.txt \u2502 index.txt \u2502 \u251c\u2500build \u251c\u2500include \u2502 hello.h \u2502 hi.h \u2502 \u2514\u2500src hello.cxx hi.cxx<\/pre>\n

2\u3001CMakeLists.txt<\/strong><\/p>\n

cmake_minimum_required(VERSION 3.1) #\u9879\u76ee\u540d project(libhello) # 1\u3001\u6307\u5b9a\u5e93\u7684\u76ee\u5f55\u53d8\u91cf set(libhello_src src\/hello.cxx) # \u6307\u5b9a\u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84 include_directories(\"${PROJECT_SOURCE_DIR}\/include\") # 2\u3001\u6dfb\u52a0\u5e93(\u5bf9\u5e94\u7684\u4e24\u4e2a\u9879\u76ee) add_library( hello_shared SHARED ${libhello_src}) add_library( hello_static STATIC ${libhello_src}) # \u6309\u7167\u4e00\u822c\u7684\u4e60\u60ef\uff0c\u9759\u6001\u5e93\u540d\u5b57\u8ddf\u52a8\u6001\u5e93\u540d\u5b57\u5e94\u8be5\u662f\u4e00\u81f4\u7684\uff0c\u53ea\u662f\u6269\u5c55\u540d\u4e0d\u540c\uff1b # \u5373\uff1a\u9759\u6001\u5e93\u540d\u4e3a libhello.a\uff1b \u52a8\u6001\u5e93\u540d\u4e3alibhello.so \uff1b # \u6240\u4ee5\uff0c\u5e0c\u671b \"hello_static\" \u5728\u8f93\u51fa\u65f6\uff0c\u4e0d\u662f\"hello_static\"\uff0c\u800c\u662f\u4ee5\"hello\"\u7684\u540d\u5b57\u663e\u793a\uff0c\u6545\u8bbe\u7f6e\u5982\u4e0b # SET_TARGET_PROPERTIES (hello_static PROPERTIES OUTPUT_NAME \"hello\") # 3\u3001cmake\u5728\u6784\u5efa\u4e00\u4e2a\u65b0\u7684target\u65f6\uff0c\u4f1a\u5c1d\u8bd5\u6e05\u7406\u6389\u5176\u4ed6\u4f7f\u7528\u8fd9\u4e2a\u540d\u5b57\u7684\u5e93\uff0c # \u56e0\u6b64\uff0c\u5728\u6784\u5efalibhello.a\u65f6\uff0c\u5c31\u4f1a\u6e05\u7406\u6389libhello.so. # \u4e3a\u4e86\u56de\u907f\u8fd9\u4e2a\u95ee\u9898\uff0c\u6bd4\u5982\u518d\u6b21\u4f7f\u7528SET_TARGET_PROPERTIES\u5b9a\u4e49 CLEAN_DIRECT_OUTPUT\u5c5e\u6027\u3002 SET_TARGET_PROPERTIES (hello_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES (hello_shared PROPERTIES CLEAN_DIRECT_OUTPUT 1) # 4\u3001\u6309\u7167\u89c4\u5219\uff0c\u52a8\u6001\u5e93\u662f\u5e94\u8be5\u5305\u542b\u4e00\u4e2a\u7248\u672c\u53f7\u7684\uff0c # VERSION\u6307\u4ee3\u52a8\u6001\u5e93\u7248\u672c\uff0cSOVERSION\u6307\u4ee3API\u7248\u672c\u3002 SET_TARGET_PROPERTIES (hello_static PROPERTIES VERSION 1.1 SOVERSION 1) SET_TARGET_PROPERTIES (hello_shared PROPERTIES VERSION 1.1 SOVERSION 1) # 5\u3001\u82e5\u5c06libhello.a, libhello.so.x\u4ee5\u53cahello.h\u5b89\u88c5\u5230\u7cfb\u7edf\u76ee\u5f55\uff0c\u624d\u80fd\u771f\u6b63\u8ba9\u5176\u4ed6\u4eba\u5f00\u53d1\u4f7f\u7528\uff0c # \u672c\u4f8b\u4e2d\uff0c\u5c06hello\u7684\u5171\u4eab\u5e93\u5b89\u88c5\u5230<prefix>\/lib\u76ee\u5f55\uff1b # \u5c06hello.h\u5b89\u88c5<prefix>\/include\/hello\u76ee\u5f55\u3002 #INSTALL (TARGETS hello hello_shared LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) #INSTALL (TARGETS hello hello_static LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) #INSTALL (FILES hello.h DESTINATION include\/hello)<\/pre>\n

3\u3001configure and generate<\/strong><\/p>\n

xxx\/to\/path cd build cmake .. <\/pre>\n

\"\u3010cmake\u3011CMakeList\u6dfb\u52a0\u5e93|\u6dfb\u52a0\u5934\u6587\u4ef6|\u6dfb\u52a0\u8def\u5f84|add_executable\u3001add_library\u3001target_link_libraries|\u6dfb\u52a0\u7f16\u8bd1\u9009\u9879|\u5b8f\u5f00\u5173<\/p>\n

4\u3001\u5176\u4ed6\u8bbe\u7f6e<\/strong><\/p>\n

  \u82e5\u9700\u8981\u6307\u5b9a\u8f93\u51fa\u8def\u5f84\uff0c\u5c1d\u8bd5\u4e0b\u9762\u7684\u793a\u4f8b\u6307\u4ee4\uff1a<\/p>\n

# \u8bbe\u7f6eVS\u4f1a\u81ea\u52a8\u65b0\u5efaDebug\u548cRelease\u6587\u4ef6\u5939 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}\/Lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}\/Lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}\/Bin) # \u8bbe\u7f6e\u5206\u522b\u8bbe\u7f6eDebug\u548cRelease\u8f93\u51fa\u76ee\u5f55 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}\/Lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}\/Lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}\/..\/..\/build\/Debug) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}\/Lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}\/Lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}\/Bin)<\/pre>\n

CMakeLists\u66f4\u591a\u5c0f\u4f8b\u5b50<\/h3>\n

<\/h4>\n

\u751f\u6210.so\u5171\u4eab\u5e93\u6587\u4ef6<\/h4>\n

\u4e0b\u9762\u662f\u6211\u7684\u51e0\u4e2a\u6587\u4ef6:<\/p>\n

1hello.cpp<\/p>\n

\/\/hello.cpp  int Calculate_sum_Of_Two_Number(int x,int y) {    int z=0;    z=x+y;    return (z); }<\/code><\/pre>\n

2hello.hpp<\/p>\n

\/\/hello.hpp #ifndef     __HELLO_H #define     __HELLO_H int Calculate_sum_Of_Two_Number(int x,int y); #endif<\/code><\/pre>\n

3 main.cpp<\/p>\n

\/\/main.cpp #include \"hello.hpp\" #include <stdio.h> int main(void) {    int a=0,b=0,c=0;    printf(\"please input two parameter:\");    scanf(\"%d\",&a);    scanf(\"%d\",&b);    c=Calculate_sum_Of_Two_Number(a,b);    printf(\"the sum is : %d\",c);    return 0; }<\/code><\/pre>\n

4 CMakeLists.txt<\/p>\n

#\u8981\u6c42\u7684Cmake\u6700\u4f4e\u7248\u672c CMAKE_MINIMUM_REQUIRED( VERSION 2.8)   #\u5de5\u7a0b\u540d\u79f0 PROJECT(main)   #\u8bbe\u7f6e\u7f16\u8bd1\u5668\u7f16\u8bd1\u6a21\u5f0f\uff1a set( CMAKE_BUILD_TYPE \"Debug\" )   #\u751f\u6210\u5171\u4eab\u5e93 #get the shared package #here needs no .hpp add_library(calculate_shared SHARED  hello.cpp)   #\u751f\u6210\u53ef\u4ee5\u6267\u884c\u7684\u6587\u4ef6 add_executable(main main.cpp)   #\u8fde\u63a5\u5171\u4eab\u5e93 target_link_libraries(main calculate_shared)<\/code><\/pre>\n

\u4e0a\u9762CmakeLists.txt\u91cc\u9762\uff0c \u5171\u4eab\u5e93\u7684\u540d\u79f0\u662fcalculate_shared\uff0c\u8fd9\u4e2a\u662f\u6211\u4eec\u53ef\u4ee5\u81ea\u5df1\u66f4\u6539\u7684\u3002\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u662fmain, \u8fd9\u4e2a\u540d\u79f0\u4e5f\u662f\u53ef\u4ee5\u66f4\u6539\u7684\u3002<\/p>\n

\u4e0d\u8fc7\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0chello.cpp\u91cc\u9762\u4e0d\u7528\u5728\u5305\u542bhello.hpp \u4e86\u3002(\u6c57\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5bfc\u81f4\u51fa\u9519\uff0c\u63d0\u793a\u8bf4\u662f\u91cd\u590d\u5b9a\u4e49\u51fd\u6570\u4e86)\uff1b<\/p>\n

\u7f16\u8bd1\u751f\u6210:<\/p>\n

mkdir build
cd    build
cmake ..
make
\u6211\u4eec\u5c31\u53ef\u4ee5\u770b\u5230build\u751f\u6210\u4e86 \u5982\u4e0b\u7684\u6587\u4ef6:<\/p>\n

CMakeCache.txt  cmake_install.cmake     main
CMakeFiles      libcalculate_shared.so  Makefile<\/p>\n

 libcalculate_shared.so\u5c31\u662f\u751f\u6210\u7684\u5171\u4eab\u5e93\u6587\u4ef6\u3002<\/p>\n

\u4ed6\u4eec\u7684\u8def\u5f84\u662f:\/home\/fan\/dev\/cmake\/4-exer\/<\/p>\n

\u4e0b\u9762\u6709build\u6587\u4ef6\u5939\uff0c\u4ee5\u53camain.cpp, hello.cpp, hello.hpp, <\/p>\n

build\u6587\u4ef6\u5939\u4e0b\u9762\u6709\u5171\u4eab\u5e93 libcalculate_shared.so.so<\/p>\n<\/p>\n

\u8c03\u7528\u5171\u4eab\u5e93\u6587\u4ef6<\/strong><\/h4>\n

\u6240\u6709\u7684\u5916\u90e8\u4f9d\u8d56\u5e93\u90fd\u662f\u8fd9\u6837\u7684\uff0c\u6bd4\u5982opencv ,openni, eigen\u7b49\u7b49\uff0c\u539f\u7406\u662f\u4e00\u6837\u7684\uff0c\u53ea\u4e0d\u8fc7\u4ed6\u4eec\u5df2\u7ecf\u5b89\u88c5\u5728\u7cfb\u7edf\u91cc\u9762\u4e86\uff0c\u53ef\u4ee5\u67e5\u627e\uff0c\u800c\u8fd9\u4e2a\u5219\u662f\u9700\u8981\u6211\u4eec\u81ea\u5df1\u53bb\u914d\u7f6e\u3002<\/p>\n

\u5373\u6211\u4e0a\u9762\u751f\u6210\u7684\u5171\u4eab\u5e93\u6587\u4ef6\u672c\u8d28\u4e0a\u548copencv\u7684\u5e93\u662f\u76f8\u540c\u7684\u3002\u53ea\u4e0d\u8fc7\u8fd9\u4e2a\u5171\u4eab\u5e93\u9700\u8981\u81ea\u5df1\u624b\u52a8\u914d\u7f6e\u3002<\/p>\n

\u6bd4\u5982\u6211\u53c8\u65b0\u5efa\u4e86\u4e00\u4e2a\u5de5\u7a0b\uff0c\u9700\u8981\u8c03\u7528\u4e0a\u9762\u7684\u5171\u4eab\u5e93 libcalculate_shared.so\u3002<\/p>\n

main.cpp\u5982\u4e0b:<\/p>\n

\/\/main.cpp #include <stdio.h> #include <iostream> #include \"hello.hpp\" using namespace std; int main(void) {    int x=2,y=3;    int z=0;    z=Calculate_sum_Of_Two_Number(x,y);    cout<<\"the result is:\"<<z<<endl;    return 0; }<\/code><\/pre>\n

\u90a3\u4e48\u5728CMakeLists.txt\u91cc\u9762\uff0c\u6211\u9700\u8981\u544a\u8bc9CMake, \u8fd9\u4e2a\u5934\u6587\u4ef6\u53ef\u4ee5\u5728\u54ea\u91cc\u627e\u5230\uff0c\u5934\u6587\u4ef6\u6240\u5b9a\u4e49\u7684\u51fd\u6570\u53c8\u53ef\u4ee5\u5728\u54ea\u91cc\u627e\u5230\u3002<\/p>\n

\u4e0a\u9762hello.hpp\u7684\u8def\u5f84\u662f:\/home\/fan\/dev\/cmake\/4-exer\/hello.hpp<\/p>\n

libcalculate_shared.so\u7684\u8def\u5f84\u662f\/home\/fan\/dev\/cmake\/4-exer\/build\/libcalculate_shared.so<\/p>\n

\u5219CMakeLists.txt\u5982\u4e0b:<\/p>\n

CMAKE_MINIMUM_REQUIRED( VERSION 2.8)   PROJECT(main) #\u8bbe\u7f6e\u7f16\u8bd1\u5668\u7f16\u8bd1\u6a21\u5f0f\uff1a SET( CMAKE_BUILD_TYPE \"Debug\" )   SET(HELLO_INCLUE      \/home\/fan\/dev\/cmake\/4-exer\/)   SET(HELLO_SO      \/home\/fan\/dev\/cmake\/4-exer\/build\/libcalculate_shared.so)   INCLUDE_DIRECTORIES(${HELLO_INCLUE})   add_executable(main main.cpp)   target_link_libraries(main ${HELLO_SO})<\/code><\/pre>\n

\u8fd9\u91cc\u8981\u6ce8\u610f\u4e00\u4e9b\u7ec6\u8282\uff08\u5bf9\u4e8e\u6211\u8fd9\u4e2a\u6e23\u6e23\u6765\u8bf4\u7684\uff09<\/p>\n

1\u3001${   }\u8fd9\u79cd\u5f62\u5f0f\u4ee3\u8868\u4e00\u4e2a\u53d8\u91cf\uff0c\u6bd4\u5982\u4e0a\u9762\u7684\uff0cHELLO_INCLUE \uff0c\u5c31\u662f\u6211\u81ea\u5df1\u5b9a\u4e49\u7684\u4e00\u4e2a\u53d8\u91cf\u3002<\/p>\n

2\u3001\u5934\u6587\u4ef6\u5305\u542b\u5230\u5934\u6587\u4ef6\u6240\u5728\u7684\u6587\u4ef6\u5939\uff0c\u5373 \/home\/fan\/dev\/cmake\/4-exer\/<\/p>\n

3\u3001\u5171\u4eab\u5e93\u8981\u6307\u660e\u5177\u4f53\u7684\u5171\u4eab\u5e93 \uff0c\u7cbe\u786e\u5230.so<\/p>\n

\u5176\u5b9e\u4e3b\u8981\u7684\u5c31\u662f\u6307\u660e\u8fd9\u4e2a\u8c03\u7528\u8fd9\u4e2a\u5171\u4eab\u5e93\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u7684\u5934\u6587\u4ef6\uff0c\u4ee5\u53ca\u5171\u4eab\u5e93\u672c\u8eab\u6240\u5728\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u5305\u542b\u94fe\u63a5\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n

\u5b89\u88c5\u8fc7\u7684\u5171\u4eab\u5e93\uff08\u4f8b\u5982opencv\uff09\u5c31\u4e0d\u7528\u8fd9\u4e48\u9ebb\u70e6\u4e86\uff0c\u56e0\u4e3a\u5b83\u7684\u5730\u5740\u90fd\u653e\u5728\u4e86\u53d8\u91cf\u91cc\u9762\u3002<\/p>\n

Opencv\u7684\u4f9d\u8d56\u6dfb\u52a0
\u6bd4\u5982Opencv, \u5b83\u7684\u5934\u6587\u4ef6\u548c.so\u6587\u4ef6\u90fd\u5df2\u7ecf\u653e\u5728\u4e86\u7cfb\u7edf\u53d8\u91cf\u91cc\u9762\uff0c\u4e0d\u7528\u5411\u4e0a\u9762\u81ea\u5df1\u5b9a\u4e49\u4e86\uff08\u4e0a\u9762\u4f8b\u5b50\u91cc\u9762\u7684\u5934\u6587\u4ef6\u548c\u5171\u4eab\u5e93\u6587\u4ef6\u7684\u5730\u5740\u90fd\u662f\u6211\u81ea\u5df1\u8bbe\u7f6e\u7684\uff09<\/p>\n

\u5b83\u7684CMakeLists.txt\u5982\u4e0b:<\/p>\n

find_package(OpenCV REQUIRED)<\/p>\n

include_directories(${OPENCV_INCLUDE_DIRS})<\/p>\n

target_link_libraries(MAIN ${OpenCV_LIBS})<\/p>\n

\u53ea\u9700\u8981\u67e5\u627e\u5c31\u53ef\u4ee5\u4e86\uff0cOpenCV_LIBS  \u548c  OPENCV_INCLUDE_DIRS  \u90fd\u662f\u7cfb\u7edf\u5e2e\u6211\u4eec\u5df2\u7ecf\u5b9a\u4e49\u597d\u7684\uff0c\u6240\u4ee5\u6bd4\u8f83\u5bb9\u6613<\/p>\n

\u53c2\u8003\u535a\u5ba2:<\/p>\n

1\u3001\u5982\u4f55\u5199\u81ea\u5df1\u7684CmakeLists.txt   https:\/\/www.cnblogs.com\/chaofn\/p\/10160555.html<\/p>\n

2\u3001 \u3010OpenCV\u3011\u4f7f\u7528CMake\u94fe\u63a5\u81ea\u5df1\u8def\u5f84\u4e0b\u9762\u7684OpenCV\u5e93 https:\/\/blog.csdn.net\/twt520ly\/article\/details\/<\/p>\n

\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/_\/article\/details\/<\/p>\n

\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\u7684 CMakeList<\/strong><\/h4>\n
#\u6dfb\u52a0\u5305\u542b\u6587\u4ef6\u7684\u7684\u76ee\u5f55 include_directories(${cppzmq_INCLUDE_DIR})              #\u7528${SOURCE_FILES}\u6307\u5b9a\u7684\u6587\u4ef6\uff0c\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6sample_project  add_executable(sample_project ${SOURCE_FILES})  #\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6sample_project \u9700\u8981\u8fde\u63a5 ${CMAKE_THREAD_LIBS_INIT}\u6307\u5b9a\u7684\u5e93 target_link_libraries (sample_project  ${CMAKE_THREAD_LIBS_INIT})  <\/code><\/pre>\n

\u751f\u6210\u4e00\u4e2a.so\u52a8\u6001\u5e93\u7684 CMakeList <\/h4>\n
#\u7528${SRC_LISTS}\u6307\u5b9a\u7684\u6240\u6709\u7684\u6e90\u6587\u4ef6\u751f\u6210\u4e00\u4e2a\u5e93\uff0c\u540d\u5b57\u53eblibsugan add_library(libsugan ${SRC_LISTS})    #\u751f\u6210libsugan\u5e93\u9700\u8981\u94fe\u63a5 ${OpenCV_LIBS}\u3001 ${PROJECT_SOURCE_DIR}\/lib\/libCommonUtilities.so\u3001${PROJECT_SOURCE_DIR}\/lib\/libInuStreams.so target_link_libraries(libsugan                      ${OpenCV_LIBS}     ${PROJECT_SOURCE_DIR}\/lib\/libCommonUtilities.so     ${PROJECT_SOURCE_DIR}\/lib\/libInuStreams.so )<\/code><\/pre>\n

\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/bandaoyu\/article\/details\/<\/p>\n

grep -nR  \"common\"  .\/  --include=*.txt|grep -vE \"src_bak|boost|erasure-code|doc|link.txt\"<\/p>\n