Search code examples
cunixcompilationsolaris

Can I compile a C program which depends of a library, but this library isn´t a .h file is a binary file, because it was compiled anteriority?


I have a program in C (program_a.c) this program depends some functions that it doesn't have declared in its body, because this functions are in another file (library.h), but I don't have the file .h or file .c only I have the version compilated which is a binary file.

Can I compile my program and make use of this library that isn´t a .h or .c file?


Solution

  • If your program is using a function func() from this external compiled library then you'd need to have:

    1. func() declaration - typically it will be in a header file, (which typically is provided with the library). If this file is called profile.h you'd #include it from the source code in your program that is calling func().
    2. func() definition - the implementation of this function - although you cannot see it, it must be in the binary of this library. You can verify it by running the nm libprofile.a which will show you the library's functions names (although sometimes it might not display them if its symbols were stripped when compiled).

    If you don't have the declaration - your code wouldn't compile.

    If you don't have the definition - your code wouldn't link.