Lynda.com
类(class):C 基础培训
问题 1:项目文件 - 00_04.c
- 终端:编译并运行正常。
- Eclipse Neon:构建但不在控制台中显示输出。 (使用工具链创建:MacOS X GCC)
00_04.c
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
Eclipse 控制台输出
15:49:04 **** Incremental Build of configuration Debug for project NewProject ****
make all
make: Nothing to be done for `all'.
15:49:04 Build Finished (took 99ms)
问题 2:项目 - 02_01.c
- 终端:无法识别包含的文件
02_01.c
#include <stdio.h> // Notice the library included in the header of this file
#include <stdlib.h>
#include "myLibrary.h" // Notice that myLibrary.h uses different include syntax
myLibrary.h
#ifndef MYLIBRARY_H_
#define MYLIBRARY_H_
void function1(void);
void function2(void);
#endif /* MYLIBRARY_H_ */
myLibrary.c
void function1(void){
puts("It works :)");
}
void function2(void){
//This function does nothing as well
}
终端输出
Undefined symbols for architecture x86_64:
"_function1", referenced from:
_main in 02_01-7f91e4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
最佳答案
如果您运行 cc 02_01.c
作为命令。然后编译器尝试在文件 (02_01.c) 或包含的文件 (myLibrary.h) 中查找 main()
函数。
02_01.c 和 myLibrary.h 中都没有 main()
函数,因此您会收到编译器错误。
要修复此问题,请使 02_01.c 看起来像这样。
#include <stdio.h> // Notice the library included in the header of this file
#include <stdlib.h>
#include "myLibrary.c" // Notice that myLibrary.h uses different include syntax
int main(void)
{
function1();
return 0;
}
关于C Lynda.com 教程文件无法在终端或 Eclipse 中编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40474879/