是否可以在Eclipse中导入/运行目标文件? [英] Is it possible to import/run object files in eclipse?

查看:246
本文介绍了是否可以在Eclipse中导入/运行目标文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的教授提供了我无法完成的先前作业的目标文件.完成/测试当前作业需要此先前的作业.我可能会以某种方式将它们导入eclipse或以某种方式使我的项目与那些目标文件一起工作吗?

Our professor made available object files of a previous assignment that I wasn't able to complete. This previous assignment is required for completing/testing the current assignment. Would it be possible somehow for me to import them into eclipse or somehow make my project work with those object files?

推荐答案

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

Let's say you have object file print_hello.a and a header print_hello.h. To be more precise let's create print_hello.a:

print_hello.h

print_hello.h

#ifndef __PRINT_HELLO_
#define __PRINT_HELLO_

void print_hello();

#endif /* __PRINT_HELLO__ */

print_hello.c

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

Now we need to add this to Eclipse. Create a project let's call it example. Create a example.c in which you will call print_hello

#include "print_hello.h"

int main() {
    print_hello();
}

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

Now we need to link it to the print_hello.a. Right-click on project and choose Properties. Go to the C/C++ Build -> Settings -> GCC C Linker -> Miscellaneous. In the Other objects click on add button and choose the path to the print_hello.a. Also add path to .h file in GCC C Compiler -> Includes. Build and run you project, it should output

Hello!

这篇关于是否可以在Eclipse中导入/运行目标文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆