We help IT Professionals succeed at work.

Will 'Hello World' program created in Windows based PC using gcc compiler run in embedded linux based system?

Medium Priority
224 Views
Last Modified: 2019-06-09
I purchased MCIMX8QXP-CPU: i.MX 8QuadX-Plus Multisensory Enablement Kit (MEK) from NXP.
https://www.nxp.com/support/developer-resources/evaluation-and-development-boards/i.mx-evaluation-and-development-boards/i.mx-8quadxplus-multisensory-enablement-kit-mek:MCIMX8QXP-CPU

This evaluation kit has some linux distribution that boots from SD card.  I use PC serial terminal program puTTy to communicate with this board.  I can see the file system is
mounted. I can type linux commands to navigate the file system.

I want to run 'Hello World' program in this board.  Using windows based PC, I used eclipse IDE with MinGW Toolchain (I installed gcc compiler from www. equation.com) website.  I created 'Hello World' program.   Is this gcc compiler intended for native use?  Or does it also apply to linux ?
If I can store my 'Hello World' executable in file system inside the board, will embedded linux execute this program?
Comment
Watch Question

Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
That will most probably NOT work. (unless you compileonan i.MX8 with same config as the target system).

For work on embedded systems you mostly need something called a cross-compiler.
That is a set of tools run on one platform building stuff for another platform.

So you have an X86 system (your windows PC)  that need to compile for a ARM based linux chipset.

So you need a ARM generating compiler running on X86.
also you need a toolchain with ARM libraries and X86 tools to link the target program.

i.MX8 point to this for setup, only you need a Linux environment to run it on afaict. So maybe you need a VM to run it in.
https://www.yoctoproject.org/
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Using gcc produces executable object code which can run on any X86 architecture...

Depending on how the executable is linked.

In your case, since your targeting an SBC (single board computer), then you'll link your executable as static, so there are no linkages to any external shared object libraries.

Note: SBC work use to be 100% of my work, several decades ago. If I were starting up a new SBC project today, not a chance I'd using anything remotely connected to Windows, as this will always add massive quantities of nonsense time drains to even the simplest work flow.

For development I'd run Ubuntu Bionic at a machine level, then run an Alpine LXD container for coding + testing + staging.

Then on my SBC, I'd run RAM based Alpine as my OS, which would allow me to use shared object libraries.

If you only have one executable running, which will eat up all 3GB of your SBC (per specs at link you published), then you'll have to use the single executable approach.

Running a full RAM based Linux instance will almost always be better.

Since RAM Alpine weights in around 10M total (yes you read that correctly), far better to run a full fledged OS, where you can for example ssh into your SBC + actually debug your code interacting with all your peripheral hardware... because...

SBC interactions with external/peripheral hardware is always the primary problem area.

If you can simplify debugging this type of problem, your initial development, future enhancements, bug fixing will all occur a lightning speed.

With Windows... more like granny on a walker, out for walk on a glacier speed...
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Along the lines of what noci said, I'd also arrange to do all my development on an ARM system... which I just noticed in the specs.

So you can arrange to cross compile (generate ARM code on Windows)... which will be even slower than other development.

Best to run all your development on an ARM based system... so again... avoid Windows like the plague, unless you have unlimited time + budget.
nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
slight correction:
gcc can create code for VAX,AXP, several IMBmainframes, 68K, x86 family, ARM (quite a range of CPU's),  ....

This is the most complete list of code backends i could find.
https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Submodel-Options.html#Submodel-Options

(and those can be run on different hosts).
Pierre FrançoisSenior consultant
CERTIFIED EXPERT

Commented:
You can run a windows executable binary into a Linux environment with wine.
nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
@pierre Francois: you will need Wine & Qemu as well because the target archtecture is ARM. (i.MX8 is a ARM 64b chipset.).

Author

Commented:
>> That will most probably NOT work.
Will it work if I choose Cross GCC toolchain in eclipse IDE instead of choosing MinGW toolchain?
nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
You would surely need a cross compiler setup.
Now the GCC suite has about 70-ish backends i could quickly find, they also run on about 70~-ish different platform then... so  70 squared in combinations is a tad too much to store on systems.

So you probably need to setup the right cross compiler environement. In your case:    Compiling on Windows-x86 or Windows-x64. and generating code for i.MX8 (32b or 64blinux  target) .

It wouldn't surprise me at all that the board has a complete toolchain already on board.
Why not develop & write code on the windows system, push it in a git repo.   and pull it on the board and compile there. That would most probably lead to a lot less headaches.
Alternatively there are i.MX8 emulators in Qemu. (f.e. lookup the development environment  for the purism librem-5 which uses the same processor).
those can be run on any host you like.

IMHO: the i.MX8 board you mention should be capable of compiling it's own code.  (it's about 3 Raspberry Pi's 3B+ stacked on one board).
did you check if it has a toolchain?

Author

Commented:
>> did you check if it has a toolchain?
How do I find out?  I posted link in my original question.  There is a Document and Software tab.  Which one of the documents will tell me if there is complete toolchain on the board?  Am I  looking for things like gcc compiler and vi editor?
The board comes with some Android Linux.  I connect to board to PC serial terminal running puTTy.
I can navigate the file system on board through puTTy.
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Visit https://www.nxp.com/support/developer-resources/evaluation-and-development-boards/i.mx-evaluation-and-development-boards/i.mx-8quadxplus-multisensory-enablement-kit-mek:MCIMX8QXP-CPU for access to Linux related docs.

You must register to get access to the Linux docs.

My guess is, as noci suggested, likely all the tools you require are already available.

Best answers will come from contacting NXP for info about toolchain support.

Author

Commented:
Great solutions!  Thank you!
nociSoftware Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
A tool-chain is a set of libraries of the target OS, target run time environment (mosty C-rtl ,possibly other lbraries).
as wel as a linker, compiler, librarian, etc. etc.
(the development tools).