I would like to compile a C program that I made for my raspberry pi from my PC.
My program uses the rt, pthread and cython libraries.
I use the arm-linux-gnueabihf-gcc compiler for this and I made a makefile:
CC = gcc
CC_ARM = arm-linux-gnueabihf-gcc
CFLAGS = -I -g -Wall
INCLUDES = -I/usr/include/python3.8 -I/
LIBS = -lrt -lpthread -lpython3.8
SRCS = main.c Config_radio.c
OBJS = $(SRCS:.c=.o)
MAIN = radio
ARM = radio_arm
.PHONY: depend clean
all: $(MAIN)
@echo radio has been compiled
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
$(ARM): $(OBJS)
$(CC_ARM) $(CFLAGS) $(INCLUDES) -o $(ARM) $(OBJS) $(LFLAGS) $(LIBS)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) *.o *~ $(MAIN)
depend: $(SRCS)
makedepend $(INCLUDES) $^
When I compile with gcc, the compilation succeed but when I try to compile with arm-linux-gnueabihf-gcc I get the following error:
make radio_arm
gcc -I -g -Wall -I/usr/include/python3.8 -I/ -c main.c -o main.o
gcc -I -g -Wall -I/usr/include/python3.8 -I/ -c Config_radio.c -o Config_radio.o
arm-linux-gnueabihf-gcc -I -g -Wall -I/usr/include/python3.8 -I/ -o radio_arm main.o Config_radio.o -lrt -lpthread -lpython3.8
main.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
make: *** [Makefile:28 : radio_arm] Erreur 1
I think my libraries don't work with arm-linux-gnueabihf-gcc.
Can you explain to me how to solve this ?
CodePudding user response:
You used gcc
to compile main.o
. That GCC is presumably the native compiler of your x86 system. Therefore, main.o
will have x86 code in it and it cannot be linked into an ARM program.
Make sure all your objects and all the libraries you are linking were compiled with the ARM toolchain and then things should be fine.
Also, the -I/usr/include/python3.8
looks like a problem to me because those will be the headers for the native Python on your system, not a Python that has been cross-compiled for ARM. It might work, but it seems pretty risky. Also -I
by itself and -I/
don't really make sense.