C语言多文件连接有关问题

C语言多文件连接问题
main.c:

#include"mm.cpp"
int main()
{
printf("the is a main \n");
mm();
}


mm.c

#pragma once
#include<stdio.h>

void mm ()
{
printf("i am a mm \n");
}


ERROR:m.obj : error LNK2005: "void __cdecl mm(void)" (?mm@@YAXXZ) 已经在 main.obj 中定义

哪里错了》?怎么改呢》?
c

------解决方案--------------------
声明放.h中, 定义放.cpp中,然后#include "xx.h"

------解决方案--------------------
因为你已经#include"mm.cpp"了,再把mm.cpp加入工程的话,相关变量和函数都会重复定义。

引用:
引用:把mm.cpp从工程中移除。
你好,能帮我讲一下原因么?
我想知道细节一点的东西

------解决方案--------------------
a simple fix:



int main()
{
        void mm(); //declare its prototype
printf("the is a main \n");
mm();
}


------解决方案--------------------
// main.c
# include <stdio.h>
# include "mm.h"
int main()
{
    printf("the is a main \n");
    mm();

    return 0;
}

// mm.h
# ifndef _MM_H_
# define _MM_H_
void mm();
# endif

// mm.c
# include <stdio.h>
 
void mm ()
{
    printf("i am a mm \n");
}

编译方法gcc -o main main.c mm.c