Question:
What is the correct command to compile C program say test.c?
?
2017-08-31 18:12:19 UTC
gcc test.c -o test // command 1
gcc test -o test // command 2
gcc test.c -o test.c // command 3
gcc Test.c -l test // command 4
Nine answers:
sabuj
2017-09-04 19:28:16 UTC
GCC (GNU Compiler Collection. Upper case.) is a set of compilers, that can compile several languages.
sergio armando h
2017-09-02 15:08:26 UTC
the first
DrZoo
2017-09-01 20:14:04 UTC
Command 1. gcc test.c -o test



This will compile the file test.c and give you a file called test that you can execute by doing ./test
?
2017-09-01 09:24:10 UTC
GCC (GNU Compiler Collection. Upper case.) is a set of compilers, that can compile several languages.
Max
2017-08-31 20:24:43 UTC
I highly recommend using an IDE like CLion by JetBrains or even Visual Studio by Microsoft. Therefore, if something fails, you will have an easier time repairing it, and it has a built in complier to save you time and effort. To answer your question, you should run "gcc "filename" -o "flags"" So if your file was called "Main", and you didn't have any flags, you would run gcc Main.c -o
SteveO
2017-08-31 18:54:26 UTC
If you're trying to name the output executable as "test", then the first command is correct. I might also suggest that you migrate to Clang if at possible unless you need to use other languages that GCC supports, like Ada or Fortran, to move away from the GPL license. I say this, however, as someone who has a philosophical disagreement with the GPL, so I am biased. Clang is overall better for C and C++ in many instances anyway though, so the performance difference is enough to warrant the switch.
PoohBearPenguin
2017-08-31 18:26:52 UTC
None of the above.



You can just do:



gcc test.c



(assuming your file is named "test.c")



gcc will generate an object file with the same filename (without the extension) by default.



Or if you wanted it to generate an object file named "foo" then again, none of the above is correct as you'd do:



gcc test.c -o foo
johnson
2017-08-31 18:14:12 UTC
no
Spock (rhp)
2017-08-31 18:13:22 UTC
which compiler is that? [i don't recognize the command line as mine has a visual interface]


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...