C 类文件未在Linux OS上运行的Eclipse Mars中构建二进制文件
C++ Class Files Not building Binaries in Eclipse Mars Running on Linux OS
在执行我的代码时,C 的新功能并获得可怕的"找不到"错误。仅当我创建一个包含类代码的源文件时,才会发生这种情况。当我编写不包括课程的程序时,这不会发生。例如,此程序在为其构建项目并运行良好时会创建二进制文件:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!";
}
但是,当我尝试为此文件构建一个项目时,二进制文件不会创建:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <algorithm> // std::max
using namespace std;
class Measure {
public:
int key;
string note;
Measure() {
key = 13;
//Generate a random key
while(key > 12)
{
key = (rand() % 100) + 1;
}
note = startNote(key);
}
int getKey() {
return key;
}
string getNote() {
return note;
}
int triad(){
int first = 0;
int third = 0;
int fifth = 0;
while(first == third && first == fifth )
{
first = (rand() % 100) + 1;
third = (rand() % 100) + 1;
fifth = (rand() % 100) + 1;
}
if (first > third && first > fifth)
return 0;
else if(third > first && third > fifth)
return 1;
else
return 2;
}
string startNote(int key){
switch(key + triad())
{
case 1 :
note = "A";
break;
case 2 :
note = "A#";
break;
case 3 :
note = "B";
break;
case 4 :
note = "C";
break;
case 5 :
note = "C#";
break;
case 6 :
note = "D";
break;
case 7 :
note = "D#";
break;
case 8 :
note = "E";
break;
case 9 :
note = "F";
break;
case 10 :
note = "F#";
break;
case 11 :
note = "G";
break;
case 12 :
note = "G#";
break;
}
return note;
}
~Measure() {
// TODO Auto-generated destructor stub
}
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
};
我查找了类似于我的问题,解决方案不起作用。我尝试在项目属性菜单中将二进制解析器更改为PE Windows Parser,Elf Parser和GNU Elf Parser。这似乎没有区别。为什么Eclipse在为某些文件而不是其他文件构建项目时会生成二进制文件(例如,上面的文件包含一个称为MAUSE的类?)
您的主要功能在类定义内。您需要移动};在您的主要功能上方。我不知道Eclipse,但它可能在这里没有看到主函数,只有一个名为main()的类方法,它不是C 中的东西。
顺便说一句,您的Startnote方法似乎有一个错误。看起来Key Triad()可以给出您的Switch语句不涵盖的值。那么在这种情况下如何构建您的对象?
相关文章:
- 无法在Ubuntu上将共享库与Eclipse链接
- Eclipse CDT:单个项目中有多个C++文件
- C++ 运行时链接器错误 (liblog4cpp.so.5) Eclipse
- Eclipse/Netbeans 中的处理模式行
- 如何在使用 SDL2 的 Eclipse 中构建 c++ 程序
- 使用 Eclipse CDT 进行 Cplex 配置
- Eclipse 没有在 Windows (C++) 中编译.exe
- 在 Eclipse 上启用 C++17 以使用 'std::byte'
- C 类文件未在Linux OS上运行的Eclipse Mars中构建二进制文件
- Eclipse Mars IDE 中C++的未解析标识符
- 在Eclipse IDE中为OS X中的C/C++开发人员Mars设置gcc(嵌入gcc-arm)
- Eclipse Mars - 为C++项目设置默认设置(默认情况下设置 c++11)
- 包含在Eclipse Mars C++中
- 链接Eclipse Mars中的GLFW
- 如何在Eclipse Mars.2 Mac上安装wxwidgets
- C++ Eclipse Mars+MinGW 中的调试器"gdb.exe --version"错误
- 尝试调试c++程序在Eclipse Mars上的MAC Pro视网膜与OS X Yosemite版本10.10.5
- Eclipse Mars c++缓慢构建
- C++错误类型"std::thread"无法解析 Eclipse Mars 4.5 , Ubuntu 12.04
- 无法编译C++OpenCV2.4.9、Win7x64、Eclipse Mars、MinGW