Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

ld: library not found - but the library is there and the flags are correct

I have a linker problems:

I don't understand why but I can't get clang++ to find the library, despite giving all the correct flags.

I tried doing the same things on a linux machine with the same project and it worked perfectly, so this is really a problem with the mac environment.

$ clang++ -std=c++11 -shared ppu_pluggable_device.cc -fPIC \
  -I/opt/homebrew/Caskroom/miniconda/base/envs/tf/lib/python3.10/site-packages/tensorflow/include \
  -L/opt/homebrew/Caskroom/miniconda/base/envs/tf/lib/python3.10/site-packages/tensorflow/python \
  -l:_pywrap_tensorflow_internal.so \
  -O2 -o plugin.so
(...)
ld: library not found for -l:_pywrap_tensorflow_internal.so
clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ ls /opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.10/site-packages/tensorflow/python
(...)
_pywrap_tensorflow_internal.so		estimator				pywrap_mlir.py				user_ops
(...)

Posted on Mar 7, 2022 12:41 PM

Reply

Similar questions

1 reply

Mar 7, 2022 1:52 PM in response to slai-nick

slai-nick wrote:

this is really a problem with the mac environment.

It's a problem with homebrew, or perhaps a problem with your command. That looks like you are trying to link with a static library, but you only seem to have some kind of funky Linux .so dynamic library. Normally low-level dynamic libraries on the Mac are .dylib files. Usually for something like this, it would build fine but then not run, because /opt/homebrew/Caskroom/miniconda/base/envs/tf/lib/python3.10/site-packages/tensorflow/python is probably not in the dylib search path.


Either homebrew should give you static libraries so you can link with this command, or you'll have to figure out how to do the dynamic libraries properly. Using dynamic libraries in this fashion isn't difficult, but it is very rarely done. I would have to dig into it and that isn't likely to happen right now.


Try omitting the -l parameter entirely and see if Homebrew has setup the rest of your environment correctly. You might get lucky.


ld: library not found - but the library is there and the flags are correct

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.