Missing crt1 and crti when crosscompiling - gcc

I'am trying to build a cross compile toolchain based on GCC4.5 and newlib with gold and link-time-optimization enabled. GCC compiles fine but it did not generate the crt1.o or crti.o files. Therefore when I tries to use the compiler for building Newlib it complains with the message:
ld: error: cannot open crti.o: No such file or directory
ld: error: cannot open crtn.o: No such file or directory
ld: error: cannot find -lc
When searching for files named crt* in the directory where GCC4.5 is installed i got the following result:
find ../../../tooltarget/ -name "crt*" -print #(result modified to consume less space)
crtprec80.o, crtend.o, crtfastmath.o, crtbegin.o, crtendS.o, crtprec32.o, crtbeginS.o, crtbeginT.o, crtprec64.o
From the GCC spec's it seems like gcc needs both the crtbegin.o and the crti.o files, but only one of them is available.
*startfile:
%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o
%s;:crtbegin.o%s}
Following is the flags i used when compiling GCC:
--prefix=${TTP}/usr --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=x86_64-awn-linux-gnu
--with-gmp=${TTP}/usr --with-mpc=${TTP}/usr
--with-mpfr=${TTP}/usr --with-libelf=${TTP}/usr
--enable-languages=c --enable-lto
--disable-nls --disable-shared
--disable-multilib --disable-decimal-float
--disable-libmudflap --disable-libssp
--disable-libgomp --disable-threads
--without-headers --with-newlib
--with-build-sysroot=${TTP} --with-build-time-tools=${TTP}/usr/bin
I'm sure on if this is due to I configured GCC wrongly, or "stuff" simply do not work this way, or if the files crti.o should come from somewhere else.
Thanks in advance
Allan W. Nielsen

Some crt* files come not from the compiler, but from the C library. I suspect this is the case here for your crt1.o and crti.o.

Related

Building gcc 11.2 with jit support requires GMP, MPFR, MPC, ISL recompiled with -fPIC

I'm on a CentOS 7 Linux system where I don't have the root access. So I have to build gcc from source. I want to build gcc 11.2 with the jit support. I invoked
contrib/download_prerequisites for GMP, MPFR, MPC and ISL. Then from a build directory I configured gcc using
../gcc-11.2.0/configure --prefix=/some/path --enable-bootstrap --enable-shared \
--enable-host-shared --enable-threads=posix --enable-languages=c,c++,jit \
--disable-multilib
then I hit make.
It failed with ld errors asking me to recompile libisl.a, libmpc.a, libmpfr.a, libgmp.a with -fPIC. Right before these errors I saw lots of jit related outputs. I assume jit is behind all of this?
Then I tried adding CFLAGS=-fPIC to the above configure command as ../gcc-11.2.0/configure CFLAGS=-fPIC *rest_of_the_options_above*. The same ld errors were emitted.
I'm aware that those dependencies each has --with-pic option to their own configure. But I'm wondering if there is a way to have gcc invoke that for me? If not, does it mean that to build gcc with jit support, one has to build the four dependencies manually with --with-pic? Thanks.

Gnatmake compilation error after compiling .adb on Mac os

I just installed the AdaCore community compiler the dwarvin version (gnat-community-2018-20180523-arm-elf-darwin-bin.dmg), with the GPS. Using the respective installer from adacore. I also managed to add on my starting script the path of gnat. Till here everything works fine, gnat --version return the appriate version etc.
But when I want to compile a .adb file using gnatmake filename.adb
user$ gnatmake filename.adb
gcc -c filename.adb
gcc: error trying to exec 'gnat1': execvp: No such file or directory
gnatmake: "filename.adb" compilation error
And even after using gnatmake -c filename.adb I get
gcc -c filname.adb
gcc: error trying to exec 'gnat1': execvp: No such file or directory
gnatmake: "filename.adb" compilation error
I asked my professor for help he said use the VM provided (for Windows) I just want to avoid using a VM. Please help me resolve this error.
After running the following command gnatmake filname.adb -cargs -c the following came up.
gcc -c -v filename.adb
Using built-in specs.
COLLECT_GCC=/opt/gps//bin/gcc
Target: x86_64-apple-darwin16.7.0
Configured with: ../src/configure --enable-languages=ada,c,c++,objc --enable-lto --with-stage1-ldflags=-static-libstdc++ --with-boot-ldflags=-static-libstdc++ --disable-libcilkrts --with-bugurl=URL:mailto:report#adacore.com --disable-nls --without-libiconv-prefix --disable-libstdcxx-pch --disable-libada --enable-checking=release --disable-multilib --with-mpfr=/gnatmail/sandbox/community/x86_64-darwin/mpfr_stable-c/install --with-gmp=/gnatmail/sandbox/community/x86_64-darwin/gmp_stable-c/install --with-mpc=/gnatmail/sandbox/community/x86_64-darwin/mpc_stable-c/install --with-build-time-tools=/gnatmail/sandbox/community/x86_64-darwin/gcc_current-c/build/buildtools/bin --prefix=/gnatmail/sandbox/community/x86_64-darwin/gcc_current-c/pkg --build=x86_64-apple-darwin16.7.0
Thread model: posix
gcc version 7.3.1 20180524 (for GNAT Community 2018 20180523) (GCC)
COLLECT_GCC_OPTIONS='-gnatea' '-c' '-v' '-gnatez' '-mtune=core2' '-mmacosx-version-min=10.14.2'
gnat1 -quiet -dumpbase filename.adb -auxbase filename -gnatez -gnatea -gnatez -mtune=core2 -mmacosx-version-min=10.14.2 -fPIC filename.adb -o /var/folders/9r/52d5kqc906v4phl9jgjrxdlr0000gn/T//ccQlDd19.s
gcc: error trying to exec 'gnat1': execvp: No such file or directory
gnatmake: "filename.adb" compilation error
Now we can see how the compiler complains (thanks for the update in the question), it looks as though you have an installation problem.
Here, I get (edited down to remove the less significant parts)
[...]
COLLECT_GCC=/opt/gnat-ce-2018//bin/gcc
You have /opt/gps//bin/gcc, so your "prefix" (under which the installation is to be found) is /opt/gps, where mine is /opt/gnat-ce-2018 (I don’t know why there are two slashes there, doesn’t seem to matter). Then,
[...]
/opt/gnat-ce-2018/bin/../libexec/gcc/x86_64-apple-darwin16.7.0/7.3.1/gnat1 -quiet -dumpbase [...]
where you just have gnat1. So, you should have a file /opt/gps/libexec/gcc/x86_64-apple-darwin16.7.0/7.3.1/gnat1, and it should be executable.
I’d try reinstalling.

Problems installing packages which use SDL2 via cgo on Windows 7

I have problems installing SDL2 for golang, using Visual Studio Code.
I try to get the package:
"C:\Users\Bob\go\src\flappyGopher>go get -v github.com/veandco/go-sdl2/sdl
github.com/veandco/go-sdl2/sdl
# github.com/veandco/go-sdl2/sdl
In file included from ..\github.com\veandco\go-sdl2\sdl\audio.go:4:0:
./sdl_wrapper.h:2:23: fatal error: SDL2/SDL.h: No such file or directory
compilation terminated."
I used this manual: https://github.com/vinzBad/go-sdl2-tut/blob/master/00_preparation/windows.md
I have also the env variables:
CGO_CFLAGS C:\MinGW64\mingw64\include
GOPATH C:\Users\Bob\go
GOROOT C:\Go\
PATH ... C:\MinGW64\mingw64\x86_64-w64-mingw32\bin;C:\MinGW64\mingw64\bin;C:\Users\Bob\Downloads\SDL2-2.0.8\x86_64-w64-mingw32\include\SDL2
edit:the gcc output looks like a mess
C:\Users\Bob>gcc -xc -E -v -
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-5.1.0/configure --build=x86_64-w64- mingw32 --e
nable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable
-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC -
-disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-d
ebug --enable-threads=posix --enable-version-specific-runtime-libs --enable-full
y-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-l
d --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm -
-with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=http://td
m-gcc.tdragon.net/bugs
Thread model: posix
gcc version 5.1.0 (tdm64-1)
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
C:/Program Files/TDM-GCC-64/bin/../libexec/gcc/x86_64-w64-mingw32/5.1.0/cc1.exe
-E -quiet -v -iprefix C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-min
gw32/5.1.0/ -D_REENTRANT - -mtune=generic -march=x86-64
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/include"
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/../../../../include"
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/include-fixed"
ignoring duplicate directory "C:/Program Files/TDM-GCC-64/lib/gcc/../../lib/gcc/
x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/include
C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../..
/include
C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/include-fixed
C:/Program Files/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../..
/x86_64-w64-mingw32/include
End of search list.
Please see this.
The reason is go install tried to compile some
cgo
code of the github.com\veandco\go-sdl2 package, and that code apparently
wants to use the C header files
of the libsdl2 library¹.
You need to make libsdl2
available to the compiler.
To figure out where the C compiler expects to find the include (header)
files, see this.
¹ That's how C works. To use a compiled library in other C code, the compiler
usually needs to know the definitions of the types and functions provided
by that library. The formats of such libraries—contrary to Go libraries—do not typically embed type information in their metadata, so the compiler
needs to get that information from somewhere. In C and C++ world this information is commonly kept in the so-called include (also: header) files
which are included—through the use of a so-called preprocessor—both into the
code used to build a library and the code which uses the library.

How to build multilib mingw-w64 gcc toolchain

I used to use MSVC a lot, and now I want to try out new C++17 features, so I decided to use mingw-w64 toolchian.
Btw I'm new to building things from source
I also want the ability to compile both 32 bit and 64 bit application (multilib).
I had mingw-w64 headers installed, then I tried to bootstrap GCC 7.1.0 in MSYS2.
I configured it by this command
../src/configure --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --enable-targets=all --disable-werror --prefix=/c/tmp/gcc/dest --with-sysroot=/c/tmp/gcc/dest --disable-shared --disable-win32-registry --enable-version-specific-runtime-libs
The process completed without an error, however the compiler isn't usable.
I tried to compile a file a.cpp by
g++ -o a.exe a.cpp
Unfortunately, a message box with title cc1plus appeared saying The code execution cannot proceed because libgcc_s_seh-1.dll was not found.
Reinstalling the program may fix this problem.
That suggested that I should have libgcc, but how can I get it?

gcc to use newlib instead of glibc?

I want to use newlib instead of glibc in order to compile small static binaries. (I do not intend to cross-compile as the binaries are to be used by the same computer.) I believe that I need to compile a separate gcc for this ?
I compiled gcc:
./configure --prefix=/home/myuser/Desktop/gcc-4.4.5 --libexecdir=/home/myuser/Desktop/gcc-4.4.5 --libdir=/home/myuser/Desktop/gcc-4.4.5 --with-gxx-include-dir=/home/myuser/Desktop/gcc-4.4.5 --enable-languages=c --enable-libmudflap --disable-multilib --disable-libssp --disable-nls --with-newlib --with-gnu-as --with-gnu-ld --with-system-zlib
make
It compiled without errors but now when I try to compile a simple Hello World! program it wants to use headers from /usr instead of the path I specified above. These are some of the errors:
In file included from /home/myprogram/Desktop/myprogram.c:1:
/usr/include/stdio.h:34:21: error: stddef.h: No such file or directory
In file included from /usr/include/stdio.h:75,
from /home/myprogram/Desktop/myprogram.c:1:
/usr/include/libio.h:53:21: error: stdarg.h: No such file or directory
In file included from /usr/include/stdio.h:75,
from /home/myprogram/Desktop/myprogram.c:1:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before 'size_t'
/usr/include/libio.h:364: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/libio.h:373: error: expected declaration specifiers or '...' before 'size_t'
What am I doing wrong ? Is compiling a new gcc necessary or can I use my existing gcc and use newlib instead of glibc ???
You shouldn't need to rebuild gcc for this; you just need to point your existing gcc at the right things (using -I, -L etc.) and tell it not pull in the usual system stuff (using -nostdlib).
The section entitled "Shared newlib" in the newlib README file has runes for building and linking against either shared or static newlib when compiled natively.
I would strongly recommend using crosstool-ng to build your GCC toolchain. If you choose x86 followed by "bare metal" as the operating system, you can safely use newlib as a libc.
Note that newlib does not work with an operating system - that is standard things, like IO, won't work out of the box.
You have to tell the compiler where it can find the include files:
gcc -IyourDirectoryHere -IanotherDirectoryHere
-I
(that is a minus followed by a capital i as in Italy)
More details: http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Directory-Options.html

Resources