Errors when compiling codeblocks c ++

0

I am trying to compile this code:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

int checkfile(char *argv[0]);
void bind();
void play();

int main(int argn, char *argv[])
{
    if(checkfile(argv)==1)
        bind();
    else
        play();

    return 0;
}

int checkfile(char *argv[0])
{
    FILE *fp;

    int i;
    char *content;

    unsigned long size;

    fp=fopen(argv[0], "rb");

    fseek(fp, 1, SEEK_END);
    size=ftell(fp);

    rewind(fp);
    content=(char *)malloc(size*sizeof(char));
    fread(content, size, 1, fp);

    for(i=0; i<size; i++)
        if(content[i]=='*' && content[i+1]=='*' && content[i+2] == '*') {
            fclose(fp);
            return 0;
        }

    fclose(fp);
    return 1;
}

void bind()
{
    char file1[]="hello1.exe";
    char file2[]="hello2.exe";
    char file3[]="hellobinded.exe";

    char *content1;
    char *content2;

    char separator[]={ '*', '*', '*' };

    unsigned long size1;
    unsigned long size2;

    FILE *fp;

    if((fp=fopen(file1, "rb"))==NULL) { return; }

    fseek(fp, 1, SEEK_END);
    size1=ftell(fp);
    rewind(fp);

    content1=(char *)malloc(size1*sizeof(char));

    fread(content1, size1, 1, fp);
    fclose(fp);

    if((fp=fopen(file2, "rb"))==NULL) { return; }

    fseek(fp, 1, SEEK_END);
    size2=ftell(fp);
    rewind(fp);

    content2=(char *)malloc(size2*sizeof(char));

    fread(content2, size2, 1, fp);

    CopyFile("binder.exe", file3, FALSE);

    if((fp=fopen(file3, "ab"))==NULL) {  return; }

    fwrite(separator, strlen(separator), 1, fp);
    fwrite(content1, size1, 1, fp);
    fwrite(separator, strlen(separator), 1, fp);
    fwrite(content2, size2, 1, fp);

    fclose(fp);
}

void play()
{
    FILE *fp;

    char file1[]="hellobinded.exe";
    char file2[]="new1.exe";
    char file3[]="new2.exe";
    char *content;

    int i, j;

    unsigned long sobra;
    unsigned long filesize;
    unsigned long size;
    unsigned long size1;

    if((fp=fopen(file1, "rb"))==NULL) { return;}

    fseek(fp, 1, SEEK_END);
    size=ftell(fp);

    rewind(fp);
    content=(char *)malloc(size*sizeof(char));
    fread(content, size, 1, fp);

    for(i=0; i<size; i++)
        if(content[i]=='*' && content[i+1]=='*' && content[i+2] == '*') {
            sobra=i+3;
            break;
        }

    for(j=i+6; j<size; j++)
        if(content[j]=='*' && content[j+1]=='*' && content[j+2] == '*') {
            filesize=j-i;
            break;
        }

    size1=sobra+filesize;

    fclose(fp);

    if((fp=fopen(file2, "wb+"))==NULL) { return; }

    for(i=sobra+3; i<size1; i++)
        fputc(content[i], fp);

    fclose(fp);

    if((fp=fopen(file3, "wb+"))==NULL) { return; }

    for(i=j+6; i<size; i++)
        fputc(content[i], fp);

    fclose(fp);


}

But it gives me the following errors:

  

|| === Build: Debug in Example (compiler: GNU GCC Compiler) === |   C: \ Users \ user \ Example \ main.c | 6 | error: conflicting types for 'bind' |   C: \ Program Files \ CodeBlocks \ MinGW \ include \ winsock2.h | 537 | note:   previous declaration of 'bind' was here |   C: \ Users \ user \ Example \ main.c | 47 | error: conflicting types for 'bind' |   C: \ Program Files \ CodeBlocks \ MinGW \ include \ winsock2.h | 537 | note:   previous declaration of 'bind' was here | || === Build failed: 2   error (s), 0 warning (s) (0 minute (s), 9 second (s)) === |

Can the compiler be doing something wrong?

    
asked by Perl 02.11.2016 в 10:17
source

1 answer

2

bind is a name already used by winsock2. What happens is that there is a collision with the names.

Change the name of your function or insert it into a namespace to avoid the collision:

namespace MisFunciones
{
  void bind()
  { ... }
} 

int main()
{
  // ...
  MisFunciones::bind();
  // ...
}

Greetings.

    
answered by 02.11.2016 / 10:24
source