对WinMain @ 16(codeblocks)的未定义引用

Jef*_*jit 10 c++ windows codeblocks

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

secrypt.h:

#ifndef SECRYPT_H
#define SECRYPT_H

void jRegister();

#endif
Run Code Online (Sandbox Code Playgroud)

secrypt.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";

}
Run Code Online (Sandbox Code Playgroud)

trial.cpp

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

using namespace std;

int main()
{
    void jRegister();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是我的错误的图像: errorimage

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

chr*_*ris 10

当没有项目时,Code :: Blocks只编译并链接当前文件.你的照片中的那个文件是secrypt.cpp,没有主要功能.为了编译和链接两个源文件,您需要手动完成或将它们添加到同一个项目中.

与其他人所说的相反,使用Windows子系统main仍然有效,但是没有控制台窗口.

您的其他尝试,仅编译和链接trial.cpp,从不链接secrypt.cpp.这通常会导致未定义的引用jRegister(),但是您已经在内部声明了函数main而不是调用它.更改main到:

int main()
{
    jRegister();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)