Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

xcode - Build ceres-solver as static library for Mac Catalyst

I'm trying to add tests for our iOS app on the newest Apple Sillicon M1 chip. One of the dependency that our application has on 3rd party libraries is on the Ceres-Solver. I've been trying for a couple of days now to compile ceres for the newest platform but all my attempts have failed.

So we're generating the build files using CMake and then I tried compiling both with Xcode and with xcodebuild. The build is successful but whenever I tried to link the libceres.a library to our application, I get a:

Building for Mac Catalyst, but the linked library 'libceresMacOS.a' was built for macOS. You may need to restrict the platforms for which this library should be linked in the target editor, or replace it with an XCFramework that supports both platforms.

I find this quite strange because I do build in Xcode and I am targeting the same platform ("My Mac") in compiling ceres and our application. One of my suspicions is that I'm setting some wrong flags in the CMake command, this is what I'm running it with

cmake $fileDir/ceres-solver 
  -G"$GENERATOR_NAME" 
  -DCMAKE_BUILD_TYPE=Release 
  -DENABLE_BITCODE=OFF 
  -DENABLE_ARC=OFF 
  -DCMAKE_INSTALL_PREFIX=$fileDir/libs-macos 
  -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=TRUE 
  -DEIGENSPARSE=ON 
  -DEIGEN_INCLUDE_DIR_HINTS=$fileDir/eigen-git-mirror 
  -DEIGEN_INCLUDE_DIR=$fileDir/eigen-git-mirror 
  -DMINIGLOG=ON 
  -DCXX11_THREADS=ON 
  -DOPENMP=OFF 
  -DTBB=OFF

I've tried adding the flags for the new apple target: -DCMAKE_C_FLAGS="-target x86_64-apple-ios13.0-macabi" but that doesn't have any effect, because when I check the output I see clang called with -target arm64-apple-macos11.1. And I also get an error during build setup:

 building for macOS-arm64 but attempting to link with file built for unknown-x86_64
    Undefined symbols for architecture arm64:
      "_main", referenced from:
         implicit entry/start for main executable
    ld: symbol(s) not found for architecture arm64

I've also tried xcodebuild -project "Ceres.xcodeproj" -configuration "Release" -scheme "ceres" -destination "platform=macOS,variant=Mac Catalyst" but this gives me an error

xcodebuild: error: Unable to find a destination matching the provided destination specifier:
        { platform:macOS, variant:Mac Catalyst }

    Available destinations for the "ceres" scheme:
        { platform:macOS, arch:arm64, id:00008103-001419A0029A001E }

    Ineligible destinations for the "ceres" scheme:
        { platform:macOS, name:Any Mac }

So I am running out of ideas here, if someone could help me out I'd be very grateful. As a mention, I'm using Xcode version 12.4 on macOS Big Sur 11.1

Thanks a lot

question from:https://stackoverflow.com/questions/65941596/build-ceres-solver-as-static-library-for-mac-catalyst

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...