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

标签 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;
}

成绩簿.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)

最佳答案

那里唯一的具体信息是

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

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

(从技术上讲这是必需的,尽管并不总是强制执行。)从您提供的输出中不清楚这是否真的只是警告,或者是否被视为错误。

关于c++ - 在我的 C++ 程序中构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11744205/

相关文章:

c++ - std::string::empty() const () 不抛出段错误

java - java非法转义字符

java - 更改 NetBeans 默认 JFrame 主函数有什么区别吗?

ios - 我在哪里更改 xcode 中的版本号

c++ - 有关我的程序正在使用的虚拟内存的信息?

c++ - 遍历导致问题的类 vector

c++ - 如何增加 vector 中数字序列的长度

java - Java 中的 OpenCV 用于图像过滤

Jenkins 构建无法启动 cucumber 测试并超时

xcode - OSX 菜单栏应用程序在存档和导出时未启动,如何调试?