[MacPorts] #62426: libc++: using a newer libc++ to build software on older macos systems
MacPorts
noreply at macports.org
Thu Mar 11 02:06:07 UTC 2021
#62426: libc++: using a newer libc++ to build software on older macos systems
--------------------------+----------------------
Reporter: kencu | Owner: kencu
Type: enhancement | Status: assigned
Priority: Normal | Milestone:
Component: ports | Version:
Resolution: | Keywords:
Port: libcxx |
--------------------------+----------------------
Comment (by kencu):
For a start, we'll try to build the attached cpp file that uses the new
std::filesystem features.
We'll do this on Mojave, which does not have these features in the OS-
supplied libc++.dylib.
Using the os-supplied Xcode clang, we don't get far:
{{{
$ /usr/bin/clang++ fstest.cpp
fstest.cpp:9:21: error: expected namespace name
namespace fs = std::filesystem;
~~~~~^
fstest.cpp:12:28: error: use of undeclared identifier 'fs'
void DisplayPathInfo(const fs::path& pathToShow)
^
fstest.cpp:16:13: warning: 'auto' type specifier is a C++11 extension
[-Wc++11-extensions]
for (const auto& part : pathToShow)
^
... and more
}}}
of course, we need c++17 for this to work so we add that, but that gives
us different errors:
{{{
$ /usr/bin/clang++ -std=c++17 fstest.cpp
fstest.cpp:12:32: error: 'path' is unavailable: introduced in macOS 10.15
void DisplayPathInfo(const fs::path& pathToShow)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/filesystem:739:24:
note: 'path' has been
explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
^
fstest.cpp:15:39: error: 'operator<<' is unavailable: introduced in macOS
10.15
cout << "Displaying path info for: " << pathToShow << "\n";
^
... and more
}}}
Apple has marked these {{{std::filesystem}}} features as not being
available in the system libc++.dylib by blocking them in the clang c++
headers, with this file:
{{{
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config
}}}
This can be overridden by passing a specific define:
{{{
// Decide whether to use availability macros.
#if !defined(_LIBCPP_BUILDING_LIBRARY) &&
\
!defined(_LIBCXXABI_BUILDING_LIBRARY) &&
\
!defined(_LIBCPP_DISABLE_AVAILABILITY) &&
\
__has_feature(attribute_availability_with_strict) &&
\
__has_feature(attribute_availability_in_templates) &&
\
__has_extension(pragma_clang_attribute_external_declaration)
# ifdef __APPLE__
# define _LIBCPP_USE_AVAILABILITY_APPLE
# endif
#endif
}}}
and so we add that define to disable the availability tests, and then we
actually see that the link fails because the symbols are not in
{{{/usr/lib/libc++.dylib}}}
{{{
$ /usr/bin/clang++ -std=c++17 -D_LIBCPP_DISABLE_AVAILABILITY fstest.cpp
Undefined symbols for architecture x86_64:
"std::__1::__fs::filesystem::path::__filename() const", referenced from:
std::__1::__fs::filesystem::path::filename() const in fstest-
049dac.o
std::__1::__fs::filesystem::path::has_filename() const in fstest-
049dac.o
.. and more ...
}}}
--
Ticket URL: <https://trac.macports.org/ticket/62426#comment:1>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list