C语言include的路径问题

使用#include引用的时候,无法顺利引用。
以下为代码:

#include "print.h"
int main(void){
  printHello();
  return 0;
}


#include <stdio.h>

void printHello(void);


#include "print.h"
    void printHello(){
      printf("Hello World \n");
}



图片描述

层级是这样的,请问大家如何解决。

阅读 4.2k
2 个回答

A2A

Your error is caused by printHello in print.h, it should be printfHello, so just a typo.

You can refer to another my answer here: https://segmentfault.com/q/10...

Update

it seems you write wrong compile commands, try simplest solution:

 gcc print.c test.c 
 ./a.out

编译的时候,如果你用的是GCC或clang,可以添加编译指令:

-I.

来告诉编译器在.(即当前目录下)搜索#include包含的文件

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进