how to use cmake

本文介绍了CMake中几个关键变量的使用方法,包括CMAKE_INSTALL_PREFIX、CMAKE_CXX_FLAGS等,并探讨了如何正确指定编译器路径以避免版本冲突导致的编译错误。
1. cmake 的几个变量:CMAKE_INSTALL_PREFIX, CMAKE_CXX_FLAGS, CMAKE_EXE_LINKER_FLAGS
   /PROJ/GR/share/Software/cmake/current/bin/cmake ../ -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=../mybin/ -DCMAKE_CXX_FLAGS="-I/PROJ/GR/share/Software/medinfo/01bin/samtools/samtools-0.1.6" -DCMAKE_EXE_LINKER_FLAGS="-L/PROJ/GR/share/Software/medinfo/01bin/samtools/samtools-0.1.6"


常见变量
CMAKE_CXX_FLAGS
CMAKE_C_FLAGS
CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS
CMAKE_C_COMPILER
CMAKE_CXX_COMPILER


往往系统会找到/usr/bin/下的gcc,c++,可能不是正确的版本而会出现编译错误,此时需要设置CMAKE_C_COMPILER和CMAKE_CXX_COMPILER
# For more information about using CMake with Android Studio, read the # documentation: https://d.android.com/studio/projects/add-native-code.html. # For more examples on how to use CMake, see https://github.com/android/ndk-samples. # Sets the minimum CMake version required for this project. cmake_minimum_required(VERSION 3.22.1) # Declares the project name. The project name can be accessed via ${ PROJECT_NAME}, # Since this is the top level CMakeLists.txt, the project name is also accessible # with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level # build script scope). project("automate") # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK. # # In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define # the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME} # is preferred for the same purpose. # # In order to load a library into your app from Java/Kotlin, you must call # System.loadLibrary() and pass the name of the library defined here; # for GameActivity/NativeActivity derived applications, the same library name must be # used in the AndroidManifest.xml file. include_directories( include ) #add_library("libProject" SHARED project/project.cpp) # Specifies libraries CMake should link to your target library. You # can link libraries from various origins, such as libraries defined in this # build script, prebuilt third-party libraries, or Android system libraries. #配置openssl # 设置第三方库的目录,按ABI分开 set(OPENSSL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/openssl/libs/${CMAKE_ANDROID_ARCH_ABI}) # 添加头文件搜索路径(必须放在add_library之前) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/openssl) # 修复点1:显式包含 # 导入第三方静态库 # 导入OpenSSL的crypto库(动态库) add_library(crypto STATIC IMPORTED) # 设置导入库的路径,${ANDROID_ABI}是构建时对应的ABI set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_DIR}/libcrypto.a) # 导入OpenSSL的ssl库(动态库) # 导入OpenSSL的ssl库(动态库) add_library(ssl STATIC IMPORTED) set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${OPENSSL_DIR}/libssl.a) #add_library(openssl STATIC IMPORTED) #set_target_properties(openssl PROPERTIES # IMPORTED_LOCATION ${OPENSSL_DIR}/libcrypto.a # IMPORTED_LOCATION ${OPENSSL_DIR}/libssl.a #) # add_library(project SHARED project/project.cpp ) add_library(stringUtils SHARED utils/stringUtils.cpp ) add_library(fileUtils SHARED utils/fileUtils.cpp ) add_library(javaUtils SHARED utils/javaUtils.cpp ) add_library(fileShard SHARED project/FileShard.cpp ) add_library(${CMAKE_PROJECT_NAME} SHARED # List C/C++ source files with relative paths to this CMakeLists.txt. automate.cpp ) target_link_libraries(${CMAKE_PROJECT_NAME} crypto openssl project stringUtils fileUtils javaUtils fileShard android log )为何还报错ld.lld: error: undefined symbol: MD5_Init >>> referenced by stringUtils.cpp:19 (U:/code/Android/AutoMate/app/src/main/cpp/utils/stringUtils.cpp:19),配置正确了还报错
11-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值