0

Make new library project in Xcode (8.3.2), choose Framework: STL (C++ Library), Type: Static, and name it "MyLibrary". You'll get starting files MyLibrary.hpp, MyLibraryPriv.hpp, MyLibrary.cpp. Create new header file, semaphore.h, an place it with in the same folder as all the others. This file should have an include guard definition semaphore_h.

Add in MyLibrary.cpp the following lines:

#include <semaphore.h>

#ifdef _BSD_SEMAPHORE_H
#warning _BSD_SEMAPHORE_H
#endif

#ifdef semaphore_h
#warning semaphore_h
#endif

I am including here a system header file, not the file I just added, but the result of the build is that semaphore_h will be written as a build warning, which is wrong. If I rename my file in Finder then _BSD_SEMAPHORE_H is written, as it should be.

Is this a bug? How to workaround it? I have a header in my project that shares the same name as a system header, but I would rather not change the name.

Strange thing is, if it were an app project (Command Line Tool) then it would work as expected. #include <semaphore.h> would cause _BSD_SEMAPHORE_H warning and #include "semaphore.h" would cause semaphore_h warning. Library project behaves differently than app project.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103

1 Answers1

0

To answer my own question, it's a bug stretching to Xcode 4 and probably beyond. Build option USE_HEADERMAP should be disabled for static libraries (Project settings > Search Paths > Use Header Maps > set to No). Then there should be no collisions between header files of the same name.

The option does not cause problems for apps, though it apparently used to in the past. There's also a SO question for which disabling the option is the answer, but when I read it for the first time I did not realize it applies to my case as well.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103