14

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?

asked Sep 13, 2010 at 7:15

4 Answers 4

10

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.

answered Sep 13, 2010 at 7:23
Sign up to request clarification or add additional context in comments.

4 Comments

I don't think that will work because the configure file is just a few statements and doesn't do anything.
Well then it's probably not built with the autotools. If you gave us more detail we might be able to help.
This guy will probably be hit several times in the next year as the latest upgrade to Ubuntu 11.04 and gcc-4.5.2 breaks gcc. I had to do this to get gst-ffmpeg to compile. I had to do something like. ./configure --prefix=/usr CC=gcc-4.4. To help searches find this link. here is the compiler error:
This will probably be hit a ton in the next year. The latest ubuntu upgrade breaks some optimizations with gcc-4.5.2 and to get gst-ffmpeg to compile I had to use ./configure --prefix=/usr CC=gcc-4.4. For searching, here is the error: internal compiler error: in set_jump_prob, at stmt.c:2319
1

If editing the configuration/Makefile is not an option, Linux includes a utility called update-alternatives for such situations. However, it's a pain to use (links to various tutorials included below).

This is a little simpler - here's a script (from here) to easily switch your default gcc/g++ version:

#!/bin/bash 
usage() {
 echo 
 echo Sets the default version of gcc, g++, etc
 echo Usage:
 echo 
 echo " gcc-set-default-version <VERSION>"
 echo 
 exit
}
cd /usr/bin
if [ -z 1ドル ] ; then 
 usage;
fi 
set_default() {
 if [ -e "1ドル-2ドル" ] ; then 
 echo 1ドル-2ドル is now the default
 ln -sf 1ドル-2ドル 1ドル
 else 
 echo 1ドル-2ドル is not installed
 fi
}
for i in gcc cpp g++ gcov gccbug ; do 
 set_default $i 1ドル
done

If you 1) name this script switch-gcc, 2) put it in your path, and 3) make it executable (chmod +x switch-gcc), you can then switch compiler versions just by running

sudo switch-gcc 3.2

Further reading on update-alternatives:

answered Oct 23, 2017 at 23:29

1 Comment

update-alternatives is a debian/ubuntu thing afaik, not a general linux utility. Some distros use other means of selecting versions of tooling in a similar way though, but it depends on which distro you are using.
0

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

answered Sep 13, 2010 at 7:21

2 Comments

It's not my program. I'm using make.
Try to add this line to the Makefile: CC=/path_to_gcc_3.4/gcc
0

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.

answered Sep 13, 2010 at 7:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.