fatal error: mach-o/dyld.h: No such file or direct

2019-08-08 22:00发布

问题:

I'm trying to compile this src on my Ubuntu 14: https://github.com/Bohdan-Khomtchouk/HeatmapGenerator/blob/master/HeatmapGenerator2_Macintosh_OSX.cxx.

To compile this source code, do: fltk-config --use-images --use-gl --compile HeatmapGenerator2_Macintosh_OSX.cxx

However, I retrieve the following error:

HeatmapGenerator2_Macintosh_OSX.cxx:52:25: fatal error: mach-o/dyld.h: 
No such file or directory
  #include <mach-o/dyld.h>
                          ^
compilation terminated.

I've looked into http://ubuntuforums.org/showthread.php?t=1623945 but it didn't help solve my issue.

Is #include <mach-o/dyld.h> not a valid preprocessor directive in Ubuntu? There seems to be very little written about it on the Internet. Perhaps it is an Apple specific library that might not be included in Ubuntu?

Any suggestions on how to bypass this error and successfully generate a binary executable file are greatly appreciated.

EDIT:

When I comment out the #include <mach-o/dyld.h> preprocessor directive, I get the following error:

HeatmapGenerator_Macintosh_OSX.cxx:568:13: error: use of undeclared identifier
      '_NSGetExecutablePath'
        if (_NSGetExecutablePath(path, &size) == 0)

Is there a way to bypass this error without using this preprocessor directive? _NSGetExecutablePath is only used once in the src, perhaps there exists an alternative...

回答1:

That source code simply won't compile under Linux as it's designed to use OSX's dylib (dynamic loader) rather than Linux's dynamic loader.

Possible solutions:

  • "Port" the source code from OSX to Linux.
  • Use OSX to compile the file.