我在本地安裝的庫存在問題。在我的項目存在XMLRPC++的0.7庫:如何通過CMake找到特定/本地文件
myproject/
+-- xmlrpc++0.7/
+-- src/
我想CMake的使用本地XMLRPC,如果沒有找到,否則回退到++目錄0.7。兩個問題,第一個,find_path()或find_library()不適用於本地目錄。如果find_xxx()處理的變量是空的,我使用變通方法測試。如果爲空,我手動設置它們。 cmake現在生成沒有錯誤的Makefile。但是如果我想通過make編譯項目,C++編譯器將返回「error:XmlRpc.h:file not found」。文件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 tesseract find_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 stuff if (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 together include_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)
Thx。這解釋了編譯錯誤。但本地路徑的問題仍然存在。如果我註釋瞭解決方法,路徑將被設置爲空。 BTW。
xmlrpc.h
和xmlrpcserver.h
位於相同的目錄中 – 2011-01-11 15:28:44