鍍金池/ 問答/C  網(wǎng)絡(luò)安全/ C語言include的路徑問題

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");
}



圖片描述

層級是這樣的,請問大家如何解決。

回答
編輯回答
凝雅

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

2018年8月3日 21:19
編輯回答
維他命

編譯的時候,如果你用的是GCC或clang,可以添加編譯指令:

-I.

來告訴編譯器在.(即當前目錄下)搜索#include包含的文件

2017年11月3日 15:01