what does passing something to a compiler mean? I'm certain my terminology is off
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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
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.
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?
@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.
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:
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)."
The "middle eight" (my term ...), which performs transformations and optimizations that are not specific to any target architecture.
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.
@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
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.
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.
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
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.
"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.
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
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.