LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-23-2019, 10:31 AM   #1
Alizah
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Rep: Reputation: Disabled
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?
 
Old 10-23-2019, 12:08 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,292

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Welcome to LQ.

That variable is probably being ignored.

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.
 
1 members found this post helpful.
Old 10-23-2019, 03:21 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Alizah View Post
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?
 
1 members found this post helpful.
Old 10-24-2019, 03:25 AM   #4
Alizah
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
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?
 
Old 10-24-2019, 03:29 AM   #5
Alizah
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by business_kid View Post
Welcome to LQ.

That variable is probably being ignored.

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 ?
 
Old 10-24-2019, 03:44 AM   #6
Alizah
LQ Newbie
 
Registered: Oct 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
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?
 
Old 10-24-2019, 09:19 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 10-24-2019, 09:35 AM   #8
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,573
Blog Entries: 19

Rep: Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452
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).
 
Old 10-24-2019, 10:13 AM   #9
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,802

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Smile Newbie?

I sometimes have to chuckle when reading some of the things that come up as "newbie" problems. It isn't just Windows-to-Linux user questions any more.
 
Old 10-25-2019, 04:14 AM   #10
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,292

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
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.
 
Old 10-28-2019, 05:04 AM   #11
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.
 
Old 07-17-2020, 10:48 AM   #12
Jon Wilder
LQ Newbie
 
Registered: Jul 2015
Posts: 17

Rep: Reputation: Disabled
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.
 
Old 07-17-2020, 10:59 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User defined linux commands in a user defined shell Sushma05 Linux - Newbie 3 09-13-2013 07:21 AM
cross_compile and static linking dk_zero-cool Linux - Software 0 12-19-2011 04:52 AM
PS3 kernel compilation error ?CROSS_COMPILE? anolis Linux - Kernel 2 03-06-2011 02:42 PM
CROSS_COMPILE parameter not recognised Glenn D. Linux - Kernel 0 09-26-2010 10:18 AM
Replace variable with user defined variable ce124 Programming 10 04-13-2007 09:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration