Author Topic: compilation of c::b fails in "compiler.cpp"  (Read 21650 times)

Offline cbnewbie

  • Multiple posting newcomer
  • *
  • Posts: 25
compilation of c::b fails in "compiler.cpp"
« on: June 04, 2013, 02:18:49 pm »
Hello!

I just downloaded c::b via svn an tried to compile it. But it fails with the following error:

compiler.cpp: In member function 'bool Compiler::EvalXMLCondition(const wxXmlNode*)':
compiler.cpp:1147:29: error: expected unqualified-id before numeric constant
compiler.cpp:1147:29: error: expected ';' before numeric constant

How can I fix it? I am using gcc-4.7.3 on Mageia 2 64-bit.

Hopefull regards,

    Markus

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: compilation of c::b fails in "compiler.cpp"
« Reply #1 on: June 04, 2013, 05:37:24 pm »
I cannot reproduce the error, but does this patch fix compilation?
Code
Index: src/sdk/compiler.cpp
===================================================================
--- src/sdk/compiler.cpp (revision 9138)
+++ src/sdk/compiler.cpp (working copy)
@@ -24,6 +24,7 @@
 #endif
 
 #include "compilercommandgenerator.h"
+#include "prep.h"
 #include <wx/arrimpl.cpp>
 #include <wx/filefn.h>
 #include <wx/xml/xml.h>

Offline cbnewbie

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: compilation of c::b fails in "compiler.cpp"
« Reply #2 on: June 05, 2013, 08:44:16 am »
It does not help. But "compiler.cpp" is not the only file with that problem. If I start compiling with "make -j" I get the following error messages:

Code
compiletargetbase.cpp: In member function 'void CompileTargetBase::GenerateTargetFilename(wxString&) const':
compiletargetbase.cpp:267:31: error: expected unqualified-id before numeric constant
compiletargetbase.cpp:267:31: error: expected ')' before numeric constant
configmanager.cpp: In member function 'void CfgMgrBldr::SwitchTo(const wxString&)':
configmanager.cpp:265:19: error: expected unqualified-id before numeric constant
configmanager.cpp:265:19: error: expected ')' before numeric constant
compiler.cpp: In member function 'bool Compiler::EvalXMLCondition(const wxXmlNode*)':
compiler.cpp:1148:29: error: expected unqualified-id before numeric constant
compiler.cpp:1148:29: error: expected ';' before numeric constant
editormanager.cpp: In member function 'void EditorManager::CollectDefines(CodeBlocksEvent&)':
editormanager.cpp:3222:28: error: expected unqualified-id before numeric constant
editormanager.cpp:3222:28: error: expected ')' before numeric constant

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: compilation of c::b fails in "compiler.cpp"
« Reply #3 on: June 07, 2013, 07:40:47 am »
There must be "lnux"-macro defined by your compiler or compiler call on your system.

For some reasons the undefine of linux in prep.h:219 :
Code
    #if defined ( linux )
        #undef linux
    #endif
must be overriden by a (system?) header after the include of prep.h.
Otherwise you would get the error in prep.h also.

You can try to change the definition of linux to cb_linux in prep.h and all places where it is used (platform::linux) respectively, to see if it works in this case.
Or put the above code-snippet into the files where it failed after all headers are included, to see if it works.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: compilation of c::b fails in "compiler.cpp"
« Reply #4 on: June 07, 2013, 07:36:55 pm »
I've committed a fix in rev 9141.

The fix is along the line Jens has posted. Similar fix should have been used long long ago when we dealt with this issue. :)
Be a part of the solution, not a part of the problem.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: compilation of c::b fails in "compiler.cpp"
« Reply #5 on: June 10, 2013, 11:02:24 am »
I'm not happy with this. This is not a fix for a problem in our code, but a fix for a broken compiler (or system headers).

Non-double-underscore, non-leading-underscore-capital-letter identifier in non-global namespace (and not-leading-underscore idendifier in any namespace) are not reserved and may be used. What we are doing is correct.

The system header that defines linux should instead define _Linux or __linux or __linux__. Of course, if it doesn't, that's bad luck for someone trying to build Code::Blocks, but still the "fix" is not addressing the problem.

Look at it this way, some disturbed person might add #define if else or #define protected private to their system headers -- does that mean we're not allowed to use the if keyword and can't have protected members in our code?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: compilation of c::b fails in "compiler.cpp"
« Reply #6 on: June 10, 2013, 02:21:41 pm »
I'm not happy with this. This is not a fix for a problem in our code, but a fix for a broken compiler (or system headers).

Non-double-underscore, non-leading-underscore-capital-letter identifier in non-global namespace (and not-leading-underscore idendifier in any namespace) are not reserved and may be used. What we are doing is correct.

The system header that defines linux should instead define _Linux or __linux or __linux__. Of course, if it doesn't, that's bad luck for someone trying to build Code::Blocks, but still the "fix" is not addressing the problem.

Look at it this way, some disturbed person might add #define if else or #define protected private to their system headers -- does that mean we're not allowed to use the if keyword and can't have protected members in our code?

I knew that you won't like it. :)

However I decided to patch our code (or a hack in your words) as some users were facing build issue. As this is a known problem we better accept it and make necessary changes in our code.


If you still dislike then you can apply the following patch which correctly fixes this issue.
Code
Index: src/sdk/compiletargetbase.cpp
===================================================================
--- src/sdk/compiletargetbase.cpp (revision 9146)
+++ src/sdk/compiletargetbase.cpp (working copy)
@@ -264,7 +264,7 @@
             {
                 wxString prefix = wxEmptyString;
                 // On linux, "lib" is the common prefix for this platform
-                if (platform::Linux)
+                if (platform::linux)
                     prefix = wxT("lib");
                 // FIXME (mortenmacfly#5#): What about Mac (Windows is OK)?!
 
Index: src/sdk/compileoptionsbase.cpp
===================================================================
--- src/sdk/compileoptionsbase.cpp (revision 9146)
+++ src/sdk/compileoptionsbase.cpp (working copy)
@@ -64,7 +64,7 @@
 {
     if(platform::windows)
         return m_Platform & spWindows;
-    if(platform::Unix)
+    if(platform::unix)
         return m_Platform & spUnix;
     if(platform::macosx)
         return m_Platform & spMac;
Index: src/sdk/configmanager.cpp
===================================================================
--- src/sdk/configmanager.cpp (revision 9146)
+++ src/sdk/configmanager.cpp (working copy)
@@ -262,11 +262,11 @@
 
     if (platform::windows)
         info.append(_T("\n\t Windows "));
-    if (platform::Linux)
+    if (platform::linux)
         info.append(_T("\n\t Linux "));
     if (platform::macosx)
         info.append(_T("\n\t Mac OS X "));
-    if (platform::Unix)
+    if (platform::unix)
         info.append(_T("\n\t Unix "));
 
     info.append(platform::unicode ? _T("Unicode ") : _T("ANSI "));
Index: src/sdk/compiler.cpp
===================================================================
--- src/sdk/compiler.cpp (revision 9146)
+++ src/sdk/compiler.cpp (working copy)
@@ -1144,7 +1144,7 @@
         else if (test == wxT("macosx"))
             val = platform::macosx;
         else if (test == wxT("linux"))
-            val = platform::Linux;
+            val = platform::linux;
         else if (test == wxT("freebsd"))
             val = platform::freebsd;
         else if (test == wxT("netbsd"))
@@ -1156,7 +1156,7 @@
         else if (test == wxT("solaris"))
             val = platform::solaris;
         else if (test == wxT("unix"))
-            val = platform::Unix;
+            val = platform::unix;
     }
     else if (node->GetAttribute(wxT("exec"), &test))
     {
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (revision 9146)
+++ src/sdk/editormanager.cpp (working copy)
@@ -3219,7 +3219,7 @@
             defines.Add(wxT("__WXOSX_MAC__"));
             defines.Add(wxT("__APPLE__"));
         }
-        else if (platform::Linux)
+        else if (platform::linux)
         {
             defines.Add(wxT("LINUX"));
             defines.Add(wxT("linux"));
@@ -3254,7 +3254,7 @@
             defines.Add(wxT("__SUNOS__"));
             defines.Add(wxT("__SOLARIS__"));
         }
-        if (platform::Unix)
+        if (platform::unix)
         {
             defines.Add(wxT("unix"));
             defines.Add(wxT("__unix"));
Index: src/plugins/projectsimporter/msvc10loader.cpp
===================================================================
--- src/plugins/projectsimporter/msvc10loader.cpp (revision 9146)
+++ src/plugins/projectsimporter/msvc10loader.cpp (working copy)
@@ -50,7 +50,7 @@
     //ctor
     if (platform::windows)
         m_PlatformName = _T("Win32");
-    else if (platform::Linux)
+    else if (platform::linux)
         m_PlatformName = _T("Linux");
     else if (platform::macosx)
         m_PlatformName = _T("MacOSX");
Index: src/plugins/compilergcc/compilergcc.cpp
===================================================================
--- src/plugins/compilergcc/compilergcc.cpp (revision 9146)
+++ src/plugins/compilergcc/compilergcc.cpp (working copy)
@@ -919,7 +919,7 @@
                 else if (test == wxT("macosx"))
                     val = platform::macosx;
                 else if (test == wxT("linux"))
-                    val = platform::Linux;
+                    val = platform::linux;
                 else if (test == wxT("freebsd"))
                     val = platform::freebsd;
                 else if (test == wxT("netbsd"))
@@ -931,7 +931,7 @@
                 else if (test == wxT("solaris"))
                     val = platform::solaris;
                 else if (test == wxT("unix"))
-                    val = platform::Unix;
+                    val = platform::unix;
             }
             if (val)
                 CompilerFactory::RegisterCompiler(
Index: src/plugins/contrib/lib_finder/processingdlg.cpp
===================================================================
--- src/plugins/contrib/lib_finder/processingdlg.cpp (revision 9146)
+++ src/plugins/contrib/lib_finder/processingdlg.cpp (working copy)
@@ -423,7 +423,7 @@
                     }
                 }
 
-                if ( platform::Linux )
+                if ( platform::linux )
                 {
                     if ( Platform==_T("lin") || Platform==_T("linux") )
                     {
@@ -477,7 +477,7 @@
                     }
                 }
 
-                if ( platform::Unix )
+                if ( platform::unix )
                 {
                     if ( Platform==_T("unix") || Platform==_T("un*x") )
                     {
Index: src/include/prep.h
===================================================================
--- src/include/prep.h (revision 9146)
+++ src/include/prep.h (working copy)
@@ -135,9 +135,9 @@
     platform::id
         Value of type platform::identifier describing the target platform
 
-    platform::windows, platform::macosx, platform::Linux
+    platform::windows, platform::macosx, platform::linux
     platform::freebsd, platform::netbsd, platform::openbsd
-    platform::darwin,  platform::solaris, platform::Unix
+    platform::darwin,  platform::solaris, platform::unix
         Boolean value that evaluates to true if the target platform is the same as the variable's name, false otherwise.
         Using the platform booleans is equivalent to using platform::id, but results in nicer code.
 
@@ -218,13 +218,13 @@
 
     const bool windows = (id == platform_windows);
     const bool macosx  = (id == platform_macosx);
-    const bool Linux   = (id == platform_linux);
+    const bool linux   = (id == platform_linux);
     const bool freebsd = (id == platform_freebsd);
     const bool netbsd  = (id == platform_netbsd);
     const bool openbsd = (id == platform_openbsd);
     const bool darwin  = (id == platform_darwin);
     const bool solaris = (id == platform_solaris);
-    const bool Unix    = (Linux | freebsd | netbsd | openbsd | darwin | solaris);
+    const bool unix    = (linux | freebsd | netbsd | openbsd | darwin | solaris);
 
     const int bits = 8*sizeof(void*);
 
Index: configure.in
===================================================================
--- configure.in (revision 9146)
+++ configure.in (working copy)
@@ -279,7 +279,7 @@
 esac
 AC_MSG_RESULT($PIC_FLAGS)
 
-CPPFLAGS="$CPPFLAGS -DTIXML_USE_STL"
+CPPFLAGS="$CPPFLAGS -ansi -DTIXML_USE_STL"
 CXXFLAGS="$CXXFLAGS $PCH_FLAGS $PIC_FLAGS -fexceptions"
 AC_SUBST(codeblocks_PCH_FLAGS, "$PCH_FLAGS")
 

This patch instructs gcc to undef all non-standard pre-processor macros.

Unfortunately we still have code, in our trunk, which relies on some non-standard macros. As a result this patch doesn't compile (build stops at depslib) at the moment. I'll explore it further when I have time.
Be a part of the solution, not a part of the problem.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: compilation of c::b fails in "compiler.cpp"
« Reply #7 on: June 11, 2013, 07:40:18 am »
This patch instructs gcc to undef all non-standard pre-processor macros.
Now that i am guided here, sorry for my ignorance in the other thread...

In fact I tend to agree with Thomas as it was a rather misleading and unexpected change for me in the first place.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: compilation of c::b fails in "compiler.cpp"
« Reply #8 on: June 11, 2013, 08:23:32 am »
This patch instructs gcc to undef all non-standard pre-processor macros.
Now that i am guided here, sorry for my ignorance in the other thread...

In fact I tend to agree with Thomas as it was a rather misleading and unexpected change for me in the first place.

Would you care to explain why is it a "misleading" change?
Be a part of the solution, not a part of the problem.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: compilation of c::b fails in "compiler.cpp"
« Reply #9 on: June 11, 2013, 09:22:10 pm »
Would you care to explain why is it a "misleading" change?
...I did, but in the other thread before I found this one... :-[
http://forums.codeblocks.org/index.php/topic,18008.msg123115.html#msg123115
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: compilation of c::b fails in "compiler.cpp"
« Reply #10 on: June 12, 2013, 04:14:57 pm »
Would you care to explain why is it a "misleading" change?
...I did, but in the other thread before I found this one... :-[
http://forums.codeblocks.org/index.php/topic,18008.msg123115.html#msg123115

Ah! I read that post.

Unfortunately we still have code, in our trunk, which relies on some non-standard macros. As a result this patch doesn't compile (build stops at depslib) at the moment. I'll explore it further when I have time.
Well it turned out to be presence of C++ comments in C file which caused that build failure. I have already fixed it in trunk. Currently I'm running a full build. If there are no further issues then above patch will go to trunk. :)
Be a part of the solution, not a part of the problem.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: compilation of c::b fails in "compiler.cpp"
« Reply #11 on: June 12, 2013, 04:41:49 pm »
Well it turned out to be presence of C++ comments in C file which caused that build failure. I have already fixed it in trunk. Currently I'm running a full build. If there are no further issues then above patch will go to trunk. :)

Build completed without any error. Patch is now in trunk.
Be a part of the solution, not a part of the problem.