I'm trying to compile a program (the splash2x.raytrace
package of the PARSEC benchmark suite, after transformations) on two architectures - amd64 and riscv64; however, when I try to natively compile it on both, I get a different behavior that I can't explain.
Specifically, while on amd64 it compiles, on riscv64 it fails with a lot of multiple definition of...
.
The program has around a dozen .c
files, and one header, included in all of them ("rt.h
").
A sample variable is:
# File: rt.h
INT prims_in_leafs;
which causes the errors:
/usr/bin/ld: cr.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: multiple definition of `prims_in_leafs'; bbox.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: first defined here
/usr/bin/ld: env.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: multiple definition of `prims_in_leafs'; bbox.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: first defined here
/usr/bin/ld: fbuf.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: multiple definition of `prims_in_leafs'; bbox.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: first defined here
/usr/bin/ld: geo.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: multiple definition of `prims_in_leafs'; bbox.o:/home/riscv/parsec-benchmark/ext/splash2x/apps/raytrace/obj/riscv64-linux.gcc/rt.h:750: first defined here
The commands used for the compilation are very simple:
gcc -c -static-libgcc -pthread *.c
gcc *.o -pthread -o raytrace -L/usr/lib64 -L/usr/lib -lm
Now, I've found that the header file has no header guard, so I suppose that in some way, on amd64 this file is included only once, while on riscv64 multiple times.
On the other hand, the include "rt.h"
is on top of each file, outside any #ifdef
, so I can't explain why it succeds on amd64, and even with a header guard, it still fails on riscv64.
The differences in the systems are:
- amd64: GCC 9.3 on ubuntu, riscv64=10.2
- riscv64: GCC 10.2 on fedora
I suppose I could manually change all variables etc, but that would be a lot of work, and it still doesn't explain the difference.
What's happening? How can I make the program compile?
Sample files here:
rt.h
: https://pastebin.com/QKjvSe02main.c
: https://pastebin.com/bT7meaMNcr.c
: https://pastebin.com/Trck6imWgeo.c
: https://pastebin.com/JY67u2Xe