Cross-build to any Apple OS fails

Issue #80 resolved
SpaceIm created an issue

If Apple, timer.cpp compilation unit of ODE relies on Microseconds(), a deprecated function provided by CoreServices framework.

While native build seems to handle this case out of the box even if CoreServices is not explicitly linked, when you cross-build on macOS, from Intel to M1 for example, linker fails to create ODE shared lib:

Undefined symbols for architecture arm64:
  "_Microseconds", referenced from:
      getClockCount(unsigned long*) in timer.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libode.0.16.2.dylib] Error 1
make[1]: *** [CMakeFiles/ODE.dir/all] Error 2

Moreover, it’s worth noting that this function Microseconds() is available on macOS only. Compilation of ODE for any other Apple OS (iOS for example) fails.

So a global apple fix for 0.16.2 would be:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -518,6 +518,10 @@ target_compile_definitions(

 if(APPLE)
    target_compile_definitions(ODE PRIVATE -DMAC_OS_X_VERSION=${MAC_OS_X_VERSION})
+   if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+       find_library(CORESERVICES_FW NAMES CoreServices)
+       target_link_libraries(ODE PRIVATE ${CORESERVICES_FW})
+   endif()
 endif()

 if(WIN32)
--- a/ode/src/timer.cpp
+++ b/ode/src/timer.cpp
@@ -176,7 +176,11 @@ double dTimerTicksPerSecond()

 #if !defined(PENTIUM) && !defined(WIN32)

-#ifndef macintosh
+#ifdef macintosh
+#include <TargetConditionals.h>
+#endif
+
+#if !defined(macintosh) || !TARGET_OS_OSX

 #include <sys/time.h>
 #include <unistd.h>

You could even drop this specific macOS branching, sys/time.h is available on macOS and as I said Microseconds() is deprecated and might be removed at any time.

Comments (12)

  1. Oleh Derevenko

    It seems you are trying the 0.16.2 build which was released long ago. Please try the latest revision in “0.16.x“ branch. There were number of platform compatibility corrections since the 0.16.2 release.

  2. Oleh Derevenko

    I’ve added your suggested change to CMakeLists.txt.
    As for other corrections — they were made against the old sources which had already been changed after the 0.16.2.
    I’ve published 0.16.3 with the changes — please check it out/

  3. Log in to comment