我使用以下.so
编译了CmakeList.txt
文件:
cmake_minimum_required(VERSION 3.5.1)
project(phase)
SET(OpenCV_INCLUDE_DIRS "/usr/local/include/opencv")
include_directories(INCLUDE_DIR include ${OpenCV_INCLUDE_DIRS})
set(OpenCV_LIB_DIR "/usr/local/lib")
link_directories(${OpenCV_LIB_DIR})
aux_source_directory(src SOURCE)
add_library(dct SHARED src/dct.c ${SOURCE})
它没有给我任何错误。我想在Python项目中使用它:
import numpy as np
import numpy.ctypeslib as npct
from ctypes import c_int, c_double
_array_1d_floatBase = npct.ndpointer(dtype=np.float32, ndim=1, flags="CONTIGUOUS")
def _from_param(cls, obj):
if obj is None:
return obj
return _array_1d_floatBase.from_param(obj)
array_1d_float = type(
'DoubleArrayType',
(_array_1d_floatBase,),
{'from_param': classmethod(_from_param)}
)
array_1d_double = npct.ndpointer(dtype=np.double, ndim=1, flags="CONTIGUOUS")
libcd = npct.load_library("/home/facu/libdct.so", ".")
libcd.FastCosineTransform.restype = None
libcd.FastCosineTransform.argtypes = [array_1d_float, c_int, c_int, c_int]
def dct_lib(in_array, xsize, ysize, sign):
libcd.FastCosineTransform(in_array, xsize, ysize, sign)
return in_array
in_array = laplacian
print in_array
out_dct = dct_lib(in_array, 512, 512, 1)
但它给了我以下错误:
OSError: /home/facu/libdct.so: undefined symbol: cvGetSeqElem
我想我在cmake文件中遗漏了一些东西。我在内部使用OpenCV生成.so
包含哪些内容?
答案 0 :(得分:1)
我在您的CMakeLists.txt中找不到您实际调用target_link_libraries(dct opencv)
之类的内容的部分。我不确定是否存在find_package(opencv REQUIRED)
或类似的查找例程,或者如果您计划使用find_package
,是否必须构建一个例程。
你必须在某处链接库本身。到目前为止,您只是设置库所在的路径,而不是要链接的实际库名。