Score:1

GCC compiling problem

es flag

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

mchid avatar
bo flag
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 avatar
bo flag
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.
hr flag
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
Dequog avatar
es flag
@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 avatar
es flag
@steeldriver I updated the question with the exact command I used
hr flag
@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`).
Dequog avatar
es flag
@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`
hr flag
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.
Dequog avatar
es flag
sorry I meant to put `main.c` and yes it does contain the `main()` function also the `-xc` command does nothing
waltinator avatar
it flag
Did you download the C compiler from a non-Ubuntu source? Why not use the C compiler from the packaging system?
Dequog avatar
es flag
@waltinator I did use the c compiler from the packaging system
mchid avatar
bo flag
[Does this help?](https://stackoverflow.com/a/7965472)
Dequog avatar
es flag
@mchid no because 1. I defined a main function 2. my original command has the `-c` part which causes the other problem
kn flag
I don't understand why the compiler needed downloading. My understanding is that gcc is built-in to all Ubuntu desktop versions.
Dequog avatar
es flag
@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
kn flag
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
Dequog avatar
es flag
I just for got to save the file sorry
ADBeveridge avatar
lb flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.