@@ -76,7 +76,9 @@ class UnixCCompiler(CCompiler):
7676 static_lib_extension = ".a"
7777 shared_lib_extension = ".so"
7878 dylib_lib_extension = ".dylib"
79+ xcode_stub_lib_extension = ".tbd"
7980 static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
81+ xcode_stub_lib_format = dylib_lib_format
8082 if sys .platform == "cygwin" :
8183 exe_extension = ".exe"
8284
@@ -255,12 +257,28 @@ def library_option(self, lib):
255257 def find_library_file (self , dirs , lib , debug = 0 ):
256258 shared_f = self .library_filename (lib , lib_type = 'shared' )
257259 dylib_f = self .library_filename (lib , lib_type = 'dylib' )
260+ xcode_stub_f = self .library_filename (lib , lib_type = 'xcode_stub' )
258261 static_f = self .library_filename (lib , lib_type = 'static' )
259262
260263 if sys .platform == 'darwin' :
261264 # On OSX users can specify an alternate SDK using
262265 # '-isysroot', calculate the SDK root if it is specified
263266 # (and use it further on)
267+ #
268+ # Note that, as of Xcode 7, Apple SDKs may contain textual stub
269+ # libraries with .tbd extensions rather than the normal .dylib
270+ # shared libraries installed in /. The Apple compiler tool
271+ # chain handles this transparently but it can cause problems
272+ # for programs that are being built with an SDK and searching
273+ # for specific libraries. Callers of find_library_file need to
274+ # keep in mind that the base filename of the returned SDK library
275+ # file might have a different extension from that of the library
276+ # file installed on the running system, for example:
277+ # /Applications/Xcode.app/Contents/Developer/Platforms/
278+ # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
279+ # usr/lib/libedit.tbd
280+ # vs
281+ # /usr/lib/libedit.dylib
264282 cflags = sysconfig .get_config_var ('CFLAGS' )
265283 m = re .search (r'-isysroot\s+(\S+)' , cflags )
266284 if m is None :
@@ -274,6 +292,7 @@ def find_library_file(self, dirs, lib, debug=0):
274292 shared = os .path .join (dir , shared_f )
275293 dylib = os .path .join (dir , dylib_f )
276294 static = os .path .join (dir , static_f )
295+ xcode_stub = os .path .join (dir , xcode_stub_f )
277296
278297 if sys .platform == 'darwin' and (
279298 dir .startswith ('/System/' ) or (
@@ -282,13 +301,16 @@ def find_library_file(self, dirs, lib, debug=0):
282301 shared = os .path .join (sysroot , dir [1 :], shared_f )
283302 dylib = os .path .join (sysroot , dir [1 :], dylib_f )
284303 static = os .path .join (sysroot , dir [1 :], static_f )
304+ xcode_stub = os .path .join (sysroot , dir [1 :], xcode_stub_f )
285305
286306 # We're second-guessing the linker here, with not much hard
287307 # data to go on: GCC seems to prefer the shared library, so I'm
288308 # assuming that *all* Unix C compilers do. And of course I'm
289309 # ignoring even GCC's "-static" option. So sue me.
290310 if os .path .exists (dylib ):
291311 return dylib
312+ elif os .path .exists (xcode_stub ):
313+ return xcode_stub
292314 elif os .path .exists (shared ):
293315 return shared
294316 elif os .path .exists (static ):
0 commit comments