对WinMain@16 - 代码块的未定义引用
Undefined reference to WinMain@16 - Codeblocks
我已经阅读了:对"WinMain@16"的未定义引用,但仍然不明白我的问题。
我有一个正在运行的程序。添加了一个类,但尚未将其实现到程序中,而只是编写了标头和.cpp文件。之前只添加此类的程序有效,现在不起作用。
错误状态... **文件地址....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;
}
我调用它的主要内容,只是因为我不确定错误是否是因为没有调用它或类似的东西是:
#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;
}
与注册相关的重载>>运算符中未设置日期。它由基本构造函数设置。
同样,我没有将这个类添加到程序中,因为它只是在以基本测试方式编写和添加后尝试编译。通过主测试。
提前谢谢。 =D
问题是您的新项目已被创建为Win32 GUI project
,而它应该被创建为Console application
。前者要求存在具有签名int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
的函数,而后者要求C或C++项目采用的常用形式之一,即int main()
或int main(char *argv[], int argc)
。
创建控制台类型的新项目并将代码复制到其中,或者使用"粘带"解决方案,并将int main()
更改为int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
您还需要导航到项目的属性并将"生成目标"从"GUI application
"更改为"Console application
- 否则将意味着您将看不到任何输出, 由于您使用的是 cout,它打印到 stdout
,由控制台显示。此窗口始终可用于控制台应用程序,但仅适用于 GUI 应用程序的调试版本。
我建议正确地执行此操作并创建一个适当类型的新项目,即 Console application
. :)
项目设置下的应用程序类型更改为控制台。WinMain16与Windows图形应用程序有关。我相信如果您将其保留为 Windows 图形应用程序,您确实需要设置一个特殊的预处理器标志或包含某种库以使其正常工作,但在这种情况下,最简单的解决方法是获取控制台应用程序。
另外,也许添加 -mwindows 标志可以帮助您。
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用