Thread: MacOS X and external functions

MacOS X and external functions

From
Gregory Seidman
Date:
I'm trying to get external functions working with PostgreSQL 7.2.1 under
MacOS X. I am using Marc Liyanage's installer package
(http://www.entropy.ch/software/macosx/postgresql/). Aside from being
unable to find postgres.h to include, I can't load any libraries at all.
Any attempt, whether with CREATE FUNCTION ... LANGUAGE C or simply LOAD,
gives the same message. For example, if I try to load libSystem:

ERROR:  Load of file /usr/lib/libSystem.dylib failed: no error message available

Has anyone managed to get external functions working under MacOS X?

--Greg


Re: MacOS X and external functions

From
Tom Lane
Date:
Gregory Seidman <gss+pg@cs.brown.edu> writes:
> Has anyone managed to get external functions working under MacOS X?

FWIW, if the regression tests pass for you then external functions
should work.  plpgsql is a dynamically loaded library, and the
regression tests also build and execute a couple of external functions
from contrib/.

            regards, tom lane

Solved! MacOS X and external functions

From
Gregory Seidman
Date:
Tom Lane sez:
} Gregory Seidman <gss+pg@cs.brown.edu> writes:
} > Has anyone managed to get external functions working under MacOS X?
}
} FWIW, if the regression tests pass for you then external functions
} should work.  plpgsql is a dynamically loaded library, and the
} regression tests also build and execute a couple of external functions
} from contrib/.

I tried the regression tests and the external function test passed, so I
looked into what the test was actually doing. It turns out that the issue
is with MacOS X terminology. There are several different object file
formats supported under MacOS X. Aside from the Classic MacOS stuff, the
are object files (.o), dynamic libraries (.dylib), bundles (.so), and
executables. I thought I needed to create a dynamic library, but it turns
out that the right choice is a bundle.

Could whoever is in charge of documentation please add the contents of the
DocNote I added to http://www.postgresql.org/idocs/index.php?xfunc-c.html

The DocNote is on the page, but for those of you who don't want to bother
going to the web page:

   Until MacOS X is covered in the main body, here is the commandline
   needed to prepare an extension (this assumes that the developer tools
   are installed):

   cc -c foo.c
   cc -bundle -flat_namespace -undefined suppress -o foo.so foo.o

}             regards, tom lane
--Greg


Re: Solved! MacOS X and external functions

From
Bruce Momjian
Date:
OK, can someone suggest where this belongs in the docs?


---------------------------------------------------------------------------

Gregory Seidman wrote:
> Tom Lane sez:
> } Gregory Seidman <gss+pg@cs.brown.edu> writes:
> } > Has anyone managed to get external functions working under MacOS X?
> }
> } FWIW, if the regression tests pass for you then external functions
> } should work.  plpgsql is a dynamically loaded library, and the
> } regression tests also build and execute a couple of external functions
> } from contrib/.
>
> I tried the regression tests and the external function test passed, so I
> looked into what the test was actually doing. It turns out that the issue
> is with MacOS X terminology. There are several different object file
> formats supported under MacOS X. Aside from the Classic MacOS stuff, the
> are object files (.o), dynamic libraries (.dylib), bundles (.so), and
> executables. I thought I needed to create a dynamic library, but it turns
> out that the right choice is a bundle.
>
> Could whoever is in charge of documentation please add the contents of the
> DocNote I added to http://www.postgresql.org/idocs/index.php?xfunc-c.html
>
> The DocNote is on the page, but for those of you who don't want to bother
> going to the web page:
>
>    Until MacOS X is covered in the main body, here is the commandline
>    needed to prepare an extension (this assumes that the developer tools
>    are installed):
>
>    cc -c foo.c
>    cc -bundle -flat_namespace -undefined suppress -o foo.so foo.o
>
> }             regards, tom lane
> --Greg
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Solved! MacOS X and external functions

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> OK, can someone suggest where this belongs in the docs?

Under "Compiling and Linking Dynamically-Loaded Functions",
programmer's guide sec 12.5.7.

            regards, tom lane

Re: Solved! MacOS X and external functions

From
Bruce Momjian
Date:
We do have this in CVS in Makefile.shlib:

    ifeq ($(PORTNAME), darwin)
      shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
      LINK.shared           = $(COMPILER) $(DARWIN_NAMESPACE_SPEC) -bundle -undefined suppress
    endif

If you run the regression tests, you will see the creation of an
extension file at the start of the run.  We don't actually document it
for every platform, but instead have people run regression and look at
the link line for a sample.  This is because Makefile.shlib, combined
with configure, gives a 100% accurate description of the link flags
involved.


---------------------------------------------------------------------------

Gregory Seidman wrote:
> Tom Lane sez:
> } Gregory Seidman <gss+pg@cs.brown.edu> writes:
> } > Has anyone managed to get external functions working under MacOS X?
> }
> } FWIW, if the regression tests pass for you then external functions
> } should work.  plpgsql is a dynamically loaded library, and the
> } regression tests also build and execute a couple of external functions
> } from contrib/.
>
> I tried the regression tests and the external function test passed, so I
> looked into what the test was actually doing. It turns out that the issue
> is with MacOS X terminology. There are several different object file
> formats supported under MacOS X. Aside from the Classic MacOS stuff, the
> are object files (.o), dynamic libraries (.dylib), bundles (.so), and
> executables. I thought I needed to create a dynamic library, but it turns
> out that the right choice is a bundle.
>
> Could whoever is in charge of documentation please add the contents of the
> DocNote I added to http://www.postgresql.org/idocs/index.php?xfunc-c.html
>
> The DocNote is on the page, but for those of you who don't want to bother
> going to the web page:
>
>    Until MacOS X is covered in the main body, here is the commandline
>    needed to prepare an extension (this assumes that the developer tools
>    are installed):
>
>    cc -c foo.c
>    cc -bundle -flat_namespace -undefined suppress -o foo.so foo.o
>
> }             regards, tom lane
> --Greg
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073