OSX Scons 构建共享库:未定义的体系结构符号 x86_64

OSX Scons building shared libraries: Undefined symbols for architecture x86_64

副标题:架构的未定义符号 x86_64:在 Mac OSX El Captain x86_64

上使用 SCons 构建 OpenCV 和 dlib

我一直在努力让我的应用程序在跨平台中构建。

我有一个 SCons 脚本,目前在 windows 上构建良好,但在 Mac.

中构建失败

我认为这是由于与新版本 XCode 的一些冲突引起的,因为我的代码和 scons 的某些先前版本运行良好(在重构之前)。

以下是报错信息,我相信是比较常见的,但是我好像没找到补救的方法。

在 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 脚本如何构建共享库的示例片段(构建静态库没有问题,只有共享库):

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 )

这是Full error log.

这是 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')

任何有关如何处理此事的帮助或建议将不胜感激!

查看您的完整构建日志,我认为您需要 link 针对多个 OSX 框架来解决您的问题。我在你的 linking 命令行中没有看到任何内容:

g++ -o out/darwin/x86_64/release/1.0.0/bin/libAPI3dfi_api_v1.dylib -ldl -lpthread -mmacosx-version-min=10.11 -DWITH_OPENEXR=OFF -dynamiclib out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Api.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_App_Manager.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_App_Params.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_App_Retry.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Device_Heartbeat.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Device_Init.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Frame_Stats.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Manager.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Session_Assign.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Session_End.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/NV3DFI_Event_Session_Start.os out/darwin/x86_64/release/1.0.0/src/api/3dfi_api_v1/src/SHA1Hash.os -L/usr/local/lib -L/opt/local/lib -Ldeps/darwin/lib/x86_64 -Lout/darwin/x86_64/release/1.0.0 -L. -Lout/darwin/x86_64/release/1.0.0/bin -Lbin -Lout/darwin/x86_64/release/1.0.0/lib -Llib -L/Users/tllewellynn/Desktop/dev/build_scons/runtime/darwin/xcode/x86_64/pthread/lib -L/Users/tllewellynn/Desktop/dev/build_scons/runtime/darwin/xcode/x86_64/intraface/lib -lSDK3dfi_detect -lSDK3dfi_algo -lSDK3dfi_au -lSDK3dfi_align -lSDK3dfi_proc -lSDK3dfi_cluster -lSDK3dfi_attr -lSDK3dfi_type -lOpencvCore -lOpencvHighgui -lOpencvImgproc -lOpencvObjdetect -lOpencvFlann -lOpencvFeature2d -lOpencvVideo -lOpencvCalib3d -lOpencvMl -lFreeimage -lFreeimageOpenEXR -lFreeimageLibTIFF -lFreeimageLibPNG -lFreeimageLibOpenJPEG -lFreeimageLibJPEG -lFreeimageLibMNG -lFreeimageZLib -lFrameworkNvaam_base -lFrameworkNvaam_filter -lFrameworkNvaam -lFrameworkProtobuf -lFrameworkLibbff -lFrameworkNvclassifier -lFrameworkNvexpression -lFrameworkTrimesh2 -lFrameworkPolyfit -lFrameworkGClasses -lFrameworkFlandmark -lFrameworkAlglib -lNetMsgpack -lNetJsoncpp -lNetTinyxml2 -lNetTinyxmlparam -lCnnEblearnTools -lCnnEblearnIdx -lCnnEblearn -lThirdPartyDlib_18_14 -lSystemTinycthread -lSystemTinythread -lSystemGlobal -lSystemDebug -lpthread -lTbb -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/

您是否在任何 openCV 论坛或 IRC 频道上询问过?

看起来您的 link 行中缺少几个关键框架。