How to use function from static library if I don’t have header file

Is it a way to use function from static lib, if I don’t have header file, only *.a file, but I know function signature?

How to import C++ header file, from static library, into Obj-C?

I am have a third-party static library, which includes a header file written in C++. I have linked the library, but get compile errors, because the header file uses #include gives a file not found err

how to use makefile to include .a static library and .h file from another directory in C?

I have created a .h header file, implemented and created .a static library file, both of them are in directory in say, /home/data/folder1. I have another .c file which will use link the .h header fil

How to use a function from a header file without including the header in C?

Suppose I have a header file abc.h which defines a function foo(). How can I use the function foo() in the header file abc.h without using #include<abc.h> in my program? I could come up with the

how to use the shared library from haskell without a header file?

I have pdflib_py.so library i want to call from haskell. I do not have a header file. And as you can see the lib’s name is not in the standard libbla form. How do i access it from haskell ? I followed

How do I locate a C library header file from a Makefile.PL?

How can I locate a C library header file from a Makefile.PL? There is ExtUtils::Liblist to find libraries, but I can’t see the equivalent for header files.

Function names extraction from static library

I have a static library static_library.a How to list functions and methods realized there. or at least how to look is there concrete function ‘FUNCTION_NAME’ realized?

how to use complex library in a header file?

I have written a piece of code that uses complex library. I have put the definition of my function in a header file and in the main.cpp i have defined the complex number I as you can see in my codes

Should I use a single header to include all static library headers?

I have a static library that I am building in C++. I have separated it into many header and source files. I am wondering if it’s better to include all of the headers that a client of the library might

Link a static library to a DLL

I am using Visual Studio 5.0 I have DLL and a static library . My intention is to use a static function that is defined in the static library . I have included the header file in the intended source c

How to create a shared object file from static library

How to create a shared object file from a static library? I am using Cygwin. Is the following syntax correct? gcc -shared -o libexample.so libexample.a

Answers

The easiest way: Write the signature in a header file, include it and link against the library.

Yes, if you know the function signature

Just write the function signature before calling it, as:

void f(int); //it is as if you've included a header file

//then call it
f(100);

All you need to do is : link the slib.a to the program.

Also, remember that, if the static library is written in C and has been compiled with C compiler, then you’ve to use extern “C” when writing the function signature (if you program in C++), as:

extern "C" void f(int); //it is as if you've included a header file

//then call it
f(100);

Alternatively, if you’ve many functions, then you can group them together as:

extern "C" 
{
   void f(int); 
   void g(int, int); 
   void h(int, const char*);
} 

You may prefer writing all the function signatures in a namespace so as to avoid any possible name-collisions:

namespace capi
{
  extern "C" 
  {
    void f(int); 
    void g(int, int); 
    void h(int, const char*);
  } 
}

//use them as:

capi::f(100); 
capi::g(100,200); 
capi::h(100,200, "string"); 

Now you can write all these in a header file so that you could include the header file in your .cpp files (as usual), and call the function(s) (as usual).

Hope that helps.