clang: cannot use 'precompiled-header' out

2019-07-21 13:53发布

问题:

When compiling on of my projects, I suddenly got this error message when switching from Xcode 4.5 to Xcode 5.

clang: cannot use 'precompiled-header' output with multiple -arch options    

My GNU Makefile contains the following fragment:

define build
CC-$(platform)-$(2)?=$(CC-$(platform))

$(bindir)/$(platformdir)-$(2)$($(3)-dirsuffix)/$(1)_%: $(srcdir)/$(1)/%.c $(common)
  mkdir -p $$(@D)
  $$(CC-$(platform)-$(2)) $(cflags) $($(3)-cflags) $(CFLAGS) -o $$@ $$^ $($(3)-ldflags) $(LDFLAGS)
endef

$(foreach library,$(libraries),$(foreach arch,$(archs),$(foreach configuration,$(configurations),$(eval $(call build,$(library),$(arch),$(configuration))))))

And $(CC) evaluates to cc which is symlinked to clang.

回答1:

The solution is to filter out header files from the list of files being compiled by using GNU Make's $(filter-out pattern...,text) function to filter out everything that matches %.h:

define build
CC-$(platform)-$(2)?=$(CC-$(platform))

$(bindir)/$(platformdir)-$(2)$($(3)-dirsuffix)/$(1)_%: $(srcdir)/$(1)/%.c $(common)
  mkdir -p $$(@D)
  $$(CC-$(platform)-$(2)) $(cflags) $($(3)-cflags) $(CFLAGS) -o $$@ $$(filter-out %.h,$$^) $($(3)-ldflags) $(LDFLAGS)
endef

And then clang isn't confused anymore.



标签: c xcode gcc clang