Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/dfunc.sgml`
4bc941be250358c776b887e53c57161c80e75bd941b57d8300000001000008d5
 <indexterm><primary>FreeBSD</primary><secondary>shared library</secondary></indexterm>
    </term>
    <listitem>
     <para>
      The compiler flag to create <acronym>PIC</acronym> is
      <option>-fPIC</option>.  To create shared libraries the compiler
      flag is <option>-shared</option>.
<programlisting>
cc -fPIC -c foo.c
cc -shared -o foo.so foo.o
</programlisting>
      This is applicable as of version 13.0 of
      <systemitem class="osname">FreeBSD</systemitem>, older versions used
      the <filename>gcc</filename> compiler.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <systemitem class="osname">Linux</systemitem>
     <indexterm><primary>Linux</primary><secondary>shared library</secondary></indexterm>
    </term>
    <listitem>
     <para>
      The compiler flag to create <acronym>PIC</acronym> is
      <option>-fPIC</option>.
      The compiler flag to create a shared library is
      <option>-shared</option>.  A complete example looks like this:
<programlisting>
cc -fPIC -c foo.c
cc -shared -o foo.so foo.o
</programlisting>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <systemitem class="osname">macOS</systemitem>
     <indexterm><primary>macOS</primary><secondary>shared library</secondary></indexterm>
    </term>
    <listitem>
     <para>
      Here is an example.  It assumes the developer tools are installed.
<programlisting>
cc -c foo.c
cc -bundle -flat_namespace -undefined suppress -o foo.so foo.o
</programlisting>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <systemitem class="osname">NetBSD</systemitem>
     <indexterm><primary>NetBSD</primary><secondary>shared library</secondary></indexterm>
    </term>
    <listitem>
     <para>
      The compiler flag to create <acronym>PIC</acronym> is
      <option>-fPIC</option>.  For <acronym>ELF</acronym> systems, the
      compiler with the flag <option>-shared</option> is used to link
      shared libraries.  On the older non-ELF systems, <literal>ld
      -Bshareable</literal> is used.
<programlisting>
gcc -fPIC -c foo.c
gcc -shared -o foo.so foo.o
</programlisting>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>

Title: Platform-Specific Shared Library Compilation
Summary
This section provides examples of compiler flags and commands for creating shared libraries on various operating systems, including FreeBSD, Linux, macOS, and NetBSD, using different compilers and flags such as -fPIC and -shared.