Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation Failure with Clang from Brewed LLVM #169820

Open
4 tasks done
gen740 opened this issue Apr 23, 2024 · 6 comments
Open
4 tasks done

Compilation Failure with Clang from Brewed LLVM #169820

gen740 opened this issue Apr 23, 2024 · 6 comments
Labels
bug Reproducible Homebrew/homebrew-core bug upstream issue An upstream issue report is needed

Comments

@gen740
Copy link

gen740 commented Apr 23, 2024

brew gist-logs <formula> link OR brew config AND brew doctor output

$ brew config
HOMEBREW_VERSION: 4.2.19
ORIGIN: https://github.com/Homebrew/brew
HEAD: 54bea636b41f7953c01a7da5f488f08c1b42ffd1
Last commit: 31 hours ago
Core tap JSON: 23 Apr 03:12 UTC
Core cask tap JSON: 23 Apr 03:12 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.KuCi5a7okU/org.xquartz:0
HOMEBREW_EDITOR: nvim
HOMEBREW_MAKE_JOBS: 14
Homebrew Ruby: 3.1.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: 14-core 64-bit arm_palma
Clang: 15.0.0 build 1500
Git: 2.44.0 => /opt/homebrew/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 14.4.1-arm64
CLT: 15.3.0.0.1.1708646388
Xcode: 15.3
Rosetta 2: false

$ brew doctor
Your system is ready to brew.

Verification

  • My brew doctor output says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.
  • I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?

Compile following simple C++ code with clang++.

#include <print>
int main() { std::println("{}", "Hello, World"); }

with /opt/homebrew/opt/llvm/bin/clang++ -std=c++23 test.cc.

What happened (include all command output)?

Undefined symbols for architecture arm64:
"std::__1::__is_posix_terminal(__sFILE*)", referenced from:
std::__1::__print::__is_terminalabi:ne180100 in test-285f15.o
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

What did you expect to happen?

Compilation successful.
I confirmed that this code builds successfully with llvm@17.

Step-by-step reproduction instructions (by running brew commands)

brew install llvm
echo '#include <print>\nint main() { std::println("{}", "Hello, World"); }' > test.cc
/opt/homebrew/opt/llvm/bin/clang++ -std=c++23 test.cc
@gen740 gen740 added the bug Reproducible Homebrew/homebrew-core bug label Apr 23, 2024
@ZhongRuoyu
Copy link
Member

I believe this is llvm/llvm-project#77653 (and llvm/llvm-project#84392). As a workaround, try adding the flag -L"$(brew --prefix llvm)"/lib/c++.

@gen740
Copy link
Author

gen740 commented Apr 23, 2024

As a workaround, try adding the flag -L"$(brew --prefix llvm)"/lib/c++.

It works for me. Thanks!

@cho-m cho-m added the upstream issue An upstream issue report is needed label Apr 23, 2024
@talkeren
Copy link

talkeren commented Apr 24, 2024

Hey, I have encountered the same issue and looked into the issue. Yes linking against the bundled libc++ solves it, but it seems that libc++ for macos does support <print> with the native lib, the this is how it was implemented:
llvm/llvm-project@4a87db6
_LIBCPP_AVAILABILITY_HAS_PRINT has to be set to zero so it will just skip using the linked functions and loss a small functionality.
And they set it only with the vendor availability annotations for apple:
https://github.com/llvm/llvm-project/blob/80f510bbc9561324fc13bac22aad2e3ef47a59c5/libcxx/cmake/caches/Apple.cmake#L9
In the libc++ includes in homebrew _LIBCPP_AVAILABILITY_HAS_PRINT is 1, so this feature is only available when linking against the bundled libc++.

@Bo98
Copy link
Member

Bo98 commented Apr 24, 2024

I guess ultimately the problem is the wrong C++ headers being used. If you're linking with system libc++ then it should be using the C++ headers shipped with the macOS SDK.

Currently there isn't an easy way to tell clang to switch between libc++ installs, unless you mess around with -nostdinc++.

Maybe splitting libc++ into a separate formula might be a starting point here.

@talkeren
Copy link

talkeren commented Apr 24, 2024

If you're linking with system libc++ then it should be using the C++ headers shipped with the macOS SDK.

clang and libc++ has the feature to target specific versions of macos (with the availability annotation), so in this situation I still wish that I could use the newest libc++ with that capability and not be stuck with the slowly updating macos sdks. Maybe a different formula for libc++ with LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS could be great.

@talkeren
Copy link

My use case is using clang to distribute a standalone binary for mac, so I want that it will be linked against the system libc.
If anyone else is interested, this was my workaround hack for this issue: (warning: it is permentatly modifying the libc++ headers, I am just using it in a github action)

sed -i '' '/^#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS/d' "$(brew --prefix llvm)"/include/c++/v1/__config_site

after that I could target the minimum version MacOS version that is required for std::println:
echo "CXXFLAGS=-mmacos-version-min=13.3" >> $GITHUB_ENV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/homebrew-core bug upstream issue An upstream issue report is needed
Projects
None yet
Development

No branches or pull requests

5 participants