Try to compile your code normally as
gcc test.c
If you get default output file a.exe,then go for
gcc test.c -o test.exe
Try to compile your code normally as
gcc test.c
If you get default output file a.exe,then go for
gcc test.c -o test.exe
I would suggest you go through this compilation instruction :-
gcc -o test.exe test.c
I believe this code runs perfectly on your windows system.Please inform if it doesn't!
gcc - How do I compile a C/C++ program through windows command prompt? - Stack Overflow
How to compile a C program with gcc? - Stack Overflow
What is the correct way to compile c code
Compiling a C++ program with GCC - Stack Overflow
Videos
if you have codeblocks installed with mingw as the gcc compiler then follow these steps
- Right click on my computer -> go to properties -> advance system settings
- Then make an environment variable named PATH and paste the complete url like program file (x86)/codeblocks/mingw/bin.
- now open cmd
- go to the directory where your program is saved.
- type gcc program_name.c -o program_name.exe to compile the program.
- run the program by typing program_name
Please read Compile Programs with MinGW -- A Guide for New Users.
To make gcc produce assembler code, use -S option:
-S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s. Input files that don't require compilation are ignored.
Good luck!
You need to run
Copygcc b.c -o b.exe
Without -o option it'll use the default output executable name which is a.exe on Windows and a.out on *nix systems. You can easily see the a.exe with the dir command
-o file
Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.
If
-ois not specified, the default is to put an executable file ina.out, the object file for source.suffix insource.o, its assembler file insource.s, a precompiled header file insource.suffix.gch, and all preprocessed C source on standard output.https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html
For more information read Determining C executable name
Of course you can also run a instead of b
Compile like this
Copygcc -o b b.c
by specifying output filename
Copy-o <output_file>
I've got a program that is split into header files and c files along with the main. I was told to do gcc main.c <library.c>... for every other code but i don't remember having to do that when I've done stuff with header files in the past. How are you supposed to do this. Also are you supposed to include the headerfile in the .c version that the header is declaring the functions from? Sorry for my lack of technical terms. I'm exhausted today
gcc can actually compile C++ code just fine. The errors you received are linker errors, not compiler errors.
Odds are that if you change the compilation line to be this:
Copygcc info.C -lstdc++
which makes it link to the standard C++ library, then it will work just fine.
However, you should just make your life easier and use g++.
Rup says it best in his comment to another answer:
[...] gcc will select the correct back-end compiler based on file extension (i.e. will compile a .c as C and a .cc as C++) and links binaries against just the standard C and GCC helper libraries by default regardless of input languages; g++ will also select the correct back-end based on extension except that I think it compiles all C source as C++ instead (i.e. it compiles both .c and .cc as C++) and it includes libstdc++ in its link step regardless of input languages.
If you give the code a .c extension the compiler thinks it is C code, not C++. And the C++ compiler driver is called g++, if you use the gcc driver you will have linker problems, as the standard C++ libraries will not be linked by default. So you want:
Copyg++ myprog.cpp
And do not even consider using an uppercase .C extension, unless you never want to port your code, and are prepared to be hated by those you work with.