postgrespro / pgsphere

PgSphere provides spherical data types, functions, operators, and indexing for PostgreSQL.
https://pgsphere.org
BSD 3-Clause "New" or "Revised" License
17 stars 14 forks source link

macOS compilation failure #127

Open chuzhe-as-a-dev opened 4 months ago

chuzhe-as-a-dev commented 4 months ago

Hi all!

Is pg_sphere supported on macOS? I was trying to compile (1.5.1) and install on macOS (Sonoma, 14.5) and this error showed up.

g++ -shared -o pg_sphere.so src/sscan.o src/sparse.o src/sbuffer.o src/vector3d.o src/point.o src/euler.o src/circle.o src/circle_sel.o src/line.o src/ellipse.o src/polygon.o src/path.o src/box.o src/output.o src/gq_cache.o src/gist.o src/gist_support.o src/key.o src/gnomo.o src/epochprop.o src/brin.o src/healpix.o src/moc.o src/process_moc.o healpix_bare/healpix_bare.o -L/opt/homebrew/lib/postgresql@14  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/Cellar/lz4/1.9.4/lib  -Wl,-dead_strip_dylibs   -bundle_loader /opt/homebrew/Cellar/postgresql@14/14.11_1/bin/postgres -L/opt/homebrew/Cellar/healpix/3.82_1/lib -lhealpix_cxx -lz
clang: error: invalid argument '-bundle_loader /opt/homebrew/Cellar/postgresql@14/14.11_1/bin/postgres' not allowed with '-dynamiclib'
make: *** [pg_sphere.so] Error 1

If macOS is supported, does anyone have an idea about this issue? I tried to trace this g++ command in the make file but failed...

esabol commented 4 months ago

I'm sure we'd like to support macOS if we can, but it's probably uncharted territory.

Your output shows an error from clang, but the command is g++. That would seem to imply that g++ isn't really g++, but it's using clang instead.

You might need to install the real gcc and g++ with Homebrew and compile PostgreSQL and this extension using the "real" gcc and g++. But that's just a guess.

esabol commented 4 months ago

Also, I know you definitely need GNU Make to build this extension. I'm not sure if macOS make is GNU or BSD. It's probably BSD since most commands on the Mac are BSD, so you'll probably need to install GNU Make with Homebrew as well, if you haven't already done so. Then make sure you are using GNU Make to build.

chuzhe-as-a-dev commented 4 months ago

@esabol Thanks for the tips! After some digging, I'm now able to compile and install w/o the Healpix package.

What I did first is simply commenting out this line. I found this varibale already defined by Postgres's pgxs/src/Makefile.shlib/Makefile.shlib, which is transitively included by package's Makefile, and seems to work so far. (I'm using Postgres 14.11)

https://github.com/postgrespro/pgsphere/blob/adda8984d20fa13d7b017c59e76a3e5ac905264c/Makefile#L100

Yet, there's another compilation issue of missing Healpix symbols:

Undefined symbols for architecture arm64:
  "T_Healpix_Base<long>::Set(int, Healpix_Ordering_Scheme)", referenced from:
      _moc_disc in process_moc.o
      _moc_polygon in process_moc.o
  "T_Healpix_Base<long>::query_disc_inclusive(pointing, double, rangeset<long>&, int) const", referenced from:
      _moc_disc in process_moc.o
  "T_Healpix_Base<long>::query_polygon_inclusive(std::__1::vector<pointing, std::__1::allocator<pointing>> const&, rangeset<long>&, int) const", referenced from:
      _moc_polygon in process_moc.o
  ...

Looking at Healpix libary file (via symbols path/to/libhealpix_cxx.dylib), I found that there is T_Healpix_Base<int> and T_Healpix_Base<long long> symbols but no T_Healpix_Base<long>. I installed Healpix via Homebrew, so I'm guessing this is caused by Homebrew only distributing template class declarations but no concrete definition. (But this is actually strange as Homebrew rarely modifies source code when packaging AFAIK...)

Compiling with make USE_HEALPIX=0 produces no more error, and following install instructions I was finally able to install and call the package in Postgres.