When I compile on macOS it works, however in Ubuntu it does not, and instead I get this error:
main.o: file not recognized: File format not recognised
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'traffic' failed
make: *** [traffic] Error 1
I know that the main.o is corrupt but even after 'make clean' no matter what this error pops up. How do I fix this so that a corrupt object file is not made. (using ansi as teacher wishes C89)
My Makefile:
CC = gcc
CFLAGS = -Wall -ansi -pedantic -Werror
OBJ = main.o initialise.o cars.o movement.o newSleep.o random.o terminal.o
EXEC = traffic
$(EXEC) : $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $(EXEC)
main.o : main.c initialise.h cars.h movement.h newSleep.h random.h terminal.h macros.h
$(CC) $(CFLAGS) -c main.c
initialise.o : initialise.c initialise.h macros.h
$(CC) $(CFLAGS) -c initialise.c
cars.o : cars.c cars.h random.h macros.h
$(CC) $(CFLAGS) -c cars.c
movement.o : movement.c movement.h
$(CC) $(CFLAGS) -c movement.c
newSleep.o : newSleep.c newSleep.h
$(CC) $(CFLAGS) -c newSleep.c
random.o : random.c random.h
$(CC) $(CFLAGS) -c random.c
terminal.o : terminal.c terminal.h
$(CC) $(CFLAGS) -c terminal.c
clean :
rm -f $(EXEC) $(OBJ)
Output of make clean; make
rm -f traffic main.o initialise.o cars.o movement.o newSleep.o random.o terminal.o
gcc -Wall -ansi -pedantic -Werror -c main.c
gcc -Wall -ansi -pedantic -Werror -c initialise.c
gcc -Wall -ansi -pedantic -Werror -c cars.c
gcc -Wall -ansi -pedantic -Werror -c movement.c
gcc -Wall -ansi -pedantic -Werror -c newSleep.c
gcc -Wall -ansi -pedantic -Werror -c random.c
gcc -Wall -ansi -pedantic -Werror -c terminal.c
gcc -Wall -ansi -pedantic -Werror main.o initialise.o cars.o movement.o newSleep.o random.o terminal.o -o traffic
main.o: file not recognized: File format not recognised
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'traffic' failed
make: *** [traffic] Error 1
Output of file *.o
cars.o: data
initialise.o: data
main.o: data
movement.o: data
newSleep.o: data
random.o: data
terminal.o: data
Output of gcc -dumpmachine
x86_64-linux-gnu
I am using the M2 chip. I am running Ubuntu on VMware Horizon Client
Output of gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
Output of file /bin/sh
I am very confused too
/bin/sh: symbolic link to dash
Output first couple lines ofod -tx1 -c main.o
0000000 00 6d 61 69 6e 2e 63 00 6d 61 69 6e 00 5f 47 4c
\0 m a i n . c \0 m a i n \0 _ G L
0000020 4f 42 41 4c 5f 4f 46 46 53 45 54 5f 54 41 42 4c
O B A L _ O F F S E T _ T A B L
0000040 45 5f 00 70 75 74 73 00 61 74 6f 69 00 6d 61 6c
E _ \0 p u t s \0 a t o i \0 m a l
0000060 6c 6f 63 00 70 72 69 6e 74 66 00 69 6e 69 74 69
l o c \0 p r i n t f \0 i n i t i
0000100 61 6c 69 7a 65 42 6f 78 00 70 6c 61 63 65 43 61
a l i z e B o x \0 p l a c e C a
Output of find $(dirname $(dirname $(which gcc))) -name collect2
Perhaps this is because I am using my universities virtual lab?
/usr/lib/gcc/x86_64-linux-gnu/7/collect2
find: ‘/usr/lib/vmware/viewagent/DesktopDaemon’: Permission denied
find: ‘/usr/lib/vmware/viewagent/bin’: Permission denied
find: ‘/usr/lib/vmware/viewagent/jre’: Permission denied
find: ‘/usr/share/pam-configs.pbis’: Permission denied
Output of file /bin/dash
/bin/dash: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=a783260e3a5fe0afdae77417eea7fbf8d645219e, stripped
Output of file $(which gcc)
/usr/bin/gcc: symbolic link to gcc-7
Output of /usr/bin/gcc*
/usr/bin/ld: error in /usr/bin/gcc-7(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: error in /usr/bin/gcc-ar(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: error in /usr/bin/gcc-ar-7(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: error in /usr/bin/gcc-nm(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: error in /usr/bin/gcc-nm-7(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: error in /usr/bin/gcc-ranlib(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: error in /usr/bin/gcc-ranlib-7(.eh_frame); no .eh_frame_hdr table will be created.
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Apologies, I have found the solution. The solution is not interesting at all. It turns out my university's virtual lab has malware protection built in, from a past incident, so you cannot compile or run any code unless the code is on the desktop.
Thank you for your help, it was not a waste as I learnt some very interesting information. It is quite ridiculous that this was the issue. I hope that if someone has a similar issue, the possible solutions commented could help somebody in the future, even if it did not solve mine.