LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-29-2016, 04:33 PM   #1
scotttc
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Rep: Reputation: Disabled
what does passing something to a compiler mean? I'm certain my terminology is off


Hi,

I'm new here and I'm also new to building executables on linux. I have this piece of code that is in a build.sh script and I don't understand what it is doing. It seems like it is calling a specific compilier to compile this specific code with it. I always tohught comiliers where a part of the environment of your machine, not something you execute.

Here is the piece of code

# build
../../../../compiler-env/arm-linux-gnueabihf.sh '
set -e

# read global build configuration
source ../../../BuildScripts/build-default.config

"$scons" $sconsOptions ARCH=arm-linux-alterasoc MODE="$(buildMode "$PREDATOR_SABINE_BUILD_VARIANT")"
'

I don't understand two things
1) it is indeed calling a specific compilier, one that might not be default on my system correct?

2) by wrapping the section of code in singular quotes, is this forcing this code to run using this compiler?

thanks,
Scotttc
 
Old 11-29-2016, 04:41 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
A compiler is a program on your computer that is used to build source code into machine code. This script is calling a cross-compiler, which is a special kind of compiler designed to build source code into machine code that's intended for use on an architecture other than what you're compiling on, eg: building a 64-bit program from a 32-bit computer, or in this case, building an ARM program on an x86 computer.

You will need to install the suitable cross-compiler on your system.

I'm not sure why that whole block of code is in single quotes, it's a little abnormal. It's essentially passing everything between the single quotes as an argument to "arm-linux-gnueabihf.sh". What that script does with this argument is a different matter...it must be some kind of wrapper script for the cross-compiler.
 
Old 11-29-2016, 04:50 PM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by scotttc View Post
Hi,

It seems like it is calling a specific compilier to compile this specific code with it. I always tohught comiliers where a part of the environment of your machine, not something you execute.

1) it is indeed calling a specific compilier, one that might not be default on my system correct?

2) by wrapping the section of code in singular quotes, is this forcing this code to run using this compiler?
A compiler is a computer program which reads your source code and generates an executable file composed of machine instructions. A compiler is usually language specific i.e. it only works with a specific language as input. A compiler is usually machine specific i.e. it only produces machine code for a specific CPU and operating system. There are a few compilers which will work with multiple languages and/or multiple CPU types.

So to answer your question we need to know:
What language are you writing in?
What machine model are you compiling for?
You state that you are using Linux, is that correct?

---------------------
Steve Stites
 
Old 11-29-2016, 07:42 PM   #4
scotttc
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
@suicidaleggroll
Cross compiler. I think that is part of the answer I was looking for. I am not entirely sure what it does with the wrapper either, but youre saying that it is not normal I guess. normally I'm guessing you just pass the scons function to the compiler as a function?

@jailbait
Thanks, I understand that part now about the compiler.
I am writing in cpp.
I am compiling for an arm processor (I know that's obvious) I will have to get back about which kind exactly.
Yes, I am using centOs 7.

I appreciate the quick responses guys. The part about the cross-compiler really helps, I had not heard about that before.

Are cross compilers usually specialized and customized? I'm assuming the one I came across is based on @suicidaeggroll 's post. I am very lost on what the wrapper could be but I will have to do some investigating it sounds like.
 
Old 11-29-2016, 08:15 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
Actually, a "cross" compiler is just an ordinary compiler ... with a different object-code generation layer on the so-called "back end."

Pretty much all compilers ... including, of course, the gcc compiler suite ... have three general layers:
  1. The "front end," which handles the syntax of a particular source language, creating a fairly language-agnostic representation [maybe ...] called (frantic hand-waving here ...!) an "Abstract-Syntax Tree (AST)."
  2. The "middle eight" (my term ...), which performs transformations and optimizations that are not specific to any target architecture.
  3. The "back end," which performs target-specific transformations and then produces object code for a particular CPU target.
While you typically run a "back end" that generates object-code for the host CPU, sometimes you don't. And, when you don't, we call that a "cross-" compiler. Yep, it's really just the same ol' compiler, but it's producing an output file that the host CPU cannot directly run.

Last edited by sundialsvcs; 11-29-2016 at 08:19 PM.
 
Old 11-29-2016, 11:27 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by scotttc View Post
@suicidaleggroll
Cross compiler. I think that is part of the answer I was looking for. I am not entirely sure what it does with the wrapper either, but youre saying that it is not normal I guess. normally I'm guessing you just pass the scons function to the compiler as a function?
You haven't reached the compiler yet, scons is a "software construction tool", like "make". Notice that "$scons" is a shell variable which might have the value of the scons, the program name. So you have a shell script, which is calling another shell script (arm-linux-gnueabihf.sh) and passing it some shell code to evaluate (the stuff in the single quotes), which is calling scons (?), which is probably calling your cross compiler.

Quote:
Originally Posted by scotttc View Post
I am writing in cpp.
By "cpp" did you mean C++? Generally, C++ compilers follow the traditional model, where you pass a file name to the compiler and it reads the code to compile from those files, you don't "pass a function" to a compiler.
 
Old 11-30-2016, 01:22 AM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Welcome to LQ!

Please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.

I am not yet ARM enabled so will leave you in the capable hands of others for the details!

However, in addition to replies already received, a quick search for the script in your exmple code, arm-linux-gnueabihf.sh, turns up many useful-looking resources, so that its useage appears to be well documented.

Good luck!
 
Old 11-30-2016, 08:37 AM   #8
scotttc
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
You haven't reached the compiler yet, scons is a "software construction tool", like "make". Notice that "$scons" is a shell variable which might have the value of the scons, the program name. So you have a shell script, which is calling another shell script (arm-linux-gnueabihf.sh) and passing it some shell code to evaluate (the stuff in the single quotes), which is calling scons (?), which is probably calling your cross compiler.
Thanks for clarifying that. I do understand the basic similarity and functions between scons and make but it ends there. In your scenario are you saying that scons itself calls the compiler? If so what is the purpose of calling arm-linux-gnueabihf.sh in the first place? how would scons know to use that specific cross compiler when it runs first?

Thanks in advance. I understand I'm new to this stuff so any help is greatly appreciated.


Quote:
Originally Posted by ntubski View Post
By "cpp" did you mean C++? Generally, C++ compilers follow the traditional model, where you pass a file name to the compiler and it reads the code to compile from those files, you don't "pass a function" to a compiler.
I do mean C++. and ok, that makes a lot more sense to me. I guess it resolves the function to a file before passing it which makes more sense.

Last edited by scotttc; 11-30-2016 at 08:38 AM.
 
Old 11-30-2016, 08:56 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
"make" is a very simple build-tool, basically able to handle dependencies and compile-order but really not much more. It is capable, for example, of determining whether a particular source-file has changed such that it needs to be recompiled, or not.

There are a wide variety of competing build-systems, including "scons," which try to inject true programming into the build-script so that it can do better things smarter. Many IDEs used by software developers integrate this sort of technology so that you can build a project by clicking a button.

These are not "the compiler." A compiler is a specific tool which takes source-code and produces something that, by some means and in the proper environment, can be executed.

Build-tools, then, are part of the surrounding ecosystem: the software which first determines what commands need to be issued (including those which invoke the compiler), then issues them in the proper sequence to accomplish this particular (re-)build.
 
Old 11-30-2016, 11:09 AM   #10
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by scotttc View Post
Thanks for clarifying that. I do understand the basic similarity and functions between scons and make but it ends there. In your scenario are you saying that scons itself calls the compiler? If so what is the purpose of calling arm-linux-gnueabihf.sh in the first place?
I don't know, perhaps it sets up some environment variables? Maybe it's just pointless complexity, these things tend to build up over time.

Quote:
Originally Posted by scotttc View Post
how would scons know to use that specific cross compiler when it runs first?
It might have to do with the ARCH=arm-linux-alterasoc parameter, or some of the aforementioned environment variables. Or the information might be in a file named SConstruct.

http://scons.org/doc/production/HTML/scons-man.html
Quote:
By default, scons searches for a file named SConstruct, Sconstruct, or sconstruct (in that order) in the current directory and reads its configuration from the first file found. An alternate file name may be specified via the -f option.
Quote:
Originally Posted by scotttc View Post
I guess it resolves the function to a file before passing it which makes more sense.
I don't know what you mean by "resolves the function to a file", but it sounds like you still have some misconceptions.
 
  


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
Passing args in terminal window is OK. but isn't when passing in GNOME launcher why? majrys1962 Debian 0 11-18-2008 06:00 PM
snmp terminology alaios Linux - Networking 8 09-10-2005 06:40 PM
Linux terminology hernan Linux - Newbie 3 01-14-2005 04:22 PM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM
Passing commands to the compiler with ./cofigure Travis86 Linux - Software 5 10-16-2003 09:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:58 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