对WinMain @ 16的未定义引用-代码块 [英] Undefined reference to WinMain@16 - Codeblocks

查看:163
本文介绍了对WinMain @ 16的未定义引用-代码块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读:对 WinMain @ 16的未定义引用&仍然不理解我的问题。

I have read: undefined reference to `WinMain@16' & still don't understand my problem.

我有一个正在运行的程序。添加了一个类,但尚未将其实现到程序中,只是编写了标头和.cpp文件。

I had a program that was working. Added a class but had not implemented it into the program yet just wrote the header and .cpp file. The program previous to just adding this class worked and now it doesn't.

错误状态... **文件地址.... libmingw.32.a( main.o):main.c :(。text.startup + 0xa7)

Error states... **file address....libmingw.32.a(main.o):main.c:(.text.startup+0xa7)

头文件

        #ifndef DATE_H
        #define DATE_H

        #include <iostream>
        #include <string>

        class Date
        {
            public:
                Date();

                //Setters
                void SetDay(unsigned dy);

                void SetMonth(std::string month);

                void SetYear(unsigned mnth);

                //Getters
                unsigned GetDay() const;

                std::string GetMonth() const;

                unsigned GetYear() const;

            private:
                unsigned day, year;
                std::string month;
        };

        #endif // DATE_H

.cpp文件

        #include "Date.h"

        Date::Date()
        {
            day = 0;
            year = 0;
            month = "Not Set";
        }

        //Setters
        void Date::SetDay(unsigned dy)
        {
            day = dy;
        }

        void Date::SetMonth(std::string mnth)
        {
            month = mnth;
        }

        void Date::SetYear(unsigned yr)
        {
            year = yr;
        }

        //Getters
        unsigned Date::GetDay() const
        {
            return day;
        }

        unsigned Date::GetYear() const
        {
            return year;
        }

        std::string Date::GetMonth() const
        {
            return month;
        }

我称呼它的主管道,只是因为我不确定是否错误是因为没有被调用或类似的东西:

my main which I call it in, just because I wasn't sure if the error was because it wasn't being called or something like that is:

        #include <iostream>
        #include <fstream>
        #include "unit.h"  // Unit class declaration
        #include "regist.h"  // Registration class declaration
        #include "date.h"

        using namespace std;

        // Main program:
        // Open an input file stream, read a Registration object,
        // including its list of courses. Redisplay all information,
        // and calculate the total credits taken. Write the results
        // to a file stream.


        int main()
        {
            ifstream infile( "testin.txt" );
            if( !infile ) return -1;

            Registration R;
            Date D;
            infile >> R;

            ofstream ofile( "testout.txt" );

            ofile   << R;

            cout << "\nComputation completed. Check output file. \n";
            cout << "\n Day is " << D.GetDay;

            return 0;
        }

没有在与注册有关的重载>>运算符中设置日期。它由基本构造函数设置。

Day does not get set in the overloaded >> operator relating to Registration. It is set by the basic constructor.

同样,我没有将此类添加到程序中,因为我只是在编写并添加到基本测试中后才尝试编译方式。通过main进行测试。

Again I haven't added this class in to the program as it is going to be I'm just trying to compile after it was write and added in a basic testing manner. Testing through main.

预先感谢。 = D

推荐答案

问题是您的新项目已创建为 Win32 GUI项目,应将其创建为控制台应用程序。前者要求具有签名 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)的函数,而后者则需要采用通常采用的一种形式用于C或C ++项目,即 int main() int main(char * argv [],int argc)

The problem is that your new project has been created as a Win32 GUI project, when it should have been created as a Console application. The former requires that a function with the signature int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) exists, while the latter requires one of the usual form taken for C or C++ projects, namely int main() or int main(char *argv[], int argc).

要么创建一个控制台类型的新项目并将代码复制到其中,要么使用粘胶带解决方案并更改 int main() int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)您还需要导航到项目的属性并将构建目标从 GUI应用程序更改为控制台应用程序-否则,您将看不到任何内容输出,因为您使用的是cout,它会打印到 stdout ,由控制台显示。此窗口始终可用于控制台应用程序,但仅可用于GUI应用程序的Debug版本。

Either create a new project of the console type and copy your code into it, or use the 'sticky-tape' solution, and change int main() to int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) You would also need to navigate to the project's properties and change the Build Target from GUI application to Console application - failing to do so would mean that you would not see any output, since you're using cout, which prints to stdout, which is shown by the console. This window is always available for a console application, but is only available for the Debug version of a GUI application.

我建议正确地进行操作并创建一个新的项目。适当的类型,即控制台应用程序。 :)

I reccomend doing it properly and creating a new project of the appropriate type, namely a Console application. :)

这篇关于对WinMain @ 16的未定义引用-代码块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆