convert a static library to a dynamic one?

Mark Brethen mark.brethen at gmail.com
Mon Nov 19 14:48:35 UTC 2018


I think it may have been the unused objects from mpich that was causing the error, so I went back and read the ld manual again and noted that -noall_load is the default. (If you use it, you get an error message: ld: warning: option -noall_load is obsolete and being ignored). Here is the linker command that actually works:

system -W ${worksrcpath}_SHARED \
        "ld spooles.a -dylib -macosx_version_min ${os.version} ${configure.ld_archflags} -x -install_name ${prefix}/lib/libspooles.1.dylib -o libspooles.1.dylib”

brethen-air:~ marbre$ otool -hv /opt/local/lib/libspooles.1.dylib
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64  X86_64        ALL  0x00       DYLIB    11        528   NOUNDEFS DYLDLINK TWOLEVEL NO_REEXPORTED_DYLIBS

The dylib is actually quite small, ~4 KB, compared to the static library, 156 KB.

Mark Brethen
mark.brethen at gmail.com



> On Nov 19, 2018, at 1:23 AM, Mark Brethen <mark.brethen at gmail.com> wrote:
> 
> With the ‘-r’ option on ld I ended up with an object, not dylib:
> 
> brethen-air:~ marbre$ otool -hv /opt/local/lib/libspooles.1.dylib
> Mach header
>      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
> MH_MAGIC_64  X86_64        ALL  0x00      OBJECT     4        688 SUBSECTIONS_VIA_SYMBOLS
> 
> Removing that, however, causes it to fail: symbol(s) not found for architecture x86_64
> 
> This builds the archive file:
> 
> :debug:build system -W /opt/local/var/macports/build/_Users_marbre_ports_math_spooles/spooles/work/spooles.2.2_SHARED/MPI/src: /usr/bin/make -f makeGlobalLib
> :info:build /opt/local/bin/mpicc-mpich-mp -c -Os -fPIC -I/opt/local/include/mpich-mp aggListMPI.c -o MPI_aggListMPI.o
> .
> .
> .
> :info:build /opt/local/bin/mpicc-mpich-mp -c -Os -fPIC -I/opt/local/include/mpich-mp utilities.c -o MPI_utilities.o
> :info:build ar rv ../../spooles.a MPI_*.o
> :info:build ar: creating archive ../../spooles.a
> .
> .
> .
> :info:build rm -f MPI_*.o
> :info:build ranlib ../../spooles.a
> 
> Then use linker to convert static library to dylib:
> 
> :debug:build system -W /opt/local/var/macports/build/_Users_marbre_ports_math_spooles/spooles/work/spooles.2.2_SHARED: ld -dylib -arch x86_64 -all_load spooles.a -x -install_name /opt/local/lib/libspooles.1.dylib -o libspooles.1.dylib
> 
> Why doesn’t this work?
> <main.log>
> Mark Brethen
> mark.brethen at gmail.com
> 
> 
> 
>> On Nov 18, 2018, at 5:54 PM, Joshua Root <jmr at macports.org> wrote:
>> 
>> The default value of configure.ld_archflags is '-arch
>> ${configure.build_arch}' provided the selected compiler supports -arch.
>> So ‘-arch ${configure.ld_archflags}’ expands to e.g. ‘-arch -arch
>> x86_64’. Don't do that. :)
>> 
>> You can easily find out the value of any variable in a portfile by
>> adding a line like:
>> 
>> puts "somevar = ${somevar}"
>> 
>> (Just run something like 'port info' to trigger it.)
>> 
>> - Josh
>> 
>> On 2018-11-19 09:34 , Mark Brethen wrote:
>>> This port does not have a configure phase and I set 'universal no’ It
>>> errors with ‘-arch ${configure.ld_archflags}’. How is this variable set? 
>>> 
>>> 
>>> Mark Brethen
>>> mark.brethen at gmail.com <mailto:mark.brethen at gmail.com>
>>> 
>>> 
>>> 
>>>> On Nov 18, 2018, at 4:16 PM, Joshua Root <jmr at macports.org
>>>> <mailto:jmr at macports.org>> wrote:
>>>> 
>>>> configure.ld_archflags
>>> 
> 



More information about the macports-dev mailing list