17

I trying to cross compile form Ubuntu to Friendly-arm but I'm getting the strange error:

root@kevin-VirtualBox:/home/kevin/Desktop/makef# make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-l
gcc -o main obj/main.o obj/serial.o obj/fb.o obj/menu_main.o obj/timer.o obj/cmdin.o obj/buzzer.o obj/statemachine.o obj/inout.o obj/network.o obj/text_file_input.o obj/text_file_input_oven.o -I./ -lgd -lrt
/usr/bin/ld: obj/main.o: Relocations in generic ELF (EM: 40)
obj/main.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [main] Error 1

command line : make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-l

Makefile: (updated)

export ARCH:=arm
export CROSS_COMPILE:=arm-none-linux-gnueabi

IDIR =./
CC=arm-linux-gnueabi-gcc
CFLAGS=-I$(IDIR)

LD= //opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi/bin/

ODIR=obj
LDIR =./

LIBS=-lgd -lrt

_DEPS = main.h Makefile
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

_OBJ = main.o serial.o fb.o menu_main.o timer.o cmdin.o buzzer.o statemachine.o inout.o network.o text_file_input.o text_file_input_oven.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))


$(ODIR)/%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

main: $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean:
    rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ 

New errors after updating Makefile:

root@kevin-VirtualBox:/home/kevin/Desktop/makef# make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi -l
gcc -o main obj/main.o obj/serial.o obj/fb.o obj/menu_main.o obj/timer.o obj/cmdin.o obj/buzzer.o obj/statemachine.o obj/inout.o obj/network.o obj/text_file_input.o obj/text_file_input_oven.o -I./ -lgd -lrt
/usr/bin/ld: obj/main.o: Relocations in generic ELF (EM: 40)
obj/main.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: [main] Error 1 (ignored)
arm-linux-gnueabi-gcc -o main obj/main.o obj/serial.o obj/fb.o obj/menu_main.o obj/timer.o obj/cmdin.o obj/buzzer.o obj/statemachine.o obj/inout.o obj/network.o obj/text_file_input.o obj/text_file_input_oven.o -I./ -lgd -lrt
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: warning: libz.so.1, needed by /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/lib/../lib/libgd.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: warning: libexpat.so.1, needed by /usr/arm-linux-gnueabi/lib/libfontconfig.so.1, not found (try using -rpath or -rpath-link)
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_GetBuffer'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_GetErrorCode'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/lib/../lib/libgd.so: undefined reference to `compress'
/usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflate'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetDoctypeDeclHandler'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ParserCreate'
/usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `crc32'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_GetCurrentLineNumber'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/lib/../lib/libgd.so: undefined reference to `uncompress'
/usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflateReset'
/usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflate'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetCharacterDataHandler'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ParserFree'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetUserData'
/usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflateInit2_'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ParseBuffer'
/usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflateEnd'
/usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `deflateEnd'
/usr/arm-linux-gnueabi/lib/libpng12.so.0: undefined reference to `inflateInit_'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_ErrorString'
/usr/arm-linux-gnueabi/lib/libfontconfig.so.1: undefined reference to `XML_SetElementHandler'
/usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflateInit2_'
/usr/arm-linux-gnueabi/lib/libfreetype.so.6: undefined reference to `inflateReset'
collect2: ld returned 1 exit status
make: *** [main] Error 1
root@kevin-VirtualBox:/home/kevin/Desktop/makef# 

the makefile works after your comment (thank you) and creates a main file the only error im getting is : warning: format not a string literal and no format arguments [-Wformat-security] but it dossent seem to be critical

kevin ver
  • 831
  • 4
  • 14
  • 37
  • The output that you have posted now (as of 18:50) does not match your Makefile. –  Apr 20 '14 at 19:11
  • The output indicates that the compiler is being run twice, once as `gcc` (or possibly `cc`) and the second time as `arm-linux-gnueabi-gcc`. This is not possible with the version of the Makefile in your question. –  Apr 20 '14 at 23:18

3 Answers3

13

It looks like you PREVIOUSLY tried to compile with a different toolchain (e.g. x86), and the object files are still there from that build.

Try using

 make clean
Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • make clean returns 'rm -f obj/*.o *~ core /*~ ' and removes all the .o files. When i run make i get the same error – kevin ver Apr 20 '14 at 18:15
  • Ah, yes, I notice that @duskwuff has spotted another problem - it's the same "type of error" (mixing tools), but caused by a different scenario. – Mats Petersson Apr 20 '14 at 18:21
  • updated the question whit the resulted of @duskwuff suggestion – kevin ver Apr 20 '14 at 18:31
  • Looks like you are missing some libraries (some sort of compression/decompression library - not sure if it's libz or something else - and some XML library by the looks of things). – Mats Petersson Apr 20 '14 at 18:35
11

As written, this Makefile is BROKEN for cross-compilation — it does not use the $(CC) variable consistently, so it cannot compile to a non-native architecture.

To fix it, change cc to $(CC) in the stanza for main, i.e:

 main: $(OBJ)
-    gcc -o $@ $^ $(CFLAGS) $(LIBS)
+    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
  • getting some other errors after updating the makefile – kevin ver Apr 20 '14 at 18:29
  • The `-` and `+` were intended as patch indicators, not as literal text in the Makefile. The errors involving libz and libexpat appear to indicate you don't have those libraries installed correctly for your crosscompile system. –  Apr 20 '14 at 18:46
  • @kevinver The errors you post now are linker errors, you seem to use various libraries that you must link to, e.g. libz, libpng, and libxml2 and possibly others. (And you might need to cross compile those first too ) – nos Apr 20 '14 at 18:55
  • I've got similar trouble and I worked it out using idea got here. I compiled .o files in .a using $(CXX) which was for cross-compilation, but compiled main program's .o using gcc. No wonder the library can't be linked to main program. They have different target environment setting. I changed gcc to $(CXX) in compilation command of main program and link command, it works. – Stan Huang at Taiwan Jan 28 '19 at 03:30
0

I was having a similar problem and clean did not help. I ended up deleting the build folder and rebuilding, it worked.

J.Sunderland
  • 50
  • 1
  • 3