【发布时间】:2016-11-17 16:26:41
【问题描述】:
我在main.c 中使用了一个名为header.h 的标头。
功能测试在header.h 中公布,在test.c 中定义。
但是,即使我使用构建系统作为 C,它也会在下面说出这些话。
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
Undefined symbols for architecture x86_64:
"test(int)", referenced from:
_main in main-a4d82e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 0.6s with exit code 1]
[cmd: ['bash', '-c', 'g++ -Wall -std=c++11 -O2 \'/Users/hanlock/Documents/CODE/TEST/TEST/main.c\' -o \'/Users/hanlock/Documents/CODE/TEST/TEST/main\' && osascript -e \'tell application "Terminal" to activate do script " cd \\"/Users/hanlock/Documents/CODE/TEST/TEST\\" &&start_ms=$(ruby -e \\"puts (Time.now.to_f * 1000).to_i\\")&&clear&&\\"/Users/hanlock/Documents/CODE/TEST/TEST/main\\" &&elapsed_ms=$(($(ruby -e \\"puts (Time.now.to_f * 1000).to_i\\") - start_ms))&& read -p \\"Press Enter to exit($elapsed_ms ms).\\"&&exit"\'']]
[dir: /Users/hanlock/Documents/CODE/TEST/TEST]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
我在 C++ 中读过类似的问题。但是,它似乎不适用于我的情况。 所以,问题来了。如何在 C 语言中使用带有 sublime 的外部头文件?
代码如下:
main.c
#include <stdio.h>
#include "./Header.h"
int main(int argc, const char * argv[]) {
test(1);
return 0;
}
header.h
#ifndef Header_h
#define Header_h
int test(int);
#endif
test.c
#include <stdio.h>
int test(int i){
printf("%d\n",i);
return 0;
}
【问题讨论】:
-
你能把你的代码和你用来编译它的命令包括进来吗?
-
当然。已编辑。顺便说一句,它可以在 Xcode 中使用相同的代码。
-
名字好像不匹配,是header叫head.h还是Header.h?
-
哦,我编辑这个问题时弄错了。它没有出现在代码中。就像我说的,它可以在 Xcode 中运行。
标签: c sublimetext3