2015-05-06 49 views
0

我们的教授提供了以前任务的目标文件,我无法完成。完成/测试当前作业需要完成此前的作业。是否有可能以某种方式将它们导入到eclipse中或以某种方式使我的项目与这些目标文件一起工作?是否可以在eclipse中导入/运行目标文件?

+0

你还需要头文件和函数/类声明。 – NikolayKondratyev

+0

谢谢,我会在稍后问教授。是否只需将对象文件拖放到与我的程序相同的源文件夹中? – AlldaRage

回答

0

比方说,你有目标文件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 -> Settings -> GCC C Linker -> Miscellaneous。在Other objects点击添加按钮,然后选择print_hello.a的路径。还要在GCC C Compiler -> Includes中添加.h文件的路径。建立和运行你的项目,它应该输出

Hello! 
相关问题