building a simple executable

41 views
Skip to first unread message

Kris Jones

unread,
Dec 14, 2017, 12:50:33 AM12/14/17
to Chromium OS dev
I'm trying to compile a small C program that will run on ChromiumOS, but does not need to be distributed. 

I've written a simple console app using glibc headers that I will be using for internal testing. I can compile it for Android using the NDK very easily. 
I'm not sure how to compile it for ChromiumOS using the toolchain provided in the build environment without making a custom package for it, which seems unnecessary, since I have no intention of ever distributing it. 

I have used the cros_sdk to build an OS image for my dev system, and I've also added modules to the kernel source, recompiled it, and pushed it to the system. 
So I do I have some experience working on existing packages. 

But when it comes to creating a new custom package, or working with code outside of the package system, I am completely lost. 
The documentation I've seen does not cover these scenarios in the detail I need. 

Is there a detailed howto guide for building outside the package system? Or, if not, a guide for creating a very simple custom package that will never need be submitted to a repo?

Thanks!    

Vincent Palatin

unread,
Dec 14, 2017, 4:31:34 AM12/14/17
to Kris Jones, Chromium OS dev
No.


Overall it's very simple for basic programs, you just have to add '--sysroot' to your gcc command-line
<arch>-cros-linux-gnueabi-gcc --sysroot=/build/<board>  file.c -o myexec

e.g.
armv7a-cros-linux-gnueabi-gcc --sysroot=/build/kevin -Wall -g -O2 foobar.c foobar_more.c -lz -o fooexe

Mike Frysinger

unread,
Dec 14, 2017, 2:13:25 PM12/14/17
to Vincent Palatin, Kris Jones, Chromium OS dev
if you `export SYSROOT=/build/kevin`, our compiler wrapper will use it automatically, so you don't need specify --sysroot every time
-mike

--
--
Chromium OS Developers mailing list: chromiu...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-os-dev?hl=en


Luis Lozano

unread,
Dec 14, 2017, 4:02:55 PM12/14/17
to Mike Frysinger, Vincent Palatin, Kris Jones, Chromium OS dev
and please use clang, not gcc. 
we are deprecating gcc and the version we have is very old.

<arch>-cros-linux-gnueabi-clang

Kris Jones

unread,
Dec 18, 2017, 7:55:59 PM12/18/17
to Chromium OS dev
Thanks guys, it works!
There were a couple small caveats:

#. I'm using x86, so I had to change "armv7a-cros-linux-gnueabi-gcc" to "x86_64-cros-linux-gnu-gcc". (I haven't tried clang, yet.)
#. the "-lz" option didn't work - I assume that's a code compressor? not a big deal at all, my binary is only 6k!
#. the binary reported a permissions error when I tried to run it on the Chromebook from /home/chronos. (This is on a test build, running as root.) After I copied it to /usr/sbin and it worked fine. I would've thought that execution restrictions would not apply on my config. How are these restrictions defined, and how are they applied? 


As an added bonus, the binary also worked on my Debian 8 (Xfce) build machine! 

Mike Frysinger

unread,
Dec 18, 2017, 9:16:51 PM12/18/17
to Kris Jones, chromium-os-dev
if you want to link against -lz, you'll need a real board like arm-generic. then you can run `emerge-arm-generic -g zlib` to get it before doing `export SYSROOT=/build/arm-generic`.

as for executing things, that is WAI.  /usr/local is where writable things get copied to execute.  we mount stuff under /home as noexec on purpose for security.
-mike

--
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages