C Lynda.com 教程文件无法在终端或 Eclipse 中编译

标签 c terminal eclipse-neon

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/

相关文章:

C字符一行替换

c - 防止输入的字符数组的缓冲区损坏

c - 字数、行数和字符数不适用于 c

Git 设置,终端返回 : command not found

macos - 尝试制作 sublime text 快捷方式时权限被拒绝

android - Eclipse Neon 首选项具有重复的 Android 条目

c - C中Winsock的HTTPS/SSL连接

typescript - 如何设置 typescript 编译器 (tsc) 的默认目标 es 版本?

java.util.concurrent.ExecutionException : org. apache.catalina.LifecycleException: 启动失败

javascript - 在 eclipse 中自动完成 jQuery