gpt4 book ai didi

include - 如何通过 CMake 查找特定/本地文件

转载 作者:行者123 更新时间:2023-12-04 09:42:26 26 4
gpt4 key购买 nike

我对本地安装的库有疑问。在我的项目中有 xmlrpc++0.7-library:

myproject/
+-- xmlrpc++0.7/
+-- src/

如果没有找到,我希望 CMake 使用本地 xmlrpc++0.7 目录回退。有两个问题,第一个,find_path() 或 find_library() 不适用于本地目录。我使用变通方法测试 find_xxx() 处理的变量是否为空。如果为空,我手动设置它们。 cmake 现在生成的 Makefile 没有错误。但是如果我想通过 make 编译项目,c++ 编译器会返回“错误:XmlRpc.h:找不到文件”。文件 XmlRpc.h 位于 myproject/xmlrpc++0.7/src 中,如果我手动编译所有这些文件,它就可以正常工作。

这是我的 CMakeLists.txt。如果有人能指出在上述条件下使用 cmake 的正确解决方案,我将非常高兴。

--- CMakeLists.txt ---

project(webservice_tesseract)cmake_minimum_required(VERSION 2.6)set(CMAKE_INCLUDE_CURRENT_DIR ON)# find tesseractfind_path(TESSERACT_INCLUDE_DIR tesseract/tesseractmain.h        /opt/local/include /usr/local/include /usr/include )find_library(TESSERACT_LIBRARY_DIR  NAMES tesseract_main PATHS  /opt/local/lib/ /usr/local/lib/ /usr/lib )message(STATUS "looked for tesseract library.")message(STATUS "Include file detected: [${TESSERACT_INCLUDE_DIR}].")message(STATUS "Lib file detected: [${TESSERACT_LIBRARY_DIR}].")add_library(tesseract STATIC IMPORTED)set_property(TARGET tesseract PROPERTY IMPORTED_LOCATION  ${TESSERACT_LIBRARY_DIR}/libtesseractmain.a )#find xmlrpc++message(STATUS "cmake home dir: [${CMAKE_HOME_DIRECTORY}].")set(LOCAL_XMLRPCPLUSPLUS ${CMAKE_HOME_DIRECTORY}/xmlrpc0.7++/)message(STATUS "xmlrpc++ local dir: [${LOCAL_XMLRPCPLUSPLUS}].")find_path(XMLRPCPLUSPLUS_INCLUDE_DIR XmlRpcServer.h ${LOCAL_XMLRPCPLUSPLUS}src /opt/local/include /usr/local/include /usr/include )find_library(XMLRPCPLUSPLUS_LIBRARY_DIR  NAMES XmlRpc PATHS  ${LOCAL_XMLRPCPLUSPLUS} /opt/local/lib/ /usr/local/lib/ /usr/lib/ )# next lines are an ugly workaround because cmake find_xxx() does not find local stuffif (XMLRPCPLUSPLUS_INCLUDE_DIR)else (XMLRPCPLUSPLUS_INCLUDE_DIR) set(XMLRPCPLUSPLUS_INCLUDE_DIR ${LOCAL_XMLRPCPLUSPLUS}src)endif (XMLRPCPLUSPLUS_INCLUDE_DIR)if (XMLRPCPLUSPLUS_LIBRARY_DIR)else (XMLRPCPLUSPLUS_LIBRARY_DIR) set(XMLRPCPLUSPLUS_LIBRARY_DIR ${LOCAL_XMLRPCPLUSPLUS})endif (XMLRPCPLUSPLUS_LIBRARY_DIR)message(STATUS "looked for xmlrpc++ library.")message(STATUS "Include file detected: [${XMLRPCPLUSPLUS_INCLUDE_DIR}].")message(STATUS "Lib file detected: [${XMLRPCPLUSPLUS_LIBRARY_DIR}].")add_library(xmlrpc STATIC IMPORTED)set_property(TARGET xmlrpc PROPERTY IMPORTED_LOCATION  ${XMLRPCPLUSPLUS_LIBRARY_DIR}/libXmlRpc.a )#### link togetherinclude_directories(${XMLRPCPLUSPLUS_INCLUDE_DIR} ${TESSERACT_INCLUDE_DIR})link_directories(${XMLRPCPLUSPLUS_LIBRARY_DIR} ${TESSERACT_LIBRARY_DIR})add_library(simpleocr STATIC simple_ocr.cpp)add_executable(webservice_tesseract webservice.cpp)target_link_libraries(webservice_tesseract xmlrpc tesseract simpleocr)

最佳答案

问题解决了。这是我的新 CMakeLists.txt:

project(webservice_tesseract)cmake_minimum_required(VERSION 2.6)set(CMAKE_INCLUDE_CURRENT_DIR ON)# find tesseractfind_path(TESSERACT_INCLUDE_DIR tesseract/tesseractmain.h    /opt/local/include    /usr/local/include    /usr/include    )find_library(TESSERACT_LIBRARY     NAMES tesseract_main    PATHS     /opt/local/lib/    /usr/local/lib/    /usr/lib    )message(STATUS "looked for tesseract library.")message(STATUS "Include file detected: [${TESSERACT_INCLUDE_DIR}].")message(STATUS "Lib file detected: [${TESSERACT_LIBRARY}].")add_library(tesseract STATIC IMPORTED)set_property(TARGET tesseract PROPERTY IMPORTED_LOCATION     ${TESSERACT_LIBRARY}    )#find xmlrpc++message(STATUS "cmake home dir: [${CMAKE_HOME_DIRECTORY}].")set(LOCAL_XMLRPCPLUSPLUS ${CMAKE_HOME_DIRECTORY}/xmlrpc++0.7/)message(STATUS "xmlrpc++ local dir: [${LOCAL_XMLRPCPLUSPLUS}].")find_path(XMLRPCPLUSPLUS_INCLUDE_DIR XmlRpc.h    ${LOCAL_XMLRPCPLUSPLUS}src    /opt/local/include    /usr/local/include    /usr/include    )find_library(XMLRPCPLUSPLUS_LIBRARY     NAMES XmlRpc    PATHS     ${LOCAL_XMLRPCPLUSPLUS}    /opt/local/lib/    /usr/local/lib/    /usr/lib/    )message(STATUS "looked for xmlrpc++ library.")message(STATUS "Include file detected: [${XMLRPCPLUSPLUS_INCLUDE_DIR}].")message(STATUS "Lib file detected: [${XMLRPCPLUSPLUS_LIBRARY}].")add_library(xmlrpc STATIC IMPORTED)set_property(TARGET xmlrpc PROPERTY IMPORTED_LOCATION     ${XMLRPCPLUSPLUS_LIBRARY}    )#### link togetherinclude_directories(${XMLRPCPLUSPLUS_INCLUDE_DIR} ${TESSERACT_INCLUDE_DIR})link_directories(${XMLRPCPLUSPLUS_LIBRARY} ${TESSERACT_LIBRARY})add_library(simpleocr STATIC simple_ocr.cpp)add_executable(webservice_tesseract webservice.cpp)target_link_libraries(webservice_tesseract xmlrpc tesseract simpleocr)

关于include - 如何通过 CMake 查找特定/本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4658850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com