You are not logged in.
Pages: 1
For whatever resason, I am currently able to compile C applications(as It executes with errors if any), just like so -> gcc -c test.c -o test.o… of course making sure it is executable, however I believe my mistake is trying to run the output(./test gives me a format error, perhaps I need to build&compile my kernel with certain modules that I forgot to add)? Im not sure what I am doing wrong as I am simply looking to jumpstart on learning linux however program won’t even properly produce desired output.
Offline
gcc -c test.c -o test.o…
Did you link executable after compilation? "gcc -c test.c test.o" produces object file, not executable. See https://man.archlinux.org/man/gcc.1#c
If your program consits of single source file, you can either compile and link it with one command:
$ gcc -o test test.cor compile to object file and link object file to executable:
$ gcc -c test.c
$ gcc -o test test.o of course making sure it is executable
Gcc already sets executable bit for produced executables.
./test gives me a format error
Please show exact commands you execute and error message.
Offline
That is the exact command I execute(.test.o). Sorry full filename wasnt in output though im sure that doesnt matter. I did try executing this set pf commands afterwards however, which that last job was what gave me no output. The first gave me, again, ‘format error’
Offline
That is the exact command I execute(.test.o).
Please don't paraphrase, https://bbs.archlinux.org/viewtopic.php?id=57855
@dimich told you that what you originally suggested will NOT produce an executable and then explained how to do that.
Post your interaction w/ gcc verbatim (all input and output), the source file you're trying to compile and the resulting binary.
See the first link below for a bunch of upload options.
Offline
reggieArchExpert wrote:gcc -c test.c -o test.o…
Did you link executable after compilation? "gcc -c test.c test.o" produces object file, not executable. See https://man.archlinux.org/man/gcc.1#c
If your program consits of single source file, you can either compile and link it with one command:$ gcc -o test test.cor compile to object file and link object file to executable:
$ gcc -c test.c $ gcc -o test test.oreggieArchExpert wrote:of course making sure it is executable
Gcc already sets executable bit for produced executables.
Thanks man, above example was what I needed to finally gain desirable outputreggieArchExpert wrote:./test gives me a format error
Please show exact commands you execute and error message.
Problem solved, so doubt output will be necessary. Though further on to this problem, why would simply giving desired '-o' flag be enough instead of doing all on one command(i.e again as you say "you can either compile and link it with one command"... in my mind, that would be like this no?
gcc -c test.c -o test.o
...
Your first example(though also works, appreciate the verbosity) simply just doesn't make sense in my mind. Don't we have to compile the code first, or perhaps simply order doesn't matter
Offline
Offline
why would simply giving desired '-o' flag be enough instead of doing all on one command(i.e again as you say "you can either compile and link it with one command"... in my mind, that would be like this no?
gcc -c test.c -o test.o
I'm not sure I understand your question.
If no output file name given, with '-c' flag output name is created from source file name by replacing '.c' suffix with '.o'. So
gcc -c test.cis the same as
gcc -c test.c -o test.oIt compiles 'test.c' into 'test.o' object file.
Compilation stage expects only one source file. Order of '-c', '-o test.o' and 'test.c' arguments doesn't matter.
Without '-c' default name for output executable is 'a.out'. Using '-o' option you can override it to any desired name.
Linking stage assumes multiple input files. Gcc tries to recognize input file format by suffix, and if it's known source file, preprocesses/compiles it first (https://man.archlinux.org/man/gcc.1#Opt … _of_Output).
Edit: clarified gcc behavior.
Last edited by dimich (Yesterday 17:30:30)
Offline
Offline
Pages: 1