【问题标题】:Unresolved external '_main' referenced from C0X32.OBJ从 C0X32.OBJ 引用的未解析的外部“_main”
【发布时间】:2014-08-31 09:55:24
【问题描述】:
#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 邮件。我收到一个错误:“从 C0X32.OBJ 引用的未解析的外部 '_main'。”

【问题讨论】:

标签: c++ c main


【解决方案1】:

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

可能就像添加一样简单:

int main (void) {
    ChilkatSample();
    return 0;
}

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

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


此外,如果您在 stdio 标头之后,您应该使用:

#include <stdio.h>

而不是像现在一样放弃扩展。

【讨论】:

    【解决方案2】:

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

    如下添加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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多