繁体   English   中英

如何强制CMake在特定目录中查找库?

[英]How can I force CMake to look for a library in a specific directory?

试图安装一个Spenvis包,这是我在运行脚本时遇到的错误:

-- Boost version: 1.41.0
-- Found the following Boost libraries:
--   python
-- Configuring done
-- Generating done
-- Build files have been written to: Desktop/build
make[2]: *** No rule to make target `/usr/local/lib64/libpython2.6.so.1.0', needed by `source/libSpenvis.so'.  Stop.
make[1]: *** [source/CMakeFiles/Spenvis.dir/all] Error 2
make: *** [all] Error 2

它在/ usr / local / lib64中寻找libpython2.6.so.1.0,但库本身在/ usr / lib64中。

我不是超级用户,因此我无法将库更改/复制到目录中,也无法建立链接。 作为参考,这是我正在运行的python脚本,后跟CMakeLists.txt文件:

"""
Main launch script
"""
import os
import sys
import shutil
from subprocess import call

"""
Define path where to find python packages
"""
loc_dir=os.getcwd()
os.chdir("python_utilities")

#Spenvis csv
#############
os.chdir("spenvis_csv")
if not os.path.exists("build"):
    os.mkdir("build")

os.chdir("build")
call("cmake ../", shell=True)
call("make")
os.chdir(loc_dir)
os.chdir("python_utilities")
if not os.path.exists("lib"):
    os.mkdir("lib")

for file_name in os.listdir("spenvis_csv/build/source"):
    if file_name.find("libSpenvis.") !=-1:
        shutil.move("spenvis_csv/build/source/%s" %(file_name),"lib/Spenvis.so") 
os.chdir("..")

和CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

# Make sure the compiler can find include files
include_directories (${PYSPENVIS_SOURCE_DIR})


# get boost
set(Boost_USE_STATIC_LIBS   OFF)
#set(Boost_USE_MULTIEADED ON)
find_package(Boost COMPONENTS
                python
             REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})

# get python
include(FindPythonLibs)

set(PythonLibs_USE_STATIC_LIBS   OFF)
find_package(PythonInterp)
find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(${PYTHON_LIBRARIES})

add_library(Spenvis  SHARED pySpenvisCSV.cc SpenvisCSV.cc SpenvisCSVCollection.cc)
TARGET_LINK_LIBRARIES(Spenvis ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

接受建议后,我在CMakeLists.txt文件的目录中运行以下命令:

cmake -DPYTHON_LIBRARY='/usr/lib64/libpython2.6.so.1.0'

这个被淘汰了:

Boost  found.
Found Boost components:
   python
-- Found PythonLibs: /usr/lib64/libpython2.6.so.1.0 (found version "2.7.1") 
-- Found PythonLibs: /usr/lib64/libpython2.6.so.1.0 (found suitable version "2.7.1", minimum required is "2.6") 
-- Configuring done
-- Generating done
-- Build files have been written to: blahblahblah

回去运行install.py程序现在返回:

-- Boost version: 1.41.0
-- Found the following Boost libraries:
--   python
-- Found PythonLibs: /usr/local/lib64/libpython2.6.so.1.0 (found version "2.6.6") 
-- Found PythonLibs: /usr/local/lib64/libpython2.6.so.1.0 (found suitable version "2.6.6", minimum required is "2.6") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/smh/Linux/Desktop/gras original/gras-03-03/python/python_utilities/spenvis_csv/build
make[2]: *** No rule to make target `/usr/local/lib64/libpython2.6.so.1.0', needed by `source/libSpenvis.so'.  Stop.

因此,返回相同的错误,只是现在声称它正在查找python库。 奇怪的是,它发现的python库不存在,也就是说,/ usr / local / lib64中没有libpython2.6.so.1.0,而是位于/ usr / lib64中。

在CMakeCache.txt中,有关所需库的行如下:

//No help, variable specified on the command line.
PYTHON_LIBRARIES:UNINITIALIZED=/usr/lib64/libpython2.6.so.1.0

//Path to a library.
PYTHON_LIBRARY:FILEPATH=/usr/lib64/libpython2.6.so

//Dependencies for the target
Spenvis_LIB_DEPENDS:STATIC=optimized;boost_python-mt-shared;debug;boost_python-mt-shared-debug;general;/usr/lib64/libpython2.6.so;

//Details about finding PythonLibs
FIND_PACKAGE_MESSAGE_DETAILS_PythonLibs:INTERNAL=[/usr/lib64/libpython2.6.so][/usr/local/include/python2.7][v2.7.1(2.6)]

/usr需要插入CMAKE_PREFIX_PATH前面,因此首先会找到它。

list(INSERT 0 CMAKE_PREFIX_PATH /usr)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM