未解析的外部'_main'从C0X32.OBJ引用

时间:2014-07-10 06:07:41

标签: c++ c main

#include <CkMailMan.h>
#include <CkEmail.h>
#include <stdio>
void ChilkatSample(void)
    {
//  The mailman object is used for sending and receiving email.
CkMailMan mailman;

//  Any string argument automatically begins the 30-day trial.
bool success;
success = mailman.UnlockComponent("30-day trial");
if (success != true) {
    printf("%s\n",mailman.lastErrorText());
    return;
}

//  Set the SMTP server.
mailman.put_SmtpHost("smtp.chilkatsoft.com");

//  Set the SMTP login/password (if required)
mailman.put_SmtpUsername("myUsername");
mailman.put_SmtpPassword("myPassword");

//  Create a new email object
CkEmail email;

email.put_Subject("This is a test");
email.put_Body("This is a test");
email.put_From("Chilkat Support <support@chilkatsoft.com>");
email.AddTo("Chilkat Admin","admin@chilkatsoft.com");
//  To add more recipients, call AddTo, AddCC, or AddBcc once per recipient.

//  Call SendEmail to connect to the SMTP server and send.
//  The connection (i.e. session) to the SMTP server remains
//  open so that subsequent SendEmail calls may use the
//  same connection.
success = mailman.SendEmail(email);
if (success != true) {
    printf("%s\n",mailman.lastErrorText());
    return;
}

//  Some SMTP servers do not actually send the email until
//  the connection is closed.  In these cases, it is necessary to
//  call CloseSmtpConnection for the mail to be  sent.
//  Most SMTP servers send the email immediately, and it is
//  not required to close the connection.  We'll close it here
//  for the example:
success = mailman.CloseSmtpConnection();
if (success != true) {
    printf("Connection to SMTP server not closed cleanly.\n");
}

printf("Mail Sent!\n");
}

我尝试使用Chilkat库发送STMP邮件。我收到一个错误:“未解析的外部'_main'从C0X32.OBJ引用。”

2 个答案:

答案 0 :(得分:3)

您需要一个main()函数,它是(托管)实现的C入口点。

可能就像添加:

一样简单
int main (void) {
    ChilkatSample();
    return 0;
}

代码,或者它可能要复杂得多。

但最重要的是,您的实施启动代码(C0X32.OBJ)正在尝试查找main,以便它可以开始正常运行您的程序。


此外,如果你在stdio标题之后,你应该使用:

#include <stdio.h>

而不是像现在这样离开扩展程序。

答案 1 :(得分:1)

您缺少程序入口点,即int main()

添加主要功能如下

int  main ( int arc, char **argv ) 
{
    ChilkatSample();
    return 0;
}

现在,您的代码应如下所示,并且应该能够编译

#include <CkMailMan.h>
#include <CkEmail.h>
#include <stdio>
void ChilkatSample(void)
    {
//  The mailman object is used for sending and receiving email.
CkMailMan mailman;

//  Any string argument automatically begins the 30-day trial.
bool success;
success = mailman.UnlockComponent("30-day trial");
if (success != true) {
    printf("%s\n",mailman.lastErrorText());
    return;
}

//  Set the SMTP server.
mailman.put_SmtpHost("smtp.chilkatsoft.com");

//  Set the SMTP login/password (if required)
mailman.put_SmtpUsername("myUsername");
mailman.put_SmtpPassword("myPassword");

//  Create a new email object
CkEmail email;

email.put_Subject("This is a test");
email.put_Body("This is a test");
email.put_From("Chilkat Support <support@chilkatsoft.com>");
email.AddTo("Chilkat Admin","admin@chilkatsoft.com");
//  To add more recipients, call AddTo, AddCC, or AddBcc once per recipient.

//  Call SendEmail to connect to the SMTP server and send.
//  The connection (i.e. session) to the SMTP server remains
//  open so that subsequent SendEmail calls may use the
//  same connection.
success = mailman.SendEmail(email);
if (success != true) {
    printf("%s\n",mailman.lastErrorText());
    return;
}

//  Some SMTP servers do not actually send the email until
//  the connection is closed.  In these cases, it is necessary to
//  call CloseSmtpConnection for the mail to be  sent.
//  Most SMTP servers send the email immediately, and it is
//  not required to close the connection.  We'll close it here
//  for the example:
success = mailman.CloseSmtpConnection();
if (success != true) {
    printf("Connection to SMTP server not closed cleanly.\n");
}

printf("Mail Sent!\n");
}

int  main ( int arc, char **argv ) 
{
    ChilkatSample();
    return 0;
}