错误C2220:警告被视为错误 - 没有'对象'文件生成

时间:2013-08-14 07:28:35

标签: c++ object compiler-errors project compiler-warnings

我有以下课程

class Cdata12Mnt
{
public:
    char IOBname[ID1_IOB_PIOTSUP-ID1_IOB_TOP][BOADNAM_MAX + 4];
    char ExIOBname[ID1_MAX_INF-ID1_EXIOB_U1TOP][BOADNAM_MAX + 4];
    char cflpath[256];
    char basetext[256];
    UINT database[ID1_MAX_INF];
    int State;

public:
    char SelectPath[256];

public:
    int GetIOBName(int slt,char *Name);
    Cdata12Mnt(char *SelectPath);
    virtual ~Cdata12Mnt();
    int     GetValue(int id);
    int     GetState() { return State; }
};

我的功能如下

Cdata12Mnt::Cdata12Mnt(char *SelectPath)
{
    SCTReg  reg;
    char    buf[256], *cpnt, *npnt, *bpnt1, *bpnt2;
    char    *startcode[] = {"CNTL_CODE ","SEGMENT "};
    char    *stopcode    = {"END_CNTL_CODE "};
    FILE    *fp;
    int     ii, infl;

    State = 0;

    for (ii = 0; ii < (ID1_IOB_PIOTSUP - ID1_IOB_TOP); ii++) {
        strcpy(IOBname[ii], "");
    }

    for (ii = 0; ii < (ID1_MAX_INF-ID1_EXIOB_U1TOP); ii++) {
        **strcpy(ExIOBname[ii], "");**
    }

    sprintf(cflpath, "%s\\%s", SelectPath, CDATAFL);

    if ((fp = fopen(cflpath,"r"))!=NULL) {
        for (ii = 0, infl = 0; fgets(buf, 256, fp) != NULL;) {
            if (infl == 0 && strncmp(buf, startcode[0], strlen(startcode[0])) == 0) {
                if ((cpnt = strchr(&buf[strlen(startcode[0])],*startcode[1])) != NULL) {
                    if (strncmp(cpnt,startcode[1], strlen(startcode[1])) == 0) {
                        infl = 1;
                        continue;
                    }
                }
            }

            if (infl == 0) {
                continue;
            }

            if (strncmp(buf,stopcode,strlen(stopcode))==0) {
                if (ii == ID1_EXIOB_U1TOP) {
                    for (int nDataNumber = ii; nDataNumber < ID1_MAX_INF; nDataNumber++) {
                        database[nDataNumber] = 0;
                    }
                }

                infl = 0;
                continue;
            }

            if (strncmp(&buf[14], " DD ", 4) == 0) {
                if ((cpnt=strchr(buf, ';')) != NULL) {
                    *cpnt = '\0';
                }

                if (ii >= ID1_IOB_TOP && ii < ID1_IOB_PIOTSUP) {
                    if ((bpnt1 = strchr(cpnt + 1,'(')) != NULL && (bpnt2=strchr(cpnt + 1,')'))!=NULL && bpnt1 < bpnt2) {
                        *bpnt2 = '\0';
                        *(bpnt1 + BOADNAM_MAX + 1) = '\0';
                        strcpy(IOBname[ii-ID1_IOB_TOP], bpnt1 + 1);
                    }
                }

                if (ii >= ID1_EXIOB_U1TOP && ii < ID1_MAX_INF) {
                    if ((bpnt1 = strchr(cpnt + 1, '(')) != NULL && (bpnt2=strchr(cpnt+1,')'))!=NULL && bpnt1 < bpnt2) {
                            *bpnt2='\0';
                            *(bpnt1+BOADNAM_MAX+1)='\0';
                            strcpy(ExIOBname[ii-ID1_EXIOB_U1TOP], bpnt1 + 1);
                    }
                }

                for (cpnt = &buf[18]; cpnt != NULL;) {
                    if ((npnt=strchr(cpnt, ',')) != NULL)
                        *npnt='\0';
                }

                if (strchr(cpnt,'H')!=NULL) {
                    sscanf(cpnt,"%XH",&database[ii]);
                } else {
                    database[ii]=atoi(cpnt);
                }

                ii++;
                cpnt = npnt;

                if (cpnt != NULL) {
                    cpnt++;
                }
            }
        }
    }

    fclose(fp);
} else {
    State=-1;
}

当我在Visual Studio 2008中编译此函数时,它会在strcpy(IOBname[ii],"");处给出错误,如下所示

  

错误C2220:警告被视为错误 - 没有&#39;对象&#39;文件生成

如何解决此错误?

5 个答案:

答案 0 :(得分:24)

错误表示警告被视为错误。因此,您的问题是一条警告信息!检查它们并修复它们。

如果您不知道如何找到它们:打开Error ListView&gt; Error List)并点击Warning

答案 1 :(得分:8)

转到project properties -> configurations properties -> C/C++ -> treats warning as error -> No (/WX-)

答案 2 :(得分:6)

此错误消息非常混乱。我刚刚在我的项目中修复了其他“警告”,我真的只有一个(简单的):

  

警告C4101:'i':未引用的局部变量

在我评论了这个未使用的i并编译后,另一个错误就消失了。

答案 3 :(得分:4)

作为旁注,您可以使用#pragma启用/禁用个别警告。您可以查看文档here

来自文档:

// pragma_warning.cpp
// compile with: /W1
#pragma warning(disable:4700)
void Test() {
   int x;
   int y = x;   // no C4700 here
   #pragma warning(default:4700)   // C4700 enabled after Test ends
}

int main() {
   int x;
   int y = x;   // C4700
}

答案 4 :(得分:1)

此警告是关于strcpy的不安全使用。请改为IOBname[ii]='\0';