c++ - 对 WinMain@16 的 undefined reference (代码块)

标签 c++ windows codeblocks

当我编译我的 secrypt.cpp 程序时,我的编译器显示错误“undefined reference to WinMain@16”。 我的代码如下

密码.h :

#ifndef SECRYPT_H
#define SECRYPT_H

void jRegister();

#endif

密码.cpp :

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include "secrypt.h"

using namespace std;

void jRegister()
{
    ofstream outRegister( "useraccount.dat", ios::out );
    if ( !outRegister    ) {
    cerr << "File could not be opened" << endl;
    exit( 1 );}
    string a,b,c,d;
    cout<<"enter your username :";
    cin>>a;
    cout<<"enter your password :";
    cin>>b;
    outRegister<<a<<' '<<b<<endl;
    cout<<"your account has been created";

}

试用.cpp

#include<iostream>
#include "secrypt.h"

using namespace std;

int main()
{
    void jRegister();

    return 0;
}

这是我的错误图片: errorimage

当我编译 trial.cpp 程序时,它会编译并打开控制台,但不会调用函数。这是 trial.cpp 程序的控制台屏幕图像。 o/p screen 谁能帮我解决这个问题?

最佳答案

当没有项目时,Code::Blocks 只编译和链接当前文件。从你的图片来看,该文件是 secrypt.cpp,它没有主要功能。为了编译和链接这两个源文件,您需要手动执行或将它们添加到同一个项目中。

与其他人所说的相反,使用带 main 的 Windows 子系统仍然有效,但不会有控制台窗口。

您的其他尝试,仅编译和链接 trial.cpp,从不链接 secrypt.cpp。这通常会导致对 jRegister() 的 undefined reference ,但您已经在 main 中声明了该函数,而不是调用它。将 main 更改为:

int main()
{
    jRegister();

    return 0;
}

关于c++ - 对 WinMain@16 的 undefined reference (代码块),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20020399/

相关文章:

c++ - 结合批处理和 C++

c++ - 共享库有一些问题

c++ - vfork导致内存 "free()"崩溃,但是fork却没有,这是怎么回事?

来自 CMD 输出的列表的 Python 列表

c# - 接收打印作业并将其转发到 LAN 中的打印机的软件

c++ - Windows 与 Linux GCC argv[0] 值

windows - native x64 dll 不工作

c - 将 JSON 库与我的 AVR 微 Controller 代码集成时遇到困难

c++ - winapifamily.h : No such file or directory

CodeChef - 运行时错误(SIGSEGV)