1

I just downloaded the GCC compile for C/C++. After compiling with the command gcc main.c -c -lGL -lGLU -lglut I get a permission error which can be fixed by changing the permissions. I then get this error: bash: ./main.o: cannot execute binary file: Exec format error. Will you help me fix this? Also if it helps I'm using C.

-Thank you in advance

Dequog
  • 55
  • It looks like it might be the wrong architecture: https://askubuntu.com/q/648555 . What does file ./main.o return? or if main.o is not in the current directory, find the file and then run the file command on the main.o to show what type of file it is. – mchid Sep 23 '21 at 19:00
  • It might be possible that it was compiled for the wrong architecture but there could be other reasons. Also, did you install GCC by running sudo apt install build-essential ? This is the recommended way to download and install GCC. – mchid Sep 23 '21 at 19:07
  • 1
    After compiling how, exactly? The fact that your command produced a .o file suggests you added the -c option, which suppresses linking to a final executable file – steeldriver Sep 23 '21 at 19:09
  • @mchid Idk I forget how I installed the gcc compiler, but I did install the build-essential package after if that makes a difference – Dequog Sep 23 '21 at 19:35
  • @steeldriver I updated the question with the exact command I used – Dequog Sep 23 '21 at 19:35
  • 2
    @Dequog right - so remove the -c (and optionally add -o progname if you want the executable to be named progname rather than the default a.out). – steeldriver Sep 23 '21 at 19:47
  • @steeldriver now I'm getting this error: /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function _start': (.text+0x24): undefined reference to 'main' collect2: error: ld returned 1 exit status – Dequog Sep 23 '21 at 19:57
  • 1
    Does main.cpp actually contain a main function? Is it really C or is it C++ (as suggested by the .cpp suffix)? If the latter, use g++ in place of gcc. If the former (C with a .cpp suffix) you may need to add -xc to direct gcc appropriately. – steeldriver Sep 23 '21 at 20:03
  • sorry I meant to put main.c and yes it does contain the main() function also the -xc command does nothing – Dequog Sep 23 '21 at 21:00
  • 2
    Did you download the C compiler from a non-Ubuntu source? Why not use the C compiler from the packaging system? – waltinator Sep 23 '21 at 23:37
  • @waltinator I did use the c compiler from the packaging system – Dequog Sep 23 '21 at 23:59
  • 1
    @mchid no because 1. I defined a main function 2. my original command has the -c part which causes the other problem – Dequog Sep 24 '21 at 00:57
  • 1
    I don't understand why the compiler needed downloading. My understanding is that gcc is built-in to all Ubuntu desktop versions. – NickT Sep 24 '21 at 08:06
  • @NickT Hey sorry it took me so long to answer, but not the gcc compiler wasn't automatically installed for me. Does it have something to do with me using the LTS version – Dequog Sep 25 '21 at 14:56
  • It seems that I asked the very same question last year. Opinions vary as to whether it was built-in. See https://askubuntu.com/questions/1276468/does-ubuntu-20-04-1-lts-not-come-with-a-c-compiler-by-default – NickT Sep 26 '21 at 10:56
  • I just for got to save the file sorry – Dequog Sep 30 '21 at 23:02
  • When I compiled a program in Ubuntu, then moved the project (it was meson-based) into my Raspberry Pi, this warning printed. The fix was to rebuild. – ADBeveridge Nov 15 '21 at 03:10

0 Answers0