Hyz Yuzhou
Hyz Yuzhou

Reputation: 83

Is there any way to do preprocessing when linking static libraries?

I have some source files .c; they are actually a library provided by others. When I build my program to use this library, I have to compile these files again. I can't to compile the files into a static library because the sources contain some preprocessor flags. I have to generate many static libraries with different composition of preprocessor flags.

So, is there any technique that I can build a static library, and select what preprocessor flags should be used when linking with this library?

Upvotes: 0

Views: 382

Answers (2)

chasep255
chasep255

Reputation: 12175

No you can't. You would need the source code. There are three basic steps in c compiling to go from source to executable.

Source->Preprocessor->Compilation into Object Files->Linking->Executable

The static libraries are kind of like the object files. They have already been compiled and preprocessed before that. Static libraries are used by the linker to make the final executable.

Upvotes: 2

Matteo Italia
Matteo Italia

Reputation: 126787

Nope; a static library is a collection of object modules, a stage of compilation where it's to late to change anything but the linking options.

If you need to have different build options for each project just build the library together with the project that needs it; static libraries are rarely worth the effort anyway.

Upvotes: 1

Related Questions