【发布时间】:2016-07-29 16:39:44
【问题描述】:
字幕:x86_64 架构的未定义符号:在 Mac OSX El Captain x86_64 上使用 SCons 构建 OpenCV 和 dlib
我一直在尝试让我的应用在跨平台上构建。
我有一个 SCons 脚本,目前在 Windows 上构建良好,但在 Mac 中构建失败。
我认为这是由于与较新版本的 XCode 的一些冲突引起的,因为我的一些以前版本的代码和 scon 运行良好(在被重构之前)。
以下是错误信息,我相信它很常见,但我似乎无法找到补救方法。
在 OpenCV2-highgui 中,cap_avfoundation.mm
Undefined symbols for architecture x86_64:
"_AVCaptureSessionPresetMedium", referenced from:
CvCaptureCAM::startCaptureDevice(int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVFileTypeAppleM4V", referenced from:
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVFileTypeMPEG4", referenced from:
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVFileTypeQuickTimeMovie", referenced from:
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
"_AVMediaTypeVideo", referenced from:
CvCaptureCAM::startCaptureDevice(int) in libOpencvHighgui.a(cap_avfoundation.o)
CvCaptureFile::CvCaptureFile(char const*) in libOpencvHighgui.a(cap_avfoundation.o)
CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in libOpencvHighgui.a(cap_avfoundation.o)
... ... ...
在 OpenCV2-highgui 中,window_cocoa.mm
"_OBJC_CLASS_$_NSSlider", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
"_OBJC_CLASS_$_NSString", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
objc-class-ref in libOpencvHighgui.a(cap_avfoundation.o)
"_OBJC_CLASS_$_NSTextField", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
"_OBJC_CLASS_$_NSThread", referenced from:
objc-class-ref in libOpencvHighgui.a(window_cocoa.o)
"_OBJC_CLASS_$_NSURL", referenced from:
... ... ...
除了构建OpenCV,dlib_18_14,source.cpp也出现同样的错误
"_XAllocColor", referenced from:
void nativefont::font_renderer::font_renderer::vals_internal::create<unsigned int>(unsigned int*, int, bool, bool, bool, nativefont::font_renderer::font_renderer::rgb_type, nativefont::font_renderer::font_renderer::rgb_type) in libThirdPartyDlib_18_14.a(source.o)
"_XAllocSizeHints", referenced from:
dlib::base_window::set_size(int, int) in libThirdPartyDlib_18_14.a(source.o)
dlib::base_window::base_window(bool, bool) in libThirdPartyDlib_18_14.a(source.o)
dlib::gui_core_kernel_2_globals::event_handler_thread::event_handler() in libThirdPartyDlib_18_14.a(source.o)
"_XChangeProperty", referenced from:
dlib::gui_core_kernel_2_globals::event_handler_thread::event_handler() in libThirdPartyDlib_18_14.a(source.o)
"_XCheckIfEvent", referenced from:
dlib::gui_core_kernel_2_globals::event_handler_thread::event_handler() in libThirdPartyDlib_18_14.a(source.o)
"_XClearArea", referenced from:
dlib::base_window::invalidate_rectangle(dlib::rectangle const&) in libThirdPartyDlib_18_14.a(source.o)
"_XCloseDisplay", referenced from:
nativefont::font_renderer::font_renderer::vals_internal::~vals_internal() in libThirdPartyDlib_18_14.a(source.o)
dlib::gui_core_kernel_2_globals::event_handler_thread::~event_handler_thread() in libThirdPartyDlib_18_14.a(source.o)
"_XCloseIM", referenced from:
dlib::gui_core_kernel_2_globals::event_handler_thread::~event_handler_thread() in libThirdPartyDlib_18_14.a(source.o)
"_XConvertSelection", referenced from:
dlib::get_from_clipboard(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&) in libThirdPartyDlib_18_14.a(source.o)
"_XCreateFontSet", referenced from:
dlib::base_window::base_window(bool, bool) in libThirdPartyDlib_18_14.a(source.o)
void nativefont::font_renderer::font_renderer::vals_internal::create<unsigned int>(unsigned int*, int, bool, bool, bool, nativefont::font_renderer::font_renderer::rgb_type, nativefont::font_renderer::font_renderer::rgb_type) in libThirdPartyDlib_18_14.a(source.o)
... ... ...
错误总结如下:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [out/darwin/x86_64/release/1.0.0/bin/libAPI3dfi_api_v1.dylib] Error 1
scons: building terminated because of errors.
我不能在这里公开整个源代码和 scons 构建脚本,所以请注意。
这是我的 scons 脚本如何构建共享库的示例 sn-p(构建静态库没有问题,只是共享库):
Import('env')
# Add third party libraries
lib_env = env.Clone()
module_lib_env = lib_env.Clone()
target_os = env.get('TARGET_OS')
target_arch = env.get('TARGET_ARCH')
######################################################################
# Runtime Dependencies
######################################################################
pthread_path = env.get('PTHREAD_PATH') + '/lib'
intraface_path = env.get('INTRAFACE_PATH') + '/lib'
######################################################################
# General flags
######################################################################
module_lib_env.AppendUnique(CPPPATH = ['inc', 'src'])
######################################################################
# Libraries
######################################################################
module_lib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')+'/bin',env.get('BUILD_DIR')+'/lib', pthread_path, intraface_path])
if target_os == 'windows':
module_lib_env.AppendUnique(LIBS = [
'libOpencvCore',
'libOpencvHighgui',
'libOpencvImgproc',
'libOpencvObjdetect',
'libOpencvFlann',
'libOpencvFeature2d',
'libOpencvVideo',
'libOpencvCalib3d',
'libOpencvMl',
'libFreeimage',
'libFreeimageOpenEXR',
'libFreeimageLibTIFF',
#'libFreeimageLibRawLite',
'libFreeimageLibPNG',
'libFreeimageLibOpenJPEG',
'libFreeimageLibJPEG',
'libFreeimageLibMNG',
'libFreeimageZLib',
'libThirdPartyDlib_18_14',
'pthread',
'IntraFaceDLL'])
else:
module_lib_env.AppendUnique(LIBS = [
'libOpencvCore',
'libOpencvHighgui',
'libOpencvImgproc',
'libOpencvObjdetect',
'libOpencvFlann',
'libOpencvFeature2d',
'libOpencvVideo',
'libOpencvCalib3d',
'libOpencvMl',
'libFreeimage',
'libFreeimageOpenEXR',
'libFreeimageLibTIFF',
#'libFreeimageLibRawLite',
'libFreeimageLibPNG',
'libFreeimageLibOpenJPEG',
'libFreeimageLibJPEG',
'libFreeimageLibMNG',
'libFreeimageZLib',
'libThirdPartyDlib_18_14',
'pthread'
# ,'IntraFaceDLL'
])
######################################################################
# Preprocessor flags
######################################################################
if not target_os == 'windows':
#allow error to be concidered as warning
module_lib_env.AppendUnique(CCFLAGS = ['-fpermissive'])
#disable warning
module_lib_env.AppendUnique(CCFLAGS = ['-Wno-sign-compare'])
module_lib_env.AppendUnique(CCFLAGS = ['-Wno-write-strings'])
module_lib_env.AppendUnique(CCFLAGS = ['-Wno-unused-variable'])
if target_os in ['darwin', 'ios']:
module_lib_env.AppendUnique(CPPDEFINES = ['_LIBCPP_HAS_NO_VARIADICS'])
######################################################################
# Source files and Targets
######################################################################
lib_src = env.Glob('src/*.cpp')
######################################################################
# Targets
######################################################################
module_lib_env.InstallTargetShared('libOpenCV', lib_src )
InstallTargetShared 如下所示:
def __install_shared(ienv, name, srcs):
ienv.SharedLibrary(target = os.path.join(env.get('BUILD_DIR') +'/bin/', name), source = srcs)
env.AppendUnique(TS = [name])
env.AddMethod(__install_shared, 'InstallTargetShared')
任何关于如何处理此事的帮助或建议将不胜感激!
【问题讨论】:
-
什么是“InstallTargetShared”?
-
@bdbaddog InstallTargetShared 是用于创建共享库的自定义函数,在 Windows 上运行良好。
-
如果您无法在此处发布您的资源,最简单的方法是创建一个最小工作示例 (MWE) 并使用它来提出您的问题。否则我们将无法正确调试您的问题...
-
@dirkbaechle 我相信我发现的问题是使用 SCons 从源代码编译第三方库 OpenCV。我能够构建所有静态库,但是在使用 OpenCV 2.4.6 和 dlib 构建共享库时会输出上述错误,与源代码无关。
-
您可以将源发布到 InstallTargetShared 吗?或者正如 Dirk 提到的一个最小的工作示例来演示您的问题。除非我们可能无法解决您的问题。完整的构建日志怎么样?
标签: c++ xcode macos opencv scons