Re: Mac OS X cross-compiler not finding system include files?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Maróy Ákos wrote:

It seems that there's an issue with the Mac OS X gcc build process, so that it automagically ads $prefix after $sysroot in the include search path.

Everything seem to tell that the "Open Source" people in Apple haven't
ever thought someone to crosscompile for MacOS X. So the Apple GCC
sources like the :

http://www.opensource.apple.com/darwinsource/tarballs/other/gcc-5490.tar.gz

the given link gave, may be quite one-eyed'ly patched only for the
native GCC case...

for example, I re-compiled gcc with prefix=/opt/i686-apple-darwin9 and sysroot=/foo/bar, and now I get:

$ /opt/i686-apple-darwin9/libexec/gcc/i686-apple-darwin9/4.0.1/cc1plus -v
ignoring nonexistent directory "/foo/bar/opt/i686-apple-darwin9/lib/gcc/i686-apple-darwin9/4.0.1/../../../../include/c++/4.0.1" ignoring nonexistent directory

This would be '$sysroot/$prefix/include/c++/4.0.1' when the
'/lib/gcc/i686-apple-darwin9/4.0.1/../../../..' (== '') is
removed.  So the traditional '$prefix/include/c++/$gcc-version'
as the install place for the common (for a GCC version) C++
headers seems to been some starting point in this mess...

But despite of using the '--with-sysroot=$sysroot', the stuff
built during the GCC build should still go into the $prefix
install scheme - but this is only my opinion, what the '--with-sysroot'
currently really does is unclear for me...

What will be put into the $sysroot scheme should only be things copied
from the target system or things waiting to be copied onto the target system after installing them onto the development host. Parts of the
crosstoolchain then don't belong to these unless they are new runtime
parts for the target system ('libstdc++.so's etc.) which of course
should be installed on it so that the crosscompiled apps could run
there...

ignoring nonexistent directory "/foo/bar/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /foo/bar/usr/include
 /foo/bar/System/Library/Frameworks (framework directory)
End of search list.

The two "Frameworks" directories then weirdly seem to follow the
assumed $sysroot idea...

if I wanted to fix / patch this, where would I look in the gcc source code tree?

One must first check the 'gcc-5490' sources... Where the 'gcc-5493'
ones you have, are as a tarball?

Ok, I tried those gcc-5490 ones but doing some snooping starting from
the 'gcc/cppdefault.c' where those headers search paths are finally
defined, really wasn't that easy :(

The 'gcc/c-incpath.c', 'gcc/c-opts.c' etc. though seemed to handle
the 'sysroot' matters... Doing a 'grep sysroot * | less' in 'gcc'
told where this was made into the current mess...

My first advice would be to leave the '--with-sysroot=' away from
the configure, then to build with the bare 'make all-gcc' and after
that see what the $BUILD/gcc/xgcc and $BUILD/gcc/cc1plus would tell
about the built-in search-paths with the '-print-search-dirs' and '-v'...

The $sysroot as a good idea could still be used, nothing disables
one to add some symlinks to point to the sysroot'ed stuff from the
"traditional crosscompiler" places.  What would happen to the
"Frameworks" directories without '--with-sysroot=' was interesting.

It seemed that these two were tried to be used directly without the
$sysroot as the prefix...

Some files in 'gcc/config' seem to handle these things and the following
place in 'darwin-c.c' would require patching for a crosscompiler :

static const char *framework_defaults [] =
  {
    "/System/Library/Frameworks",
    "/Library/Frameworks",
  };

One probably would like these to be put into the normal $tooldir aka
$prefix/$target :

  $tooldir/System/Library/Frameworks
and
  $tooldir/Library/Frameworks

One way to get this is to define something like :

--------------------------- clip ---------------------------------
T_CPPFLAGS=-DCROSS_TOOLDIR=\"$(tooldir)\"
--------------------------- clip ---------------------------------

in the proper "target Makefile fragment", the 'tmake-file', here the
'gcc/config/t-darwin'.  Then in the required file(s) like the told
'gcc/config/darwin-c.c', do some conditional compiling :

--------------------------- clip ---------------------------------
#ifndef CROSS_DIRECTORY_STRUCTURE

static const char *framework_defaults [] =
  {
    "/System/Library/Frameworks",
    "/Library/Frameworks",
  };

#else

static const char *framework_defaults [] =
  {
    CROSS_TOOLDIR "/System/Library/Frameworks",
    CROSS_TOOLDIR "/Library/Frameworks",
  };

#endif
--------------------------- clip ---------------------------------

The '-DCROSS_TOOLDIR=$prefix/$target' would appear in the compile
commands and from it got into the conditional compile(s)...

Of course these only would define where these things would be searched,
physically the stuff could be in the $sysroot, the traditional $tooldir
only having symlinks to the physical stuff, so the $sysroot could have

  $sysroot/usr/include
  $sysroot/usr/lib
  $sysroot/System/Library/Frameworks
  $sysroot/Library/Frameworks

etc. The traditional (without '--with-sysroot=') search scheme in a
cross GCC is :

  $tooldir/bin           - target binutils
  $tooldir/include       - target headers
  $tooldir/lib           - target libraries

Okeydokey, with the previous suggested patches the produced 'cc1plus'
produced from the gcc-5490 sources gave :

[root@Dell build]# cd gcc
[root@Dell gcc]# ./cc1plus -v
ignoring nonexistent directory "/usr/local/lib/gcc/../../include/c++/4.0.1"
ignoring nonexistent directory "/usr/local/lib/gcc/../../include/c++/4.0.1/i686-apple-darwin9" ignoring nonexistent directory "/usr/local/lib/gcc/../../include/c++/4.0.1/backward" ignoring nonexistent directory "/usr/local/lib/gcc/i686-apple-darwin9/4.0.1/include" ignoring nonexistent directory "/usr/local/lib/gcc/../../i686-apple-darwin9/sys-include" ignoring nonexistent directory "/usr/local/lib/gcc/../../i686-apple-darwin9/include" ignoring nonexistent directory "/usr/local/i686-apple-darwin9/System/Library/Frameworks" ignoring nonexistent directory "/usr/local/i686-apple-darwin9/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
End of search list.

The default $prefix (no '--prefix=$prefix' given in configure) was
used here...

The patches for the 'gcc/config' things so are :

--------------------------- clip ---------------------------------
*** t-darwin.orig       2009-07-09 20:30:43.000000000 +0300
--- t-darwin    2009-07-09 20:36:16.000000000 +0300
***************
*** 46,48 ****
--- 46,49 ----
# file names to appear in stabs, causing the bootstrap to fail. Using -pipe
  # works around this by not having any temporary file names.
  TARGET_LIBGCC2_CFLAGS = -fPIC -pipe
+ T_CPPFLAGS=-DCROSS_TOOLDIR=\"$(tooldir)\"
--------------------------- clip ---------------------------------
and:
--------------------------- clip ---------------------------------
*** darwin-c.c.orig     2008-03-14 23:49:59.000000000 +0200
--- darwin-c.c  2009-07-09 20:41:35.000000000 +0300
***************
*** 841,848 ****
--- 841,853 ----

  static const char *framework_defaults [] =
    {
+ #ifndef CROSS_DIRECTORY_STRUCTURE
      "/System/Library/Frameworks",
      "/Library/Frameworks",
+ #else
+     CROSS_TOOLDIR "/System/Library/Frameworks",
+     CROSS_TOOLDIR "/Library/Frameworks",
+ #endif
    };

  /* Register the GNU objective-C runtime include path if STDINC.  */
--------------------------- clip ---------------------------------

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux