0

When I try to compile my eek.cpp file with g++ eek.cpp -o eek -fsanitize=undefined flag, it shows:

ld: library not found for -lubsan
collect2: error: ld returned 1 exit status

but g++ eek.cpp -o eek is working fine. My terminal screenshot here.

I'm using zsh and gcc 10.2.0 on macOS Big Sur. fsanitize=undefined was still working yesterday before I updated my macOS from Catalina.

The ubsan.h file does exist in /usr/local/Cellar/gcc/10.2.0_2/lib/gcc/10/gcc/x86_64-apple-darwin20/10.2.0/plugin/include, but it isn't working. I've also read this post but it didn't solve my problem. How should I fix it?

Cow Frog
  • 1
  • 2
  • 1
    *How* are you building? Please [edit] your question to show us the exact commands. Also please take some time to read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Jan 17 '21 at 06:39
  • Obviously you need the ubsan *library*, not the ubsan *header*. – n. m. could be an AI Jan 17 '21 at 06:51

2 Answers2

1

I've had the same problem since I updated my macOS, but have just now fixed with brew upgrade. I'm sorry that I can't say what formula was involved in this problem, but updating formulae would be worth trying.

kaage
  • 11
  • 1
0

I had similar problem when trying to compile a fortran program and getting the error ld: librarynot found for -lSystem. The answer of @kaage helped me but I don't have enough reputation to comment it.

I just wanted to add that when running brew upgrade it complained that my command line tools were too outdated. Running (as suggested by brew itself)

 sudo rm -rf /Library/Developer/CommandLineTools
 sudo xcode-select --intsall

fixed it.

Not sure this perfectly targets the question asked though so feel free to correct me.

Tafuzzo
  • 1
  • 1