Author Topic: Linking an external object file  (Read 5570 times)

mojaam

  • Guest
Linking an external object file
« on: October 10, 2006, 12:46:55 am »
So here's the thing: I have an object file (obj.o) and a header(someHeader.h) of that object file. Then I have my main.c file and included the .h (someHeader.h) so I can use one function in obj.o file. Where do I put that object file? And how do I add it to my project. Note that I'm kind of a noob and that when I use linux (gcc -c main.c then gcc main.o obj.o) it works.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7786
    • My Best Post
Re: Linking an external object file
« Reply #1 on: October 10, 2006, 02:12:35 am »
That is more an GCC and Binutils Question than C::B (CodeBlocks) Question.

http://en.wikipedia.org/wiki/Binutils

In this case I think it is an archiver question, note I have not used GCC much.

http://en.wikipedia.org/wiki/Ar_%28Unix%29

The minGW command appears to be called ar like the standard GNU ar command this is not always true for all GNU commands.

I would create a library using the .o object files via the ar command and then use the library.

Tim S
« Last Edit: October 10, 2006, 02:15:56 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Linking an external object file
« Reply #2 on: October 10, 2006, 02:39:07 am »
Just add obj.o (with path if necessary) in Project->Build options->Linker->Other linker options in the project file you created.


mojaam

  • Guest
Re: Linking an external object file
« Reply #3 on: October 10, 2006, 03:38:32 pm »
Tried both, ar rcs libclass.a ... command and moved it my project folder and when running, it said it couldn't find -lclass. Then I just listed the object file in the other linker options section and it said it couldn't find reference to the function...

It's perhaps because it was compiled and made in Linux and I am trying to run it in windows.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Linking an external object file
« Reply #4 on: October 10, 2006, 05:03:32 pm »
If it was compiled in Linux using the native compiler then it won't work in Windows.