3

I don't have a Raspberry Pi 2 yet, but was wondering what code gcc will produce.

Many of my programs use WiringPi and if I compile this and my programs will they use ARM7 code, and thus be incompatible with ARM6. (I must admit I have never studied the codesets, so don't have any idea what the differences may be.)

Milliways
  • 59,890
  • 31
  • 101
  • 209

3 Answers3

3

The gcc documentation explains this in detail. Basically, you can tell the compiler to forcibly use armv6:

gcc -march=armv6 -c foo.c -o foo.o

You can also let gcc try to autodetect the current architecture:

gcc -march=native -c foo.c -o foo.o
Arne
  • 2,226
  • 2
  • 18
  • 35
0

I'm sure it can. It doesn't appear to do so by default on the current Pi 2 B.

I just compiled the same sources on a B+ and a Pi 2 B.

B+

harry /ram $ ls -l *o
-rw-r--r-- 1 joan pi  27604 Feb  9 09:20 command.o
-rw-r--r-- 1 joan pi   2052 Feb  9 09:21 pig2vcd.o
-rw-r--r-- 1 joan pi  36144 Feb  9 09:20 pigpiod_if.o
-rw-r--r-- 1 joan pi   5792 Feb  9 09:21 pigpiod.o
-rw-r--r-- 1 joan pi 154712 Feb  9 09:20 pigpio.o
-rw-r--r-- 1 joan pi   4904 Feb  9 09:21 pigs.o
-rwxr-xr-x 1 joan pi 182052 Feb  9 09:21 x_pigpio
-rw-r--r-- 1 joan pi  32324 Feb  9 09:21 x_pigpiod_if.o
-rw-r--r-- 1 joan pi  31784 Feb  9 09:21 x_pigpio.o
harry /ram $ file command.o
command.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
harry /ram $

Pi 2 B

joan@paul /ram $ ls -l *.o
-rw-r--r-- 1 joan joan  27920 Feb  9 09:19 command.o
-rw-r--r-- 1 joan joan   2052 Feb  9 09:19 pig2vcd.o
-rw-r--r-- 1 joan joan  31932 Feb  9 09:19 pigpiod_if.o
-rw-r--r-- 1 joan joan   5780 Feb  9 09:19 pigpiod.o
-rw-r--r-- 1 joan joan 158696 Feb  9 09:19 pigpio.o
-rw-r--r-- 1 joan joan   5080 Feb  9 09:19 pigs.o
-rw-r--r-- 1 joan joan  34756 Feb  9 09:19 x_pigpiod_if.o
-rw-r--r-- 1 joan joan  34088 Feb  9 09:19 x_pigpio.o
joan@paul /ram $ file command.o
command.o: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped
joan@paul /ram $

I copied pigs and pigpiod from the Pi 2 B to the B+ and the executables appeared to run ok.

Read into that what you can.

joan
  • 71,024
  • 5
  • 73
  • 106
  • I just got my Pi 2. I entered the command gcc -Q --help=target which lists -march=armv6. gcc -v implies that gcc was configured with this. – Milliways Feb 10 '15 at 02:22
0

gcc will produce ARMv7 code for the Raspberry Pi 2. Assuming you are compiling on a RPi2, gcc-4.8 and g++-4.8 support -march=native, which means you don't need to worry about specific compiler architecture and cpu flags for code running on the RPi2. (See here for how to install gcc/g++ 4.8.)

I just did a test build of the Icarus Verilog codebase with the following:

$ ./configure CXX=g++-4.8 CC=gcc-4.8 CFLAGS='-march=native -O3' CPPFLAGS='-march=native -O3'
$ make -j 4

The gcc command line here will display which flags -march=native will activate.