编译现有代码库时编译错误

时间:2010-06-12 12:44:45

标签: c++ gcc g++

在使用本机构建设置在Mac OS上构建现有代码库时,我在编译阶段遇到了一些基本的奇怪错误。

你们有没有任何想法,正如我所看到的那样,在这个论坛上也没有任何充分的理由进行过讨论。我看不到包含任何冲突的文件。 但是我仍然无法编译代码,因为出现了这个错误。

Source就像下面给出的代码一样,出现编译错误

$ cat a.h
    #include <string>
    #include <sstream>

    namespace brijesh {
        typedef std::string String;

        template<class T>
        String toString(T value) {
            std::ostringstream buffer;
            buffer << value;
            return buffer.str();
    }

$ cat b.h
    #include "a.h"
    namespace brijesh {
        class Platform {
            public:
                static String getName();
        };
     }

$ cat b.cpp
     #include "b.h"

     namespace brijesh {

         String Platform::getName()
         {
             String  name = "UNKNOWN";
     #ifdef  LINUX
              name = "linux";
     #endif
     #ifdef  MACOSX
              name = "Mac";
     #endif
              return name;
         }
     }
用于编译的

标志

 g++ -c -o test.o -DRELEASE_VERSION -ggdb -arch ppc -mmacosx-version-min=10.4 -pipe -fpermiss    ive -nostdinc -nostdinc++ -isystem /Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3    .3 -I/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++ -I/Developer/SDKs/MacOS    X10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/ppc-darwin -isystem /Developer/SDKs/MacOSX10.3.9.    sdk/usr/include -F/Developer/SDKs/MacOSX10.3.9.sdk/System/Library/Frameworks -Wreturn-type -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -Wall -Wno-multichar -Wno-unk    nown-pragmas  -Wno-long-double -fconstant-cfstrings  -MP -MMD x.cpp


/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/bits/locale_facets.h: In constructor 'std::collate_byname<_CharT>::collate_byname(const char*, size_t)':
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/bits/locale_facets.h:1072: error: '_M_c_locale_collate' was not declared in this scope
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/ppc-darwin/bits/messages_members.h: In constructor 'std::messages_byname<_CharT>::messages_byname(const char*, size_t)':
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/ppc-darwin/bits/messages_members.h:79: error: '_M_c_locale_messages' was not declared in this scope
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits: At global scope:
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: 'float __builtin_huge_valf()' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: 'float __builtin_huge_valf()' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: 'float __builtin_nanf(const char*)' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: 'float __builtin_nanf(const char*)' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:900: error: field initializer is not constant
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:915: error: field initializer is not constant

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试使用OS X 10.3开发人员工具(Xcode ),并且正在尝试定位OS X 10.4,这显然不会起作用。更改构建命令以删除不兼容的标志,例如-mmacosx-version-min=10.4,或升级到更新版本的OS X + Xcode + SDK。