是否可以在eclipse中导入/运行目标文件?
我们的教授提供了我无法完成的先前作业的目标文件。 完成/测试当前分配需要先前的分配。 以某种方式我可以将它们导入到eclipse中或以某种方式使我的项目与这些目标文件一起工作吗?
假设你有对象文件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 #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 -> Settings -> GCC C Linker -> Miscellaneous
。 在Other objects
单击add按钮并选择print_hello.a
的路径。 还要在GCC C Compiler -> Includes
添加.h
文件的路径。 构建并运行你的项目,它应该输出
Hello!