0

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?

jww
  • 97,681
  • 90
  • 411
  • 885
AlldaRage
  • 121
  • 1
  • 1
  • 8
  • You will also need header file with functions/classes declarations. – Nikolay K May 06 '15 at 20:30
  • Thanks, I'll ask the professor for those later. Do I just drag and drop the object files into the same source folder as my program? – AlldaRage May 06 '15 at 20:44
  • Also see [Link object file to my project Eclipse CDR](https://stackoverflow.com/q/11810701/608639), [Is it possible to import/run object files in eclipse?](https://stackoverflow.com/q/30086902/608639), [How to link object (.o) file in Eclipse](https://stackoverflow.com/q/23396199/608639), [Include object file or assembler file in C Project?](https://stackoverflow.com/q/45338665/608639), [Adding object file to cpp code in eclipse](https://stackoverflow.com/q/25866628/608639) – jww Mar 23 '18 at 20:45

1 Answers1

2

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

#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");
}

Compile it with

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

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();
}

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!
Nikolay K
  • 3,770
  • 3
  • 25
  • 37
  • This shows how to workaround the problem by converting object to lib; doesn't show how to link with object file. – Danijel Sep 26 '22 at 09:48