unorthodox build setup?

Ryan Schmidt ryandesign at macports.org
Sat Oct 6 02:17:45 UTC 2018


Static and dynamic libraries are found at build time by the paths specified in -L arguments, like -L/opt/local/lib. When a library is specified with a -l flag, like -lreduce, it looks for a file libreduce.dylib or libreduce.so or libreduce.a in each of the directories specified by -L flags, plus a few built-in directories like /usr/lib.

It's also possible to specify a library to link with by its absolute path instead of with -L and -l flags, so for example "/opt/local/lib/libreduce.so" instead of "-L/opt/local/lib -lreduce". I don't see this done very often.

Dynamic libraries are found at runtime by their install_names. Using "otool -L" on a program or library, you can see the absolute paths of the libraries it will look for. If they're not there at those paths, the program or library won't work.

Static libraries are embedded at build time. If you link a program with a static library, the static library is copied into the program. So there's nothing to be found at runtime.

-Ryan


On Oct 5, 2018, at 20:05, Mark Brethen wrote:

> I know very little regarding libraries, so thank you! It is building without errors. I also added a similar line for RedPy.so. What about the static library, libreduce.a, how is it found?
> 
> 
> 
> On Oct 5, 2018, at 4:20 PM, Ryan Schmidt wrote:
> 
> 
> 
>>> On Oct 5, 2018, at 16:18, Mark Brethen wrote:
>>> 
>>> libreduce.so: $(OBJ)
>>> 	rm -f libreduce.so
>>> 	gcc $(FAT) -shared $(OBJ) -o libreduce.so
>> 
>> 
>> On this gcc line is where
>> 
>> -install_name /opt/local/lib/libreduce.so
>> 
>> needs to appear.
>> 
> 



More information about the macports-dev mailing list