On Thu, Jan 31, 2008 at 02:36:03PM -0000, mark wrote:
> please anyone help me determine the problem here.
> i have this sample program compiled and run with gcc for windows.
>
> #include <stdio.h>
> int main()
> {
> printf("HI HELLO!");
> return 0;
>
> }
>
> Then it doesn't make, build or compile, just generating this error
> message:
>
> g++.exe -x c++ -c E:\mark\C files\mark11.c -o E:\mark\C files\mark11.o
> -Wall -fpermissive -fconserve-space
> g++.exe: cannot specify -o with -c or -S and multiple compilations
> Failure
>
> What's wrong with my program?
> Did i miss anything with my compiler?
You need quotes around filenames with spaces in them. This should work:
g++.exe -x c++ -c "E:\mark\C files\mark11.c" -o "E:\mark\C files\mark11.o"
-Wall -fpermissive -fconserve-space
However, you have some other problems that may need addressing:
1. Your source code is written in C, but you're compiling it with 'g++', a
C++ compiler. Fairly harmless in this case, but you should generally
use 'gcc' for C code.
2. "-x c++" is redundant when using g++. g++ defaults to compiling in
C++ mode. As I wrote above, use gcc for compiling C code.
3. You can avoid using double quotes around filenames with gcc if you
set the working directory using 'cd':
e:
cd "\mark\C files"
Then use gcc:
gcc -c mark11.c -o mark11.o -Wall
4. "-Wall" is good, and you should probably use "-W" too, but
-fpermissive and -fconserve-space are obscure options to pass to gcc!
Those two are really unnecessary if you're just doing the basics. You
can leave them out unless you're sure you have a particular need for
them.
5. If you use '-c', it tells the compiler to make an .o (object) file.
You could've left out the
-o "E:\mark\C files\mark11.o"
part and gcc would still create mark11.o because you specified -c.
6. .o object files aren't executable. You need to create an executable
file from the object file and the "standard library". This is called
"linking". On Windows, executable end in .exe. On Linux & BSD,
executables generally have no extension. Either way, once mark11.o has
been created, you can do:
gcc -o mark11.exe mark11.o
7. BUT! There is an easier way! You can skip the creation of the .o
file and just make the .exe file like this:
gcc -W -Wall -o mark11.exe mark11.c
8. BUT WAIT! There is an even easier way! You probably have 'make'
installed. Make is intelligent enough so you can type:
make mark11
And it will call gcc with the correct options to build mark11.exe
automatically from mark11.c. Later on, you could learn how to write
your own makefile, but that's another story.