sharing a function between 2 .c files

前端 未结 3 1132
无人共我
无人共我 2021-01-29 10:24

dir1 has dir2, file1.c and file1.h.

dir2 has file2.c

Now, if I want to access a function defined in file1.c in file2.c, I need to declare it in file1.h and inclu

3条回答
  •  被撕碎了的回忆
    2021-01-29 11:08

    including the .h files is not enough because it only includes the prototype of that function not the definition of the function and the definition of the function is in a seperate .c file.

    one way to fix it is just type:

    gcc -o out file1.c file2.c
    

    or as Nate says you could seperate the compilation process and the link process

提交回复
热议问题