Page 1 of 1
SOLVED: Building a GCC 11.2.0 Cross Compiler
Posted: Sat Apr 23, 2022 3:55 pm
by Barry
Hello,
I'm currently trying to build a toolchain for my OS, and I've got stuck while compiling GCC. I've already got a i686-elf GCC working, and I've got binutils compiled to target my OS.
The issue, however, is when I compile GCC. I get:
Code: Select all
gcc-11.2.0/gcc/configure: line 4543: syntax error near unexpected token `-I"$srcdir"/ada/libgnat'
which causes
make all-gcc to fail.
There are also some warnings earlier:
Code: Select all
gcc-11.2.0/gcc/configure: line 3070: ACX_NONCANONICAL_HOST: command not found
gcc-11.2.0/gcc/configure: line 3073: ACX_NONCANONICAL_TARGET: command not found
gcc-11.2.0/gcc/configure: line 3080: GCC_TOPLEV_SUBDIRS: command not found
I'm configuring like this:
Code: Select all
../gcc-11.2.0/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot=$SYSROOT --disable-nls --enable-languages=c
and that runs without errors.
Has anyone built GCC 11.2.0 to target their OS, and had similar problems? What was the solution?
Am I just missing some dependency, or forgot to do an autoconf somewhere?
The wiki article for this topic is pretty outdated (it targets GCC 7.2.0), so I'll probably update that afterwards, if I can get 11.2.0 to build.
Thanks,
Barry
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sat Apr 23, 2022 4:17 pm
by Barry
UPDATE:
I've just spotted this in the
configure output:
Code: Select all
*** This configuration is not supported in the following subdirectories:
target-libgomp target-libatomic target-libitm target-libsanitizer target-libvtv target-libphobos gnattools gotools target-libada target-libhsail-rt target-libstdc++-v3 target-zlib target-libbacktrace target-libgfortran target-libgo target-libffi target-libobjc target-liboffloadmic
(Any other directories should still work fine.)
I'm looking into it further, but I think I haven't set up these directories to target my OS, so they can't be built with the TARGET I specified.
If anyone knows how to configure these, I'd appreciate if you could give me some advice.
Otherwise, I'm going to keep trying, and I'll update the wiki page when I figure it out.
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sat Apr 23, 2022 8:43 pm
by Barry
FINAL UPDATE:
I fixed the issue.
I got a clean copy of the binutils & gcc source code, patched them again, and compiled and it worked. I also had a few things missing from my libc headers. I'll probably add those to the wiki article too when I've confirmed my build is fully functional.
Thanks,
Barry
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sat Apr 23, 2022 9:51 pm
by davmac314
Just FYI GCC 11.3 has been released so you might want to consider using that instead. It has a ton of bug-fixes over 11.2.
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 11:08 am
by Barry
Ah thanks, I'll go ahead and try to build that today. Any idea which version of binutils will be compatible? I assume probably the latest one too.
I have one slight issue with my current build: GCC doesn't seem to be providing stdint.h. My gcc-11.2.0/gcc/config.gcc has a line for my target with use_gcc_stdint=wrap. But when I compile GCC I can't #include <stdint.h> in any of my source files, it's a missing header. I can make it myself in my include dir, but then I won't have any of the types. This actually caused an issue when building libgcc because it couldn't find intptr_t. To get the build to complete I just defined it as an int in my sys/types.h header, but I'm not a big fan of this sort of work around.
Any idea why GCC isn't providing stdint.h?
Once I've got 11.3.0 built successfully, I'll update the wiki.
Thanks,
Barry
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 11:23 am
by kzinti
You probably don't want to use_gcc_stdint=wrap. This is telling that you want GCC's version of stdint.h to be a wrapper around your existing one. But you don't have one, so it doesn't work.
Let GCC provide stdint.h for you (use_gcc_stdint=provide) and you should be good.
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 11:40 am
by Barry
Thanks,
I actually had this thought, and I do have a blank version of stdint.h in my include dir, but still not much luck.
I'll just switch to provide, as it'll almost certainly cover my use-case.
Thanks for that,
Barry
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 11:56 am
by Barry
Well, that fixed the
#include <stdint.h> issue, but
libgcc is still complaining about intptr_t not being declared/defined.
This seems like something that it should have defined by itself, and it even says
Code: Select all
gcc-11.3.0/libgcc/libgcov.h:186:1: note: 'intptr_t' is defined in header '<stdint.h>'; did you forget to '#include <stdint.h>'?
But I have to define it manually in my headers to get the build to finish.
Any ideas?
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 12:03 pm
by kzinti
You could go back to the wrapper if you wanted to... But your own version of stdint.h can't be blank, it needs to define everything that needs to be defined. Using the wrapper means that GCC won't define anything and it's up to you to do so.
As to why GCC is not defining intptr_t in it's own stdint.h, I have no idea. Have you looked what's in that file to see if there is any clue?
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 12:32 pm
by Barry
Question: If GCC provides stdint.h for me when it's built, how can I compile binutils (which requires stdint.h) before GCC has provided the header, or compile GCC before it provides the header?
I think there's a bit of a bootstrapping issue here, and I don't know how I got into this situation.
I'm tempted to try building binutils/GCC on a completely fresh install.
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 12:47 pm
by nullplan
Barry wrote:Question: If GCC provides stdint.h for me when it's built, how can I compile binutils (which requires stdint.h) before GCC has provided the header, or compile GCC before it provides the header?
You compile binutils with the host compiler. It does not require the target's stdint.h.
Re: Building a GCC 11.2.0 Cross Compiler
Posted: Sun Apr 24, 2022 12:54 pm
by Barry
Yeah, this makes sense. I've been investigating further, and it appears that the stdint.h error is actually caused by my linux install not having the right headers. I might have to do a fresh install to get this to work. I can't even compile the latest GCC to target my host system, so it's definitely a system error.
Sorry for how long this has been drawn-out.