views:

68

answers:

3

In Linux I am trying to compile something that uses the -fwritable-strings option. Apparently this is a gcc option that doesn't work in newer version of gcc. I installed gcc-3.4 on my system, but I think the newer version is still being used because I'm still get the error that says it can't recognize the command line option -fwritable-strings. How can I get make to use the older version of gcc?

A: 

If you can find where the writeable strings are actually being used, another possibility would be to use strdup and free on the subset of literal strings that the code is actually editing. This might be more complicated than downgrading versions of GCC, but will make the code much more portable.

Edit
In response to the clarification question / comment below, if you saw something like:

char* str = "XXX";
str[1] = 'Y';
str[2] = 'Z';
// ... use of str ...

You would replace the above with something like:

char* str = strdup("XXX");
str[1] = 'Y';
str[2] = 'Z';
// ... use of str ...
free(str);

And where you previously had:

char* str = "Some string that isn't modified";

You would replace the above with:

const char* str = "Some string that isn't modified";

Assuming you made these fixes, "-fwritable-strings" would no longer be necessary.

Michael Aaron Safyan
How does that work? Can you give an example?
awakeFromNib
A: 

Maybe you could just give the whole path of the gcc-3.4 install while compiling your program: /path_to_gcc_3.4/gcc your_program

itisravi
It's not my program. I'm using make.
awakeFromNib
Try to add this line to the Makefile: CC=/path_to_gcc_3.4/gcc
Thomas Padron-McCarthy
A: 

You say nothing about the build system in use, but usually old versions of gcc can be invoked explicitly, by something like (this is for an autotools-based build):

./configure CXX=g++-3.4 CC=gcc-3.4

For a make-based build system, sometimes this will work:

make CXX=g++-3.4 CC=gcc-3.4

Most makefiles ought to recognise overriding CC and CXX in this way.

Jack Kelly
I don't think that will work because the configure file is just a few statements and doesn't do anything.
awakeFromNib
Well then it's probably not built with the autotools. If you gave us more detail we might be able to help.
Jack Kelly