ceres-solver / ceres-solver

A large scale non-linear optimization library
http://ceres-solver.org/
Other
3.66k stars 1.01k forks source link

Ceres built with miniglog but not linking with app #1025

Closed sengineering2008 closed 6 months ago

sengineering2008 commented 6 months ago

Hi @alexsmac

libceres.a and libceres_internal.a are generated and build on Xcode using the Clang LLVM toolchain for iOS. It uses the internal miniglog, however, there are link issues while building an iOS app to compute residuals.

google::LogMessage::stream(), referenced from: void ceres::AngleAxisRotatePoint(double const, double const, double) in BAFunctionCeresSolver.o ceres::internal::NumericDiff<MyToolScalarCostFunctorForBundleAdjustment, (ceres::NumericDiffMethodType)0, 2, ceres::internal::ParameterDims<false, 3, 7>, 0, 3>::EvaluateJacobianForParameterBlock(MyToolScalarCostFunctorForBundleAdjustment const, double const*, ceres::NumericDiffOptions const&, int, int, int, double*, double) in BAFunctionCeresSolver.o ceres::internal::NumericDiff<MyToolScalarCostFunctorForBundleAdjustment, (ceres::NumericDiffMethodType)0, 2, ceres::internal::ParameterDims<false, 3, 7>, 1, 7>::EvaluateJacobianForParameterBlock(MyToolScalarCostFunctorForBundleAdjustment const, double const, ceres::NumericDiffOptions const&, int, int, int, double*, double) in BAFunctionCeresSolver.o

a) the Xcode generator log says : Building for iOS : Forcing use of miniglog and tool b) otool output says logging.o object is created with libceres (static build) c) I also tried building and linking miniglog separately as a static entity d) Cmake version is 3.27.4 and iOS version is 17 e) the script in CMakeLists.txt file in internal/ceres does not install miniglog in the include directories f) in the header search paths, both the public directories are included as per your post in https://github.com/ceres-solver/ceres-solver/issues/196#issuecomment-189393058

if (MINIGLOG)

Force the miniglog headers to the front of the public include directories to protect against the case when the user has glog installed in a standard location (specifically the same as the Ceres install location) but compiled Ceres with MINIGLOG anyway. Otherwise: "glog/logging.h" in the public Ceres headers used in client code would match the installed version of glog, not the miniglog headers, and the client application would fail to link.

Note that this is an imperfect fix, as we cannot control the include directories in client projects, and they could easily invert this ordering themselves (intentionally or otherwise) and so break their build.

target_include_directories(ceres BEFORE PUBLIC $<BUILD_INTERFACE:${Ceres_SOURCE_DIR}/internal/ceres/miniglog> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ceres/internal/miniglog>

sengineering2008 commented 6 months ago

Resolved - successfully built for IOS (arm64).