在 Ubuntu 12.04 上运行,一个在 Windows 上的 MS Visual Studio 中用 c++11

Running on Ubuntu 12.04 a project written in c++11 in MS Visual Studio on Windows

本文关键字:上的 Windows 一个 MS Visual c++11 中用 Studio Ubuntu 运行      更新时间:2023-10-16

我在Windows上的MS Visual Studio 2015中编写了一个项目(由几个cpp和h文件组成(,但我需要在Ubuntu上运行它。有什么办法可以做到这一点吗?我通过简单的智慧尝试 $ g++ -std=c++0x *.cpp但我得到很多错误:

    In file included from DataTable.cpp:1:0:
DataTable.h:9:14: sorry, unimplemented: non-static data member initializers
DataTable.h:9:14: error: in-class initialization of static data member ‘data’ of non-literal type
DataTable.cpp: In member function ‘void DataTable::printTable(std::ostream&)’:
DataTable.cpp:12:22: error: ‘data’ was not declared in this scope
DataTable.cpp: In member function ‘void DataTable::addData(std::string)’:
DataTable.cpp:22:8: error: ‘class DataTable’ has no member named ‘data’
In file included from ElfSymbol.h:7:0,
                 from ElfSymbol.cpp:1:
DataTable.h:9:14: sorry, unimplemented: non-static data member initializers
DataTable.h:9:14: error: in-class initialization of static data member ‘data’ of non-literal type
In file included from ElfSymbol.h:7:0,
                 from SymbolTable.h:6,
                 from LineParser.h:11,
                 from Instruction.h:5,
                 from Instruction.cpp:1:
DataTable.h:9:14: sorry, unimplemented: non-static data member initializers
DataTable.h:9:14: error: in-class initialization of static data member ‘data’ of non-literal type
In file included from Instruction.h:5:0,
                 from Instruction.cpp:1:
LineParser.h:27:7: error: use of enum ‘instructionStrings’ without previous declaration
LineParser.h:31:21: error: ‘instructionStrings’ was not declared in this scope
LineParser.h:31:39: error: template argument 2 is invalid
LineParser.h:31:39: error: template argument 4 is invalid
In file included from Instruction.cpp:1:0:
Instruction.h:18:14: sorry, unimplemented: non-static data member initializers
Instruction.h:18:14: error: in-class initialization of static data member ‘addr’ of non-literal type
Instruction.cpp: In member function ‘void Instruction::setAddr(std::string)’:
Instruction.cpp:59:2: error: ‘addr’ was not declared in this scope
Instruction.cpp: In member function ‘std::string Instruction::getAddr()’:
Instruction.cpp:64:9: error: ‘addr’ was not declared in this scope
Instruction.cpp: In member function ‘std::string Instruction::getDataString()’:
Instruction.cpp:130:15: error: ‘addr’ was not declared in this scope
Instruction.cpp:141:15: error: ‘addr’ was not declared in this scope
In file included from ElfSymbol.h:7:0,
                 from SymbolTable.h:6,
                 from LineParser.h:11,
                 from LineParser.cpp:1:
DataTable.h:9:14: sorry, unimplemented: non-static data member initializers
DataTable.h:9:14: error: in-class initialization of static data member ‘data’ of non-literal type
In file included from LineParser.h:12:0,
                 from LineParser.cpp:1:
Instruction.h:18:14: sorry, unimplemented: non-static data member initializers
Instruction.h:18:14: error: in-class initialization of static data member ‘addr’ of non-literal type
In file included from LineParser.cpp:1:0:
LineParser.h:27:7: error: use of enum ‘instructionStrings’ without previous declaration
LineParser.h:31:21: error: ‘instructionStrings’ was not declared in this scope
LineParser.h:31:39: error: template argument 2 is invalid
LineParser.h:31:39: error: template argument 4 is invalid
LineParser.cpp:7:13: error: ‘instructionStrings’ is not a member of ‘LineParser’
LineParser.cpp:7:13: error: ‘instructionStrings’ is not a member of ‘LineParser’
LineParser.cpp:7:43: error: template argument 2 is invalid
LineParser.cpp:7:43: error: template argument 4 is invalid
LineParser.cpp:7:71: error: invalid type in declaration before ‘;’ token
LineParser.cpp: In static member function ‘static bool LineParser::isInstruction(std::string, SymbolTable)’:
LineParser.cpp:412:14: error: ‘instructionStrings’ was not declared in this scope
LineParser.cpp:412:32: error: template argument 2 is invalid
LineParser.cpp:412:32: error: template argument 4 is invalid
LineParser.cpp:412:44: error: expected initializer before ‘it’
LineParser.cpp:413:6: error: ‘it’ was not declared in this scope
LineParser.cpp:413:27: error: request for member ‘end’ in ‘LineParser::instructionMap’, which is of non-class type ‘int’
LineParser.cpp: In static member function ‘static void LineParser::initializeInsMap()’:
LineParser.cpp:1622:26: error: ‘INT’ was not declared in this scope
LineParser.cpp:1623:26: error: ‘JMP’ was not declared in this scope
LineParser.cpp:1624:27: error: ‘CALL’ was not declared in this scope
LineParser.cpp:1625:26: error: ‘RET’ was not declared in this scope
LineParser.cpp:1626:25: error: ‘JZ’ was not declared in this scope
LineParser.cpp:1627:26: error: ‘JNZ’ was not declared in this scope
LineParser.cpp:1628:26: error: ‘JGZ’ was not declared in this scope
LineParser.cpp:1629:27: error: ‘JGEZ’ was not declared in this scope
LineParser.cpp:1630:26: error: ‘JLZ’ was not declared in this scope
LineParser.cpp:1631:27: error: ‘JLEZ’ was not declared in this scope
LineParser.cpp:1633:27: error: ‘LOAD’ was not declared in this scope
LineParser.cpp:1634:29: error: ‘LOADUB’ was not declared in this scope
LineParser.cpp:1635:29: error: ‘LOADSB’ was not declared in this scope
LineParser.cpp:1636:29: error: ‘LOADUW’ was not declared in this scope
LineParser.cpp:1637:29: error: ‘LOADSW’ was not declared in this scope
LineParser.cpp:1639:28: error: ‘STORE’ was not declared in this scope
LineParser.cpp:1640:29: error: ‘STOREB’ was not declared in this scope
LineParser.cpp:1641:29: error: ‘STOREW’ was not declared in this scope
LineParser.cpp:1643:27: error: ‘PUSH’ was not declared in this scope
LineParser.cpp:1644:26: error: ‘POP’ was not declared in this scope
LineParser.cpp:1646:26: error: ‘ADD’ was not declared in this scope
LineParser.cpp:1647:26: error: ‘SUB’ was not declared in this scope
LineParser.cpp:1648:26: error: ‘MUL’ was not declared in this scope
LineParser.cpp:1649:26: error: ‘DIV’ was not declared in this scope
LineParser.cpp:1650:26: error: ‘MOD’ was not declared in this scope
LineParser.cpp:1651:26: error: ‘AND’ was not declared in this scope
LineParser.cpp:1652:25: error: ‘OR’ was not declared in this scope
LineParser.cpp:1653:26: error: ‘XOR’ was not declared in this scope
LineParser.cpp:1654:26: error: ‘NOT’ was not declared in this scope
LineParser.cpp:1655:26: error: ‘ASL’ was not declared in this scope
LineParser.cpp:1656:26: error: ‘ASR’ was not declared in this scope
In file included from ElfSymbol.h:7:0,
                 from SymbolTable.h:6,
                 from main.cpp:9:
DataTable.h:9:14: sorry, unimplemented: non-static data member initializers
DataTable.h:9:14: error: in-class initialization of static data member ‘data’ of non-literal type
In file included from LineParser.h:12:0,
                 from SymbolTable.h:7,
                 from main.cpp:9:
Instruction.h:18:14: sorry, unimplemented: non-static data member initializers
Instruction.h:18:14: error: in-class initialization of static data member ‘addr’ of non-literal type
In file included from SymbolTable.h:7:0,
                 from main.cpp:9:
LineParser.h:27:7: error: use of enum ‘instructionStrings’ without previous declaration
LineParser.h:31:21: error: ‘instructionStrings’ was not declared in this scope
LineParser.h:31:39: error: template argument 2 is invalid
LineParser.h:31:39: error: template argument 4 is invalid
In file included from ElfSymbol.h:7:0,
                 from SymbolTable.h:6,
                 from SymbolTable.cpp:1:
DataTable.h:9:14: sorry, unimplemented: non-static data member initializers
DataTable.h:9:14: error: in-class initialization of static data member ‘data’ of non-literal type
In file included from LineParser.h:12:0,
                 from SymbolTable.h:7,
                 from SymbolTable.cpp:1:
Instruction.h:18:14: sorry, unimplemented: non-static data member initializers
Instruction.h:18:14: error: in-class initialization of static data member ‘addr’ of non-literal type
In file included from SymbolTable.h:7:0,
                 from SymbolTable.cpp:1:
LineParser.h:27:7: error: use of enum ‘instructionStrings’ without previous declaration
LineParser.h:31:21: error: ‘instructionStrings’ was not declared in this scope
LineParser.h:31:39: error: template argument 2 is invalid
LineParser.h:31:39: error: template argument 4 is invalid

但是这一切都在VS上没有出错。

Ubuntu 12.04 附带 GCC 4.6.3。 这个非常旧的版本没有实现某些 C++11 功能。 您可以在 GCC 4.6 中了解 C++0x 支持中可用的功能。 从这个列表中可以看到,»非静态数据成员初始值设定项«根本没有实现,这正是编译器告诉您的。

最好使用更新的编译器(GCC ≥ 4.8.1(,或者更好的是,更新您的操作系统! 否则,此问题应迁移到 https://retrocomputing.stackexchange.com/