Click here to Skip to main content
15,611,367 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
OK, I am used to have header and .cpp files.

I have build x.a library from .cc files.

stupid question

how do I access / reference the library when there is no header file ?

What I have tried:

I do not have a clue what to try
Updated 17-Dec-22 9:18am

1 solution

There's not much you can do without a header file, but you probably already have one (or more). For example, the source for your .a library probably contains .h files that the library uses itself. If you check them, you will probably see something like:
class xClass {
   // xClass definition
   xClass(); // constructor
   ~xclass(); // destructor
   bool operator<(const xClass& other) const;
   // other member functions ...

So this would be the header for xClass objects.
To include the header in a compile you would do something like
g++ -I /path_to/library_souce  -L /path_to/library_archive -lx -o myprog 
The -I flag tells the compiler to add "/path_to/library_source" the the search path when looking for the headers, the -L flag tells the compiler (actually the linker, but compiler works for the sake of this discussion) where to look for additional libraries and the -lx flag tells the compiler (again linker, really) what additional libraries to search to resolve object (i.e. compiled class and function definitions) references.

If this is your own library you've written, and you have not separated out the class or function declarations into separate header files, now is a good time to refactor. It's might also a good time to review how C++ namespaces work.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900