Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compile a compiler that runs on other architectures #7

Open
HalfSweet opened this issue Jun 28, 2023 · 4 comments
Open

How to compile a compiler that runs on other architectures #7

HalfSweet opened this issue Jun 28, 2023 · 4 comments

Comments

@HalfSweet
Copy link

I want to cross-compile compilers that run on other architectures, currently my environment is Ubuntu on AMD64, can I compile compilers that run on Windows on AMD64 on this?

I tried to change the --host parameter in the script, but it doesn't seem to work, the compiled Xuantie-800-gcc-elf-newlib-Win32 is still an executable under Linux

python3 . /build-csky-gcc.py csky-gcc --src . / --triple csky-unknown-elf --jobs=8 --host=Win32 --rebuild

图片

@Cooper-Qu
Copy link
Collaborator

Sorry, the reminder email got lost among many others, and I just noticed it now. To compile the Windows toolchain, you can use the MinGW cross-compiler on Linux to generate a compiler that can run on Windows. First, install the cross-compilation toolchain on Linux, for example, using "apt install g++-mingw-w64-x86-64". Then, add the "--host=mingw" option to your script.

If you have any other questions, please feel free to ask again.

@HalfSweet
Copy link
Author

It was great! I managed to implement a cross-compile on Ubuntu 22.04 for Linux, Windows, and macos running on x86 platforms where the target product is x86, which required some modifications to the build python scripts, and I'll be coming up with a pr to use to refine the project later.

I am a bit confused though, I found out that the binary distribution has a version of libc called minilibc and there is a get_libc function in Toolchain.py to get the actual version of libc used. However, during the actual compilation process, the compiler complains that it can't find the source code for minilibc, and I haven't found any source code or binaries for it in the repository. How to solve this problem?

Thank you for your reply and I wish you all the best in your work life!

@Cooper-Qu
Copy link
Collaborator

Thank you for your contribution to the script.

Minilibc is not an open-source project. Its advantage lies in having a relatively compact code, but it also has some drawbacks, such as incomplete support for new language standards like c11. newlib is another bare-metal toolchain that is similar to the minilibc toolchain in functionality, but with better support for language standards. Can it meet your requirements?

@BorisSpa
Copy link

Hi @Cooper-Qu and @HalfSweet I've tried to compile with mingw but I get the error:

error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify

when running the command:

python3 ./build-csky-gcc.py csky-gcc --src ./ --host mingw --triple csky-unknown-elf --no-multilib --cpu ck803s --fpu soft --endian little --jobs=-1

image

Those are all the installed packages in the ubuntu docker container:

apt-get install -y autoconf automake autotools-dev nano curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 g++-mingw-w64-i686

Can you give me some instructions on how to compile for mingw host?

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants