gpt4 book ai didi

C++ 错误 LNK2001 : unresolved external symbol function _main

转载 作者:可可西里 更新时间:2023-11-01 18:06:50 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

我正在学习 C++,但在我的项目中遇到编译问题。我已经阅读了大量标题上有此错误的帖子,但我找不到问题出在哪里。

我的 Main 函数中有一个方法调用是导致错误的原因。每当我评论该项目编译完美的行。

代码如下:

main.cpp

#pragma once 
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <WinSock.h>
#include <Windows.h>
#include <string.h>
#include "NetUtils.h"
#include "Utils.h"
#include "FileUtils.h"
#include "SendMail.h"
using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{

SendMail *mail = new SendMail("somemail@mail.com","Envio de C++","Cuerpo del mail");
char* msg="";
mail->SendNow();
...

这个方法mail->SendNow是我评论解决问题的方法,所以我猜我在 SendMail.cpp 或 SendMail.h 中有某种标题声明问题

现在剩下的类和标题:

发送邮件.h

#pragma once
#ifndef SENDMAIL_H
#define SENDMAIL_H


class SendMail

{
public:
SendMail(char* c_to, char* c_subject, char* c_body);
void Check(int iStatus, char *szFunction);
void SendNow();
char * to;
char * subject;
char * body;
};


#endif

发送邮件.cpp

#define WIN32_LEAN_AND_MEAN

#pragma once
#include "SendMail.h"
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <windows.h>
#include <winsock2.h>



#pragma comment(lib, "ws2_32.lib")
using namespace std;

// Insist on at least Winsock v1.1
const int VERSION_MAJOR = 1;
const int VERSION_MINOR = 1;

#define CRLF "\r\n" // carriage-return/line feed pair



SendMail::SendMail(char* c_to, char* c_subject, char* c_body)
{
to = c_to;
subject= c_subject;
body = c_body;

}

// Basic error checking for send() and recv() functions
void Check(int iStatus, char *szFunction)
{
if((iStatus != SOCKET_ERROR) && (iStatus))
return;

cerr << "Error during call to " << szFunction << ": " << iStatus << " - " << GetLastError() << endl;
}

void SendNow()
{
// WSADATA WSData;

///* Attempt to intialize WinSock (1.1 or later)*/
// if(WSAStartup(MAKEWORD(VERSION_MAJOR, VERSION_MINOR), &WSData))
// {
// cout << "Cannot find Winsock v" << VERSION_MAJOR << "." << VERSION_MINOR << " or later!" << endl;
// ErrMsg="Cannot find Winsock v";
// return;
// }
}

如您所见,Send 方法被注释掉了,所以我无法弄清楚问题出在哪里。

编译器输出为:

Error   6   error LNK1120: 1 unresolved externals   C:\Users\clanderasm\Documents\Visual Studio 2010\Projects\LandeTestConsole\Debug\LandeCplusConsole.exe  LandeCplusConsole
Error 5 error LNK2019: unresolved external symbol "public: void __thiscall SendMail::SendNow(void)" (?SendNow@SendMail@@QAEXXZ) referenced in function _main C:\Users\clanderasm\Documents\Visual Studio 2010\Projects\LandeTestConsole\LandeCplusConsole\LandeCplusConsole.obj LandeCplusConsole

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com