Using custom built OpenCV for iOS on XCode produce

2020-03-25 06:55发布

问题:

I'm trying to use a C++ static library into my iPhone app which uses a modified version of OpenCV for iOS and I'm stuck with this issue at linking time:

Undefined symbols for architecture armv7:
  "___sincos_stret", referenced from:
      cv::initInterTab2D(int, bool) in opencv2(imgwarp.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I really do not understand what I'm missing, that function does not seem to be present in OpenCV and I do not find anything meaningful on the web; I'm wondering if it's in some mathematical library, but I haven't found anything yet.

I've compiled OpenCV with Clang and using the default libc++ library.

The libmylibrary.a and the OpenCV2 framework are correctly in the list of linked libraries.

I'm new to XCode, therefore I could have missed something trivial in the compilation of the static library and/or in the linking of it into my project.

I haven't changed the source code of that object as my changes were related to another part of the imgproc module of OpenCV, therefore I guess that this could have happen even using the default version.

Do you have any clues?

回答1:

I ran into this problem after installing the XCode 5 developer preview and building OpenCV with the build_framework.py script. ___sincos_stret appears to be coming from using the new compiler version.

I fixed this problem by changing the path to the command-line tools.

In Terminal, verify the XCode command-line path:

xcode-select --print-path

If it prints a path inside XCode5-DP.app, then switch to the tools for Xcode 4:

xcode-select --switch /Applications/XCode.app/Contents/Developer

And rebuild the framework. Then try recompiling the project.



回答2:

For fixing this problem with the Xcode 5 toolchain I specified the minimum supported iOS version as a compiler option to match the configuration in Xcode. For example:

-miphoneos-version-min=5.0

You can add this to the C and CXX flags in the makefile

CFLAGS += -miphoneos-version-min=5.0
CXXFLAGS += -miphoneos-version-min=5.0


回答3:

For those who don't want to build with lower version of XCode, try changing python build script of OpenCV iOS. In build_framework.py, I added IPHONEOS_DEPLOYMENT_TARGET=6.0 in lines and rebuilt OpenCV for iOS.

os.system("xcodebuild -parallelizeTargets ARCHS=%s -jobs 8 -sdk %s -configuration Release -target ALL_BUILD" % (arch, target.lower()))
os.system("xcodebuild ARCHS=%s -sdk %s -configuration Release -target install install" % (arch, target.lower()))

to get

os.system("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 -parallelizeTargets ARCHS=%s -jobs 8 -sdk %s -configuration Release -target ALL_BUILD" % (arch, target.lower()))
os.system("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 ARCHS=%s -sdk %s -configuration Release -target install install" % (arch, target.lower()))

For me that fixed the issue. A nice read on the symbol __sincos_stret

TODO: Though that fixes the issue, in OpenCV.xcodeproj (in build folder) generated from the python script, it still has deployment target as iOS 7.0. There might be a cleaner way.



回答4:

Per a quick search in support of Adam's question elsewhere, the symbol is defined in [path to SDK]/usr/lib/system/libsystem_m.dylib. Proof:

nm /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/lib/system/libsystem_m.dylib | grep sincos

Rather than sticking to old versions of the tools or SDK, just make sure you're linking against that.