clang - linking a static library with a pch file c

2019-09-15 19:33发布

问题:

Am currently trying to link a bunch of Objective C modules into a static library.

I am getting the following error and am unable to locate any information on how the __STATIC__ can not be disabled when building a PCH file.

error: __STATIC__ predefined macro (as opposed to __DYNAMIC__) was disabled in PCH file but is currently enabled

The command to build the PCH file is:

clang -cc1 -target-cpu x86-64 -g -fno-validate-pch -emit-pch -x objective-c-header afile.pch -o afile.pch.bin -O0 -fmath-errno -fobjc-arc -fobjc-runtime=gnustep -fblocks -pthread -fexceptions -fobjc-exceptions -I...

With lots of -I options to locate header files.

The library file is being built with:

clang -static -o lib.a -include-pch afile.pch.bin ...

with pretty much the same link options and include directories.

Any help would be much appreciated on how to deal with this issue.

回答1:

When using the clang -cc1 option, the static compilation switch for the PCH header file is:

-static-define

(Also the main compilation and link should likely be using --static as opposed to -static; this is from the gcc documentation as opposed to the clang documentation)