0

My issue is with the openmp not working with a C Extension in a python setup.py file.

I am running this code and I have a setup.py file as below:

from setuptools import *

libTM = Extension('libTM',
                  sources = ['pyTsetlinMachineParallel/ConvolutionalTsetlinMachine.c', 'pyTsetlinMachineParallel/MultiClassConvolutionalTsetlinMachine.c', 'pyTsetlinMachineParallel/Tools.c'],
                  include_dirs=['pyTsetlinMachineParallel'],
                  extra_compile_args=['-fopenmp'],
                  extra_link_args=['-lgomp'])

setup(
   name='pyTsetlinMachineParallel',
   version='0.2.1',
   ]
)

Now when I compile this using python3 setup.py build , I get a clang-13 error:

ld: library not found for -lgomp
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

I know openmp is installed on my mac (installed with Homebrew) because I can run the OpenMP test code with the following Makefile:

CPP = /usr/local/opt/llvm/bin/clang
CPPFLAGS = -I/usr/local/opt/llvm/include -fopenmp
LDFLAGS = -L/usr/local/opt/llvm/lib

omp_hello: omp_hello.c
    $(CPP) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)

This is the result if I do echo $PATH:

/usr/local/opt/llvm/lib:/usr/local/opt/llvm/include:/usr/local/opt/llvm/bin:/usr/local/opt/python@3.7/bin:/Users/Saram/bin:/usr/local/bin:/usr/local/opt/llvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands

ANY help would be appreciated, I have tried nearly everything I can find on StackOverflow and I am really struggling. Thank you.

  • PATH doesn't tell `ld` where to look for libraries! `-L` does, so are there libgomp.* in /usr/local/opt/llvm/lib ? – Marcus Müller Mar 22 '22 at 18:04
  • @MarcusMüller No, there aren't any libgomp.* files in /usr/local/opt/llvm/lib. but there is a file with name libomp.dylib – Saram Abbas Mar 22 '22 at 18:15
  • but you ask the linker to find `libgom` with `-lgomp`, not `libomp`! – Marcus Müller Mar 22 '22 at 18:20
  • so does that mean the linker command is wrong? – Saram Abbas Mar 22 '22 at 18:23
  • That I can't tell you. I don't know your software. Maybe you actually want libgomp, but have libomp installed, or maybe you actually want libomp, but got a g too many in `-lgomp`. Question: did you *try* install libgomp? It will depend on GCC, it's not compatible with clang, as far as I know. – Marcus Müller Mar 22 '22 at 18:25
  • @MarcusMüller I got the setup.py from online, I am not sure which one I need. [This](https://github.com/cair/pyTsetlinMachineParallel) is the link for it. It is a machine learning algorithm needing multithreading. – Saram Abbas Mar 22 '22 at 21:34
  • so you need to figure out whether that needs libgomp or libomp; sorry, we can't do that for you – Marcus Müller Mar 23 '22 at 05:34
  • libgomp is the GCC OpenMP runtime, libomp the LLVM one. (Though beware the Apple induced confusion that `gcc` in XCode is really LLVM, though with OpenMP hidden and no runtime library provided.) – Jim Cownie Mar 23 '22 at 09:03
  • @MarcusMüller @JimCownie I have asked others at my uni and they made theirs work with lgomp, they have ubuntu and it works for them. I have lgomp installed in ```/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11```. Where do I go next? – Saram Abbas Mar 28 '22 at 21:12
  • @SaramAbbas as been explained before, you *cannot* use libgomp without GCC. It's not what you need. You're on a system that does not use GCC natively. So, it doesn't help that all your friends are using it. – Marcus Müller Mar 28 '22 at 21:24
  • @MarcusMüller I do want to thank you for your help so far though. I hope I am not being annoying - I just want to learn. I have installed GCC using homebrew and in my $PATH I have put that GCC before the apple version of it. When I do ```gcc --version```, it shows ```gcc (Homebrew GCC 11.2.0_3) 11.2.0```. So with this GCC, should I be okay to use libgomp? – Saram Abbas Mar 28 '22 at 21:36

1 Answers1

0

If you are linking with -lgomp, the linker will look for a libgomp.* file.

First, try to locate the file with the find command. For my centos machine, it is in /usr/lib64, which I found with the following command: find /usr -name libgomp*.

Then, you have to indicate the location of that directory with either -L compiler option, or setting the LD_LIBRARY_PATH environment variable (Note that PATH is not checked for libs, as others pointed out).

Also, just check if you have libomp.* instead, and try to link with it using -lomp to see if it works.

  • how do I indicate the location of the directory? I put ```-L /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11 ``` in ```extra_link_args``` and now it says ```ld: warning: directory not found for option '-L /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11 -l lgomp'``` – Saram Abbas Mar 28 '22 at 21:32
  • Remove the space between -L and the path. So, it should be `-L/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11` – Nimish Shah Mar 30 '22 at 11:29
  • it says ```ld: warning: directory not found for option '-L/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/ -l lgomp'``` when I do that still. But when I cd into ```/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/```, I can see ```libgomp.a``` ```libgomp.dylib``` and ```libgomp.spec``` etc. – Saram Abbas Mar 30 '22 at 11:42
  • could this be a problem with the ```-l lgomp``` bit? should it be ```libgomp``` since that is what I see in the directory? – Saram Abbas Mar 30 '22 at 11:53
  • I noticed you were using `-l lgomp`, which is incorrect. Just use `-lgomp`. There should be no space after `-l`. It is ok if the name of the library is `libgomp`. '-lgomp' essentially means that the linking will happen with the `libgomp` library. – Nimish Shah Mar 30 '22 at 13:32
  • I tried that, but the warning is still the same. What else could be the problem? – Saram Abbas Mar 30 '22 at 18:12