gcc/g++ : does the positions of options matter

Hi,

Though I have some experience in C/ C++ programming, I am new to Linux.

My questions are regarding various compiler option (gcc/ g++) option.

1) It appears to me that mostly relative positions of options do not matter. Could someone please tell me when would these position matter?

2) gcc vs g++: When to choose one over other? (I used to think that g++ has something to do with C++ :()

Thanks,
Dushyant

> It appears to me that mostly relative positions of options do not matter

Yes.

> when would these position matter?

Among the commonly used options, the position of an option specifying a library to link with is significant. In general, put these right at the end.

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.
https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Link-Options.html#Link-Options


> gcc vs g++: When to choose one over other?

gcc is the C compiler driver; use it to compile C code
g++ is the C++ compiler driver; use it to compile C++ code
Last edited on
It is possible to use gcc for C++ code but then you will have to pass some extra options. Easier to use g++.
Last edited on
Topic archived. No new replies allowed.