当项目中有两个 c 源时,无法通过 Eclipse 构建 C 项目

标签 c eclipse build yocto toolchain

我想通过 Eclipse 构建 c 项目。 代码没问题(如下所示)但链接无效。所以我无法构建它们。如果 sub() 的内容在 sub.h 中定义,则构建工作正常。

我经常使用 Microsoft visual studio,但我是 eclipse 的初学者,无法设置链接器选项。

我想做什么

如何通过 Eclipse 链接和构建分离的 C 源代码? 我想通过单击“全部构建”按钮来构建项目。

错误信息

  • 对“子”的 undefined reference

  • collect2:错误:ld 返回了 1 个退出状态

eclipse 设置

enter image description here

主.c

#include <stdio.h>
#include "sub.h"

int main(void)
{
  printf("sub() = %d\n", sub());
  return 0;
}

sub.c

#include "sub.h"

int sub(void)
{
  return 1;
}

子.h

#ifndef SUB_H
#define SUB_H

int sub(void);

#endif

最佳答案

我解决了。这个问题在 yocto 开发的情况下比较特殊。

在 Makefile.am 中添加 sub.c 可以正常构建。

这个链接帮助了我。 https://community.nxp.com/docs/DOC-106613

关于当项目中有两个 c 源时,无法通过 Eclipse 构建 C 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48660406/

相关文章:

c - GLUT不会画画

android - java.lang.NullPointerException React Native

c# - 切换到任何 CPU 配置后,Win Service 项目不会构建

c - #define FOO 1u 2u 4u ... 1u 和 2u 是什么意思?

c - 计算字符的c程序中的段错误

eclipse - 使用 RAD 清除工作空间环境的方法(基于 Eclipse)

eclipse和gradle : do not deploy test classes

java - Jenkins maven无法在JDK中找到Javac编译器

c - 如何为新文件创建补丁?

Java 编译器问题