当前位置:网站首页>About gcc:multiple definition of

About gcc:multiple definition of

2022-07-28 06:59:00 Zhaoyang

stay ubuntu Edit in environment C Language source code

//file name main.c
#include<stdio.h>
#include "increment.c"
#include "negate.c"

int main()
{
    printf("%d\t%d\n",increment(10),negate(10));
    printf("%d\t%d\n",increment(0),negate(0));
    printf("%d\t%d\n",increment(-10),negate(-10));
    return 0;
}
//file name increment

int increment(int a)
{
    return ++a;
}
//file name negare.c

int negate(int b)
{
    return b*(-1);
}

Compile the connection through the command, and multiple definition of( Error reporting with multiple definitions )

modify main.c file

//file name main.c

include<stdio.h>
int increment(int a);
int negate(int b);

int main()
{
    printf("%d\t%d\n",increment(10),negate(10));
    printf("%d\t%d\n",increment(0),negate(0));
    printf("%d\t%d\n",increment(-10),negate(-10))
}

Recompile connection and execute

 

 

 

 

原网站

版权声明
本文为[Zhaoyang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280518378063.html