在我的C ++程序中构建错误

时间:2012-07-31 15:57:10

标签: c++ netbeans build

这是我的第三个C ++应用程序,所以我是初学者。请查看以下代码

Main.cpp的

#include<iostream>
#include <string>
#include "GradeBook.h"

using namespace std;

int main()
{
    GradeBook myGradeBook1("Java");
    GradeBook myGradeBook2("C++");

    cout << "Course Name is: " << myGradeBook1.getCourseName() << endl;
    cout << "Course Name2 is: " << myGradeBook2.getCourseName() << endl;
}

GradeBook.h

#include <iostream>
#include <string>

using namespace std;

class GradeBook
{
private:
    string courseName;

public:

    GradeBook(string name)
    {
        setCourseName(name);
    }

    void setCourseName(string name)
    {
        courseName = name;
    }

    string getCourseName()
    {
        return courseName;
    }

    void displayMessage()
    {
        cout << "Welcome to " << getCourseName() << endl;
    }
};

现在,当我运行程序时(我使用netbeans,编译器是cygwin),它会出现以下错误:

> "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS=
> .build-conf make[1]: Entering directory
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> "/usr/bin/make"  -f nbproject/Makefile-Debug.mk
> dist/Debug/Cygwin-Windows/learncplusplus.exe make[2]: Entering
> directory
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> mkdir -p build/Debug/Cygwin-Windows rm -f
> build/Debug/Cygwin-Windows/ClassWithPara.o.d g++    -c -g -MMD -MP -MF
> build/Debug/Cygwin-Windows/ClassWithPara.o.d -o
> build/Debug/Cygwin-Windows/ClassWithPara.o ClassWithPara.cpp
> ClassWithPara.cpp:28:4: warning: no newline at end of file mkdir -p
> dist/Debug/Cygwin-Windows g++     -o
> dist/Debug/Cygwin-Windows/learncplusplus
> build/Debug/Cygwin-Windows/IfStatement.o 
> build/Debug/Cygwin-Windows/ClassWithConstructors.o 
> build/Debug/Cygwin-Windows/HelloWorld.o 
> build/Debug/Cygwin-Windows/ClassWithSetters.o 
> build/Debug/Cygwin-Windows/ClassWithPara.o 
> build/Debug/Cygwin-Windows/FirstClass.o 
> build/Debug/Cygwin-Windows/AddIntegers.o  
> nbproject/Makefile-Debug.mk:68: recipe for target
> `dist/Debug/Cygwin-Windows/learncplusplus.exe' failed make[2]: Leaving
> directory
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> nbproject/Makefile-Debug.mk:65: recipe for target `.build-conf' failed
> make[1]: Leaving directory
> `/cygdrive/c/Users/Yohan/Documents/NetBeansProjects/LearnCPlusPlus'
> nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
> /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o): In
> function `main':
> /usr/src/debug/cygwin-1.7.16-1/winsup/cygwin/lib/libcmain.c:39:
> undefined reference to `_WinMain@16' collect2: ld returned 1 exit
> status make[2]: *** [dist/Debug/Cygwin-Windows/learncplusplus.exe]
> Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl]
> Error 2
> 
> 
> BUILD FAILED (exit value 2, total time: 11s)

1 个答案:

答案 0 :(得分:1)

那里唯一的具体信息是

ClassWithPara.cpp:28:4: warning: no newline at end of file mkdir -p

您是否尝试在该文件的末尾添加换行符?

(从技术上来说,它是必需的,虽然并不总是强制执行。)从输出中你不清楚这是否真的只是一个警告或是否被视为错误。