0

There is a Github repo containing Python "bindings" for a C++ library that I am interested in playing with. The README has abundant information about how to install the C++ library on Linux like machines, but no information about how to do so with a mac OS.

I have also opened up an issue requesting the README installation instructions include mac OS-specific installs in addition to linux. There hasn't been any activity on that issue.

Here are the two repos:

Since the C++ package isn't available for installing via Brew/pip/anaconda, I'm not sure how to get going.

What I've Tried:

I have tried ./configure, and make. There is no ./configure file.

To address the lack of ./configure, read about a tool called autoconf which supposedly generates ./configure for you. I installed it with brew, but am not sure what arguments to pass it. These docs were pretty hard to understand: https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Making-configure-Scripts.html

Just using make results in the error clang: error: unsupported option '-fopenmp'That sent me down a whole different rabbit hole which had me adding lines to the 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)

That felt dangerous because I have no idea what any of that stuff means. Plus it resulted in a new error: *** missing separator. Stop.

So then I read that's probably due to using "soft" tabs instead of "hard" tabs which can be identified using cat -e -t -v makefile_name. I found the one line where a "hard" tab was missing (the indented line above) and inserted it. This resulted in a new error:

make: *** No rule to make target `omp_hello.c', needed by `omp_hello'.  Stop.

Next, following the advice of Yang Yushi and his follow on comments, I changed lines 39 and 40 according to his answer, plus added the locations of some additional files to the CXXFLAGS variable:

-I//opt/homebrew/Cellar/libomp/11.0.1/include 
-L/opt/homebrew/Cellar/libomp/11.0.1/lib

And this got me a little further. Next, OSX didn't like where this script was trying to install, as explained by this answer. So I changed these two lines in the makefile which seemed to dictate install location:

INSTALL_HEAD_DIR = $(DESTDIR)/usr/include/libspot
INSTALL_LIB_DIR = $(DESTDIR)/usr/lib

to

INSTALL_HEAD_DIR = $(DESTDIR)/usr/local/include/libspot
INSTALL_LIB_DIR = $(DESTDIR)/usr/local/lib

And that indeed got me a little farther. Next I ran into an error complaining about the flat -t at these lines in the makefile:

@install -t $(INSTALL_LIB_DIR) $(LIB_DIR)/*.so
@install -t $(INSTALL_HEAD_DIR) $(INC_DIR)/*.h

So I deleted those flags, which then resulted in this error:

Checking the headers installation directory (/usr/local/include/libspot)
Checking the library installation directory (/usr/local/lib)
Installing the shared library (libspot.so)
install: /usr/local/lib: Inappropriate file type or format

For which I can find no reading material and have no clue how to fix. Any further assistance appreciated.

Here's a list of SO and other resources I've perused trying to answer this question:

My Question

How do I proceed.

If you know how to do this, could you also include a brief explanation of the concepts behind each step? I'd be happy to learn a little instead of just copying and pasting commands in the right order.

rocksNwaves
  • 5,331
  • 4
  • 38
  • 77

2 Answers2

1

Compile the C++ source code with Apple Clang

I downloaded the prjoect (libspot) and successfully compiled it on my Mac. I change two lines (39 and 40) in the Makefile to make it work. (Following this answer)

CC = clang++  # change from g++ to default Apple clang
CXXFLAGS = -std=c++11 -Wall -pedantic -Xpreprocessor -fopenmp  -lomp  # additional flags

You should get the binary file by just type make with a "correct" Makefile.

(If you see something like "cant find omp.h", add -I/usr/local/opt/libomp/include to the CXXFLAGS.)


For the Question

The error message in the updated question description

make: *** No rule to make target omp_hello.c', needed by omp_hello'. Stop.

is telling us that the file omp_hello.c is missing. The Makefile is written to compile the source code omp_hello.c to an executable binary file omp_hello. If I have the C source file (omp_hello.c), the Makefile will allow me to compile by just typing

make

instead of

/usr/local/opt/llvm/bin/clang \
-I/usr/local/opt/llvm/include -fopenmp \
-L/usr/local/opt/llvm/lib \
omp_hello.c -o omp_hello

This is just a normal compile process, it has nothing to do with Python. The error message is saying the source code to be compiled (omp_hello.c) is missing.


It looks like this is a small project with custom Makefile. Normally you compile the code with just make. The error you got seems to suggest the lack of llvm. You may want to try install llvm following this answer.

Yang Yushi
  • 725
  • 4
  • 20
  • Thank you, but I made sure I have `llvm` installed as well as `libomp`. I have already seen that answer. – rocksNwaves Feb 02 '21 at 17:58
  • Maybe try to change `CPP = /usr/local/opt/llvm/bin/clang` to `CPP = /usr/local/opt/llvm/bin/clang++`? – Yang Yushi Feb 02 '21 at 17:59
  • Unfortunately, that still leaves me with `*** No rule to make target `omp_hello.c', needed by `omp_hello'. Stop.` – rocksNwaves Feb 02 '21 at 18:04
  • Oh sorry this is saying you don't have the file `omp_hello.c`. Do you see the file in your current folder? (Also this is actually a C file not C++ so maybe you want to change `CPP` back to `CPP = /usr/local/opt/llvm/bin/clan`...) – Yang Yushi Feb 02 '21 at 18:07
  • Hi @rocksNwaves it might also be helpful if you share the link to the repository that you are playing with. – Yang Yushi Feb 02 '21 at 18:09
  • Hi @rocksNwaves I compiled the project on my Mac, and I modified its Makefile a little bit. I posted my method in the answer. Hopefully it would help. – Yang Yushi Feb 02 '21 at 18:33
  • when I see the `omp.h` error, should I add that flag in addition to what is already there or replace what is already there? – rocksNwaves Feb 02 '21 at 18:54
  • 1
    Add it to the end, something like `CXXFLAGS = -std=c++11 -Wall -pedantic -Xpreprocessor -fopenmp -lomp -I/usr/local/opt/libomp/include` – Yang Yushi Feb 02 '21 at 18:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/228174/discussion-between-rocksnwaves-and-yang-yushi). – rocksNwaves Feb 02 '21 at 18:55
0

Usually it comes to running brew install <your C++ package> or downloading the source code to some directory and running a set of commands:

./configure
make
make install

While usually it works, some packages can not be installed on Mac since their maintainers did not prepare configuration for Mac.

igrinis
  • 12,398
  • 20
  • 45
  • There is no `./configure` file in the repo I cloned from GitHub. I tried just using `make` but got `clang: error: unsupported option '-fopenmp'` – rocksNwaves Feb 02 '21 at 17:19
  • If you fail on the first try, I suggest taking other path. Try installing Linux as VM. It will probably be much faster. – igrinis Feb 02 '21 at 18:20