代码在CLion中编译,但不在命令提示符中编译

问题描述 投票:0回答:1

我正在尝试使用C ++库,并且需要(想要)使用嵌套的名称空间,以提高代码的可读性。但是,尝试使用g++ main.c在Windows命令提示符下编译我的代码时遇到了问题。

下面的代码是我将拥有的一个示例-嵌套的名称空间,然后是一些函数或类:

namespace gpc::warning {
    void raiseError() {
        std::cout << "Error...\n";
        exit(1);
    }
}

下面的代码是我的main.c文件的示例:

#include <iostream>
#include "Warning/raise.hpp"

int main() {
    std::cout << "Hello, World!" << std::endl;
    gpc::warning::raiseError();

    return 0;
}

[当我在CLion中运行此简单程序时,它可以编译并完美运行,但是,当我在Windows 10命令提示符中运行代码时,出现以下错误,告诉我有关名称空间的一些信息:

In file included from main.cpp:2:0:
Warning/raise.hpp:10:14: error: expected '{' before '::' token
 namespace gpc::warning {
              ^
Warning/raise.hpp:10:16: error: 'warning' in namespace '::' does not name a type
 namespace gpc::warning {
                ^
main.cpp: In function 'int gpc::main()':
main.cpp:9:10: error: 'gpc::warning' has not been declared
     gpc::warning::raiseError();
          ^
main.cpp: At global scope:
main.cpp:12:1: error: expected '}' at end of input
 }
 ^

我想知道我做错了什么以及如何解决此问题。

谢谢!

我正在尝试使用C ++库,并且需要(想要)使用嵌套的名称空间,以提高代码的可读性。但是,尝试在Windows中编译我的代码时遇到问题...

c++ gcc namespaces command-prompt clion
1个回答
1
投票

尝试将您的g++版本更新为6.1.0或更高版本。

© www.soinside.com 2019 - 2024. All rights reserved.