【问题标题】:Is it possible to import/run object files in eclipse?是否可以在 Eclipse 中导入/运行目标文件?
【发布时间】:2015-05-06 20:28:37
【问题描述】:

我们的教授提供了我之前未能完成的作业的目标文件。完成/测试当前作业需要此先前的作业。我是否有可能以某种方式将它们导入 eclipse 或以某种方式使我的项目与这些目标文件一起工作?

【问题讨论】:

标签: c eclipse object-files


【解决方案1】:

假设您有目标文件print_hello.a 和标题print_hello.h。更准确地说,让我们创建print_hello.a

print_hello.h

#ifndef __PRINT_HELLO_
#define __PRINT_HELLO_

void print_hello();

#endif /* __PRINT_HELLO__ */

print_hello.c

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

void print_hello() {
    printf("Hello!\n");
}

用它编译

$ gcc -c print_hello.c -o print_hello.a

现在我们需要将它添加到 Eclipse。创建一个项目,我们称之为example。创建一个example.c,您将在其中调用print_hello

#include "print_hello.h"

int main() {
    print_hello();
}

现在我们需要将其链接到print_hello.a。右键单击项目并选择Properties。转至C/C++ Build -&gt; Settings -&gt; GCC C Linker -&gt; Miscellaneous。在Other objects 中单击添加按钮并选择print_hello.a 的路径。还要在GCC C Compiler -&gt; Includes 中添加.h 文件的路径。构建并运行你的项目,它应该输出

Hello!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    相关资源
    最近更新 更多