How to use an older version of gcc in Linux

前端 未结 4 1221
太阳男子
太阳男子 2020-12-20 13:39

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 gc

4条回答
  •  半阙折子戏
    2020-12-20 14:17

    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.

提交回复
热议问题