Forum for developers, compiling on Threos, etc.
-
aron
- Posts: 92
- Joined: Tue Dec 05, 2017 11:06 am
Post
by aron » Thu Apr 26, 2018 2:28 pm
Once you installed the
gcc package, you will be able to compile C sources files with gcc:
The following examples can be done in the
/usr/src/examples directory (from the
examples package).
To compile
hello1.c into a PIE (Position-Independent Executable, uses GOT/PLT and dynamically links to the libc, and other libraries):
To compile a static executable (does not use dynamic libraries):
Code: Select all
$ gcc -mcmodel=large -static -fno-pie -fno-pic -Wl,-Nqx,--start-group,-ldevlib,-lkrnlext hello1.c
-
aron
- Posts: 92
- Joined: Tue Dec 05, 2017 11:06 am
Post
by aron » Wed May 23, 2018 2:03 pm
Starting from
gcc-4.7.2-7, the default mode is dynamically linked PIE (as it was before). However, the
-static is a synonym to
-static-pie (or
-static -pie). Also, the
-static switch includes the
-ldevlib -lkrnlext flags.
In order to build a static non-PIE program, use
-static -no-pie. For example:
Code: Select all
$ gcc -mcmodel=large -static -fno-pie -fno-pic -Wl,-Nqx hello1.c
-
aron
- Posts: 92
- Joined: Tue Dec 05, 2017 11:06 am
Post
by aron » Mon Mar 04, 2019 3:02 pm
The most recent gcc package (version 8.2.0-4) has much better default flags, so the common cases shall compile/link without any problem.