Author Topic: Fix for Warning: cmd line option '-std=c11' is valid for C/ObjC but not for C++  (Read 626 times)

Offline Robert Eastwood

  • Multiple posting newcomer
  • *
  • Posts: 13
That is a warning you get when trying to compile a CPP file with a C option. Codeblocks solved this problem by adding a right click to compiler options, and at that location it lists items to exclude.  In the C Only box -std=c11 is said to be excluded.

So you should never see that warning.

Unless

You add that option in project build option settings AND the compiler setting option.  In that case when the removal of c flags from cpp builds is done, it only removes one of the two times you added the flags

You add in compiler settings   -std=c11
And you add in project settings -std=c11

and this code only removes one of them when building cpp file

In sdk\compilercommandgenerator.cpp line 380

Code: [Select]
[size=8pt][font=courier]
 wxString cFlags = m_CFlags[target];
    wxArrayString remFlags;
    if (compExec == ceC)
        remFlags = GetArrayFromString(compiler->GetCPPOnlyFlags(), wxT(" "));
    else if (compExec == ceCPP)
        remFlags = GetArrayFromString(compiler->GetCOnlyFlags(), wxT(" "));
    if (!remFlags.IsEmpty())
    {
        wxArrayString aCflags = GetArrayFromString(cFlags, wxT(" "));
        for (size_t i = 0; i < remFlags.GetCount(); ++i)
        {
            int index = aCflags.Index(remFlags[i]);
            if (index != wxNOT_FOUND)
                aCflags.RemoveAt(index);
        }
        cFlags = GetStringFromArray(aCflags, wxT(" "), false);
    }
[/font][/size]

to fix this we need to remove all possible flags on the list, not just one of them

Code: [Select]
[size=8pt][font=courier]
   wxString cFlags = m_CFlags[target];
    wxArrayString remFlags;
    if (compExec == ceC)
        remFlags = GetArrayFromString(compiler->GetCPPOnlyFlags(), wxT(" "));
    else if (compExec == ceCPP)
        remFlags = GetArrayFromString(compiler->GetCOnlyFlags(), wxT(" "));
    if (!remFlags.IsEmpty())
    {
        wxArrayString aCflags = GetArrayFromString(cFlags, wxT(" "));
        for (size_t i = 0; i < remFlags.GetCount(); ++i)
        {
//RE_CODE_CHANGE while loop used to remove multiple same flags in config script
            int index = aCflags.Index(remFlags[i]);
            while (index != wxNOT_FOUND)
   {
                aCflags.RemoveAt(index);
index = aCflags.Index(remFlags[i]);
   }
//RE_CODE_CHANGE END
        }
        cFlags = GetStringFromArray(aCflags, wxT(" "), false);
    }
[/font][/size]


If someone with SVN change rights wants to add that change it will fix the issue that made it where in some cases the option exclusion list was not excluding even when an option was listed there.

another method would be to check the command line for duplicates and delete them before doing that step of removing c cpp exclusive commands, if there are no reasons for duplicates and there are no reasons a user might want to know if he added same command option twice, this code could be added but it really is a design decision.
Code: [Select]
[size=8pt][font=courier]
    // Special handling for compiler options to filter between C and C++ compilers
    wxString cFlags = m_CFlags[target];

//RE_CODE_CHANGE remove duplicate flags
wxArrayString aCflagsRemoveDups = GetArrayFromString(cFlags, wxT(" "));
wxArrayString aCflagsNoDups;
aCflagsNoDups.Empty();
if(!aCflagsRemoveDups.IsEmpty())
{
for (size_t i = 0; i < aCflagsRemoveDups.GetCount(); ++i)
               {
int index = aCflagsNoDups.Index(aCflagsRemoveDups[i]);
if(index == wxNOT_FOUND)
{
aCflagsNoDups.Add(aCflagsRemoveDups[i]);
}
}
cFlags = GetStringFromArray(aCflagsNoDups, wxT(" "), false);
}
aCflagsRemoveDups.Clear();
aCflagsNoDups.Clear();
//RE_CODE_CHANGE END remove duplicate flags

    wxArrayString remFlags;   
if (compExec == ceC)[/font][/size]

Either one of those fixes solves that problem that created some confusion where someone said they were seeing that warning, when they had the warning listed in exclusion box to be only used for c or cpp compiling.

Offline Miguel Gimenez

  • Regular
  • ***
  • Posts: 341
The best method for proposing a change is creating a patch file (using svn diff > fix.patch) and attach it to a ticket. In the forum the messages are soon forgotten and the patches lost.

Offline Robert Eastwood

  • Multiple posting newcomer
  • *
  • Posts: 13
The best method for proposing a change is creating a patch file (using svn diff > fix.patch) and attach it to a ticket. In the forum the messages are soon forgotten and the patches lost.

I don't have much skill in SVN and don't have a SVN setup on my laptop, only place I look at stuff such as this code.
You are right it is a better approach, and thanks for advice, although currently outside of my setup.

Not that big of a need anyways, but some probably wondered why that was occuring

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6636
    • My Best Post
If you have skill in git, there are Code::Blocks git repos that you can use, instead.

But, they are often a few to many commits behind the official SVN repo.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Robert Eastwood

  • Multiple posting newcomer
  • *
  • Posts: 13
If you have skill in git, there are Code::Blocks git repos that you can use, instead.

But, they are often a few to many commits behind the official SVN repo.

Tim S.

I am looking into using TortoiseSVN It seems functional on windows 10.
However I am waiting till I can afford a new SSD drive before using SVN features

I recently noticed that source from 17.12 release and latest and greatest has quite a few changes, so currently am Downloading snapshots and hoping I get all the recent  updates by doing that.