Bubu
Bubu

Reputation: 87

Is it possible to link to, include and use a static library without extra include headers/files?

I want to make a static library so that my other projects can use the same code.

Is it possible to link to the static library in the other projects, without having extra include/header files or is there a better way for this?

Upvotes: 1

Views: 903

Answers (2)

Corbell
Corbell

Reputation: 1413

Do you mean the header file that contains the key functionality in your static library, or are you talking about header files of all the dependencies and/or internals used by the static library?

You should have a header (or more than one) to show the facilities of your static library to the code that uses it. (It's possible to omit this but then your static library has no declared interfaces).

But, it's best practice to not include any unneeded headers - those that are used by the library's internal implementation. Often you can move dependency includes into the static library's .cpp files so they aren't exposed by your library's headers.

Upvotes: 1

R Sahu
R Sahu

Reputation: 206717

Is it possible to link to the static library in the other projects, without having extra include/header files?

It is possible. You have to declare the funtions that are defined in the .lib manually before you can use them. It is errorprone and is not advised.

Upvotes: 4

Related Questions