3

I'm working on a project from school, and we were given a .o and a corresponding .h file. We need to use several functions from the .o file in our .c program. Just placing it in the same directory doesn't work. I tried to look for something like this in the project properties, but no good. I keep getting ../code_files/Search.c:116: undefined reference to 'reportError'

I'm using Eclipse (Juno) CDT, gcc MinGW under Windows 7

I know it's possible to include .a files, but I couldn't find any indication on how to include a .o file #include "ErrorHandle.h" is included in the main c file.

Anyone knows how to include a .o file to a project? Thanks!

La bla bla
  • 8,558
  • 13
  • 60
  • 109
  • Also see [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

2 Answers2

8

I found this answer:

I tried doing something similar, only I didn't think of the miscellaneous thing enter image description here

La bla bla
  • 8,558
  • 13
  • 60
  • 109
  • How does it know where to search for mtm_ex1.o?? – Danijel Nov 06 '18 at 10:57
  • This worked for me only after I added the full path to the object file: `/home/dd/file.o`. Adding the path `/home/dd` to linker lib search paths did not help. – Danijel Sep 26 '22 at 09:55
2

You can trivially turn the .o into a .a with ar cvs library.a object.o, and then add the .a to your project.

John Auld
  • 476
  • 2
  • 12