Skip to content

std::expected link error #132945

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

Closed
andrea-cassioli-maersk opened this issue Mar 25, 2025 · 6 comments
Closed

std::expected link error #132945

andrea-cassioli-maersk opened this issue Mar 25, 2025 · 6 comments
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@andrea-cassioli-maersk
Copy link

Compiling the following example

#include <expected>
#include <iostream>

int main() {
  std::expected<int, int> a;
  auto& x = a.value();
  std::cout << x << std::endl;
  return 0;
}

with

/opt/homebrew/opt/llvm@19/bin/clang++ -std=c++23 test-value.cpp

I get the following error

/opt/homebrew/opt/llvm@19/bin/clang++ -std=c++23 test-value.cpp 
Undefined symbols for architecture arm64:
  "std::__1::bad_expected_access<void>::what() const", referenced from:
      vtable for std::__1::bad_expected_access<int> in test-value-22e761.o
  "typeinfo for std::__1::bad_expected_access<void>", referenced from:
      typeinfo for std::__1::bad_expected_access<int> in test-value-22e761.o
  "vtable for std::__1::bad_expected_access<void>", referenced from:
      std::__1::bad_expected_access<void>::bad_expected_access[abi:ne190107]() in test-value-22e761.o
   NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

some more info

➜  tmp /opt/homebrew/opt/llvm@19/bin/clang++ -v
Homebrew clang version 19.1.7
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/19.1.7_1/bin
Configuration file: /opt/homebrew/etc/clang/arm64-apple-darwin23.cfg
System configuration file directory: /opt/homebrew/etc/clang
User configuration file directory: /Users/xxxxxxx/.config/clang

Compiling with clang version 18 gives no error.

Not sure what is the issue. Hope someone can help.

@frederick-vs-ja frederick-vs-ja added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Mar 26, 2025
@frederick-vs-ja
Copy link
Contributor

#87390 seems related.

@andrea-cassioli-maersk
Copy link
Author

andrea-cassioli-maersk commented Mar 26, 2025

Not sure it helps, but

  • using Apple clang works
  • using any level of optimization (-01 and above) works, just -O0 leads to an error

@philnik777
Copy link
Contributor

The problem is that you're using a libc++ dylib which is older than the headers. You need to either make sure that you're loading the correct (homebrew-provided) dylib, or have availability annotations enabled that match AppleClangs. Fundamentally this is a homebrew issue though, since they're not automagically loading the correct dylib. Please ask them for further support/guidance. I'm quite certain this isn't the first issue I've seen related to this. If they need help properly distributing Clang and libc++ they are free to ask.

@philnik777 philnik777 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2025
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Mar 26, 2025
@GuillaumeQuenneville
Copy link

I just ran into this issue. As @philnik777 said, it seems that it was picking up another libc++.
Adding this to my CmakeLists

if(APPLE)
    target_link_options(expected_test PRIVATE
      -L/opt/homebrew/opt/llvm/lib/c++ # TODO: non-hardcoded path
    )
endif()

fixes the issue.

@ldionne
Copy link
Member

ldionne commented Mar 27, 2025

I agree with @philnik777 here, I think this is a Homebrew issue. If you want to file an issue against Homebrew, feel free to ping me on it and I can help them to figure out the right way to distribute on Apple platforms.

@andrea-cassioli-maersk
Copy link
Author

Thanks @ldionne and @GuillaumeQuenneville. It is indeed a configuration issue. For future reference the issue is addressed here https://github.com/orgs/Homebrew/discussions/5849

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

7 participants