0

I have been given a static library(.a) by my client for my project. The objective of this static library is to integrate the functionality present in the library to my project.

The problem I'm facing is that when I'm trying to link this file, my linker could not link it and throws error.

Eg: consider the library has a function defined "void get_input ()". When I trying to invoke this function in my c file, my linker throws the error that the symbol is undefined.

I'm using Greenhills compiler.

  • Did they provide headers? https://stackoverflow.com/questions/2612027/static-library-but-i-still-need-headers – Jerry Zhao Jun 08 '17 at 18:33
  • you have to link the library and include all the necessary header file using `-I`. undefined reference happens because its not able to find the reference. – danglingpointer Jun 08 '17 at 18:34
  • 1
    "could not link it and throws error" is a very bad problem description. ***What*** error do you get? Please edit your question to include the full, copy-paste and unedited build output. And please take some time to [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). – Some programmer dude Jun 08 '17 at 18:34
  • Also note that the order of libraries and object files on the command line when linking might be important. Please show us *how* you build as well. And try to experiment with the order of object files and libraries on the command line. – Some programmer dude Jun 08 '17 at 18:36
  • I cannot paste the code. Sorry for the trouble. I do have a header file provided. I have included the header file in my source file. Still it throws the error that the symbol(function name) cannot be resolved – Sanal Parakkat Jun 08 '17 at 18:39
  • @JerryZhao BTW if the error is a linking error it means that the code does *compile* ==> headers are fine. – SHG Jun 08 '17 at 18:44
  • Try to use `nm ` command (if it's Linux). It will show you all the symbols in the library, you can verify `get_input()` is there. – SHG Jun 08 '17 at 18:46
  • @some programmer dude - does order of the object file and library matter? I'm asking you because I'm trying to link all the object and library files of the project in randomly. – Sanal Parakkat Jun 08 '17 at 18:56
  • @shg - is it possible to extract the object files present inside the static library? – Sanal Parakkat Jun 08 '17 at 18:57
  • The order *might* be significant, it depends on the linker. Place object files first, then libraries last. Like if `A` depends on `B` then `A` must come before `B` on the linker command line. – Some programmer dude Jun 08 '17 at 19:02
  • You don't care about the object files anymore because it's already a binary. You just want to make sure the needed symbols are in. – SHG Jun 08 '17 at 19:12
  • I got the issue. After dumping the object file, I found that the static file(.a) is generated for power PC architecture. I'm working for a project whose controller architecture is different than power PC architecture. Thank you all for the suggestions. – Sanal Parakkat Jun 09 '17 at 11:43

0 Answers0