Is CROSS_COMPILE a builtin or user defined variable?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is CROSS_COMPILE a builtin or user defined variable?
I am relatively new to Linux OS environment. So, forgive me for this simple question. I have been using CROSS_COMPILE variable for cross compilation. But, I am not sure if its a user defined variable or by default its one of the bash shell environment variables like PATH?
If you're cross compiling (say on x86 for arm) you'll need your x86 environment to run and a stack of stuff from an arm installation. You'll also need installed compilers for arm, etc. It's a big effort.
I am relatively new to Linux OS environment. So, forgive me for this simple question. I have been using CROSS_COMPILE variable for cross compilation. But, I am not sure if its a user defined variable or by default its one of the bash shell environment variables like PATH?
Exactly where have you been using it? And with success, not, or mixed results?
Why I'm asking is:
For cross compiling any code to run on a different target from your build machine one typically configures and installs tools that are set up to create the result for the target environment.
There are plenty of define names, but have you run into specifically CROSS_COMPILE? And was it documented? Or did you just decide to name one to be this?
Can you please elaborate more about what exactly you're trying to accomplish here?
Exactly where have you been using it? And with success, not, or mixed results?
Why I'm asking is:
For cross compiling any code to run on a different target from your build machine one typically configures and installs tools that are set up to create the result for the target environment.
There are plenty of define names, but have you run into specifically CROSS_COMPILE? And was it documented? Or did you just decide to name one to be this?
Can you please elaborate more about what exactly you're trying to accomplish here?
Thanks rtmistler for your reply.
Yes, I understand that cross compiling is needed when code is to be run on different target from your build machine and I build using CROSS_COMPILE variable(cross compiling on X86 for ARM).
I am working with NXP i.MX family boards (mpus) and I successfully been able to build a kernel module by installing and configuring I2C tools with the help of a tutorial.
But I need to understand in depth about the shell environment variables. So, it crossed my mind whether I can use another variable instead of CROSS_COMPILE?
If you're cross compiling (say on x86 for arm) you'll need your x86 environment to run and a stack of stuff from an arm installation. You'll also need installed compilers for arm, etc. It's a big effort.
Thanks business_kid for your reply. Yes I am cross compiling on x86 for ARM. I have successfully been able to build a kernel module for i.MX microprocessor board. But i just wanted to understand, can we use another user define variable instead of CROSS_COMPILE ?
Exactly where have you been using it? And with success, not, or mixed results?
Why I'm asking is:
For cross compiling any code to run on a different target from your build machine one typically configures and installs tools that are set up to create the result for the target environment.
There are plenty of define names, but have you run into specifically CROSS_COMPILE? And was it documented? Or did you just decide to name one to be this?
Can you please elaborate more about what exactly you're trying to accomplish here?
Thanks rtmistler for your reply. I have successfully been able to compile a kernel module on i.MX MPU board by following a tutorial. I am cross compiling on x86 for ARM boards and I understand the concept of cross compiling for running on a different target from your build machine.
But I need to understand in depth about the shell environment variables. Since, I came across with CROSS_COMPILE variable, and I wondered if we can use another variable instead?
A definition such as CROSS_COMPILE seems too general.
The environment you are using should already redefine tools and establish certain defines as part of the make process. Suggest you read he make files for your project. If you have to type a command to set up your tools for your environment prior to performing a build, then check the command, which is likely a script and see what it is doing. Most typically it is changing the alias for things like GCC and GPP, and the LDD path so that the correct tools are used and correct libraries are used.
You usually cross-compile by giving gcc an explicit host rather than using the default host (the build machine). If you are building for a completely different architecture, you will need to create a set of build tools which have that architecture as a target, not just as a host. You might like to read the manual for cross-Linux from source (CLFS).
When you're cross compiling you have to specify loads of stuff because the configure script will look on your running system and get them wrong. So you might have something like
Code:
--arch=arm --cc=gcc-arm --libdir=/opt/arm/lib etc. etc.
It's more than possible that somebody lumped them all into $CROSS_COMPILE to use that instead. Why don't you try
echo $CROSS_COKPILE and see if that throws any light on matters.
Cross compiling generally involves a toolchain specific for the task. Otherwise many individual things have an --arch= configure option. TBH, it's simpler just to compile it on the destination device with the native environment. Not to imply desirable depending on the specs of the target device and what you are compiling.
CROSS_COMPILE is a variable that I believe is built into the Makefile of most packages. When you either set this variable via export or pass it on the command line, you pass the target triplet of the cross toolchain you're wanting to cross compile with.
ARCH is another variable built into most package Makefiles that you use to pass the processor architecture to the Makefile of the package being built. This variable is used in conjunction with CROSS_COMPILE, and it allows the build/host toolchain to find the architecture specific include and source files for the target architecture within the package. Most packages have different source files for different architectures, and the source for each architecture is stored in its own dedicated directory named for the architecture (ex. in GCC you have gcc/config/arm/*, and in the Linux Kernel package you have arch/<ARCH>/include).
Say you're on a x86_64-pc-linux-gnu machine, and on this machine you have an arm cross compiler, something like armv7l-unknown-linux-gnueabihf. To build the package for Arm using your Arm cross compiler, you would pass this to the command line -
Code:
user@localhost ~ $: ARCH=arm CROSS_COMPILE="armv7l-unknown-linux-gnueabihf-" make
Notice at the end of my target triplet there is a trailing dash. That MUST be there because the Makefile will invoke $CROSS_COMPILE-gcc, $CROSS_COMPILE-g++, $CROSS_COMPILE-ar, $CROSS_COMPILE-ranlib, etc etc. It doesn't prepend the dash to the gcc, g++, ar, ranlib, etc etc so you must make sure you place a trailing dash at the end of the target triplet.
I do believe that the path to your cross toolchain root must also be set in your users $PATH variable in order for this to work. If it's installed in the same location as your native toolchain you're already set.
Last edited by Jon Wilder; 07-17-2020 at 10:57 AM.
CROSS_COMPILE is probably a built-in. But used only in cross-compile toolchains, otherwise this variable is pointless/meaningless.
CROSS_COMPILE is not a bash [or any other shell] built-in.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.