[c++] error C2220: warning treated as error - no 'object' file generated

I have below class

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; }
};

And I have function as below

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;
}

When I compile this function in Visual studio 2008, it gives me error at strcpy(IOBname[ii],""); as below

error C2220: warning treated as error - no 'object' file generated

How to fix this error?

This question is related to c++ object compiler-errors project compiler-warnings

The answer is


This warning is about unsafe use of strcpy. Try IOBname[ii]='\0'; instead.


The error says that a warning was treated as an error, therefore your problem is a warning message! The object file is then not created because there was an error. So you need to check your warnings and fix them.

In case you don't know how to find them: Open the Error List (View > Error List) and click on Warning.


This error message is very confusing. I just fixed the other 'warnings' in my project and I really had only one (simple one):

warning C4101: 'i': unreferenced local variable

After I commented this unused i, and compiled it, the other error went away.


As a side-note, you can enable/disable individual warnings using #pragma. You can have a look at the documentation here

From the documentation:

// 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
}

Go to project properties -> configurations properties -> C/C++ -> treats warning as error -> No (/WX-).


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to object

How to update an "array of objects" with Firestore? how to remove json object key and value.? Cast object to interface in TypeScript Angular 4 default radio button checked by default How to use Object.values with typescript? How to map an array of objects in React How to group an array of objects by key push object into array Add property to an array of objects access key and value of object using *ngFor

Examples related to compiler-errors

intellij idea - Error: java: invalid source release 1.9 Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' Deserialize JSON with Jackson into Polymorphic Types - A Complete Example is giving me a compile error Android java.exe finished with non-zero exit value 1 error: expected primary-expression before ')' token (C) What does "collect2: error: ld returned 1 exit status" mean? Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing Maven error :Perhaps you are running on a JRE rather than a JDK? What does a "Cannot find symbol" or "Cannot resolve symbol" error mean? Operator overloading ==, !=, Equals

Examples related to project

How to create a Java / Maven project that works in Visual Studio Code? IntelliJ does not show 'Class' when we right click and select 'New' error C2220: warning treated as error - no 'object' file generated Android Studio: Default project directory Error: Selection does not contain a main type How to open an existing project in Eclipse? The project was not built since its build path is incomplete Eclipse projects not showing up after placing project files in workspace/projects Method to find string inside of the text file. Then getting the following lines up to a certain limit "Sources directory is already netbeans project" error when opening a project from existing sources

Examples related to compiler-warnings

Property getters and setters error C2220: warning treated as error - no 'object' file generated Objective-C implicit conversion loses integer precision 'NSUInteger' (aka 'unsigned long') to 'int' warning How do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit? What is "android:allowBackup"? Why this "Implicit declaration of function 'X'"? How to compile without warnings being treated as errors? warning: implicit declaration of function Multi-character constant warnings What does "control reaches end of non-void function" mean?