简体   繁体   English

为 Mac Catalyst 构建 ceres-solver 作为 static 库

[英]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.我正在尝试在最新的 Apple Silicon M1 芯片上为我们的 iOS 应用程序添加测试。 One of the dependency that our application has on 3rd party libraries is on the Ceres-Solver.我们的应用程序对第三方库的依赖之一是 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.几天来,我一直在尝试为最新平台编译 ceres,但我所有的尝试都失败了。

So we're generating the build files using CMake and then I tried compiling both with Xcode and with xcodebuild .所以我们使用 CMake 生成构建文件,然后我尝试使用 Xcode 和xcodebuild进行编译。 The build is successful but whenever I tried to link the libceres.a library to our application, I get a:构建成功,但每当我尝试将libceres.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.我觉得这很奇怪,因为我确实在 Xcode 中构建,并且在编译 ceres 和我们的应用程序时,我的目标是相同的平台(“我的 Mac”)。 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 命令中设置了一些错误的标志,这就是我正在运行的

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 .我尝试为新的苹果目标添加标志: -DCMAKE_C_FLAGS="-target x86_64-apple-ios13.0-macabi"但这没有任何效果,因为当我检查 output 时,我看到 clang 被称为-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 -project "Ceres.xcodeproj" -configuration "Release" -scheme "ceres" -destination "platform=macOS,variant=Mac Catalyst"但这给了我一个错误

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作为提及,我在 macOS Big Sur 11.1 上使用 Xcode 版本 12.4

Thanks a lot非常感谢

After some more researching I figured out how to make this work, in case anyone stumbles upon the same problem.经过更多研究后,我想出了如何使这项工作,以防万一有人偶然发现同样的问题。 I ended up reading this issue description ( link ) and made me think I should try and use a different code generator.我最终阅读了这个问题描述(链接)并让我认为我应该尝试使用不同的代码生成器。 My cmake configuration was correct however apparently there is a bug with using XCode as the code generator (in here -G"$GENERATOR_NAME" ).我的 cmake 配置是正确的,但显然使用XCode作为代码生成器存在错误(此处-G"$GENERATOR_NAME" )。 After I set GENERATOR_NAME=Ninja I managed to compile a version of the library that is for Mac Catalyst.在我设置GENERATOR_NAME=Ninja之后,我设法编译了一个用于 Mac Catalyst 的库版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM