我正在尝试在最新的Apple Sillicon M1芯片上为我们的iOS应用程序添加测试。我们的应用程序对第三方库的依赖之一是对Ceres-Solver的依赖。我已经尝试了几天来为最新的平台编译ceres,但我所有的尝试都失败了。
所以我们使用CMake生成构建文件,然后我尝试用Xcode和xcodebuild编译。构建是成功的,但是每当我尝试将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.
我觉得这很奇怪,因为我确实是在Xcode中构建的,并且在编译ceres和我们的应用程序时,我的目标是同一个平台("My Mac")。我的一个怀疑是,我在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我尝试为新的苹果目标添加标志:-DCMAKE_C_FLAGS="-target x86_64-apple-ios13.0-macabi",但没有任何效果,因为当我检查输出时,我看到用-target arm64-apple-macos11.1调用的clang。在构建设置过程中,我也得到了一个错误:
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我也尝试过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 }所以我的想法已经用完了,如果有人能帮我,我将非常感激。值得一提的是,我在macOS Big Sur11.1上使用Xcode12.4版本
非常感谢
发布于 2021-03-02 00:33:29
经过进一步的研究,我想出了如何让它工作,以防有人遇到同样的问题。我最终阅读了这个问题描述(link),并使我认为我应该尝试使用不同的代码生成器。我的cmake配置是正确的,但是显然使用XCode (这里是-G"$GENERATOR_NAME" )作为代码生成器有一个错误。在我设置了GENERATOR_NAME=Ninja之后,我设法编译了一个适用于Mac Catalyst的库版本。
https://stackoverflow.com/questions/65941596
复制相似问题