问题描述
我在本地安装的库有问题。在我的项目中有xmlrpc ++ 0.7库:
I have a problem with a locally installed library. In my project there is the xmlrpc++0.7-library:
myproject /
+ - xmlrpc ++ 0.7 /
+ - src /
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,如果我手动编译所有这些工作正常。
I want that CMake fallbacks using the local xmlrpc++0.7 directory if not found otherwise. Two problems, the first one, find_path() or find_library() does not work with local dir. I used a workaround testing if variables processed by find_xxx() are empty or not. If empty I set them manually. The cmake generates the Makefile without errors now. But if I want to compile the project via make, the c++ compiler returns "error: XmlRpc.h: file not found". The file XmlRpc.h lies in myproject/xmlrpc++0.7/src and if I compile all them manually it works fine.
这里是我的CMakeLists.txt。我非常高兴,如果有人能指出正确的解决方案,在上述条件下使用cmake。
Here is my CMakeLists.txt. I am very happy if anyone could me point to the right solution to use cmake under conditions described above.
--- CMakeLists.txt ---
--- 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)
推荐答案
find_library在调用它们时不关心本地/全局路径。它将搜索您要指定的路径以查找。验证您正在搜索的路径是否正确。在您的问题中,您提到 xmlrpc ++ 0.7 ,但在您的cmakelists.txt中,您可以查找 xmlrpc0.7 ++ >这将解释为什么它没有找到。此外,正如你所说,编译器无法找到 xmlrpc.h ,但使用 xmlrpcserver.h 找到路径。
find_library does not care about local/global paths as you call them. It searches the paths where you specify it to look for. Verify that the paths you are searching for are correct. In your question you mention xmlrpc++0.7 but in your cmakelists.txt you look for xmlrpc0.7++ which would explain why it is not found. Also, as you say, the compiler fails on not finding xmlrpc.h but you use xmlrpcserver.h to find the path.
这篇关于如何通过CMake查找特定/本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!