Mac Makefile Set Library Path

Aug 28, 2013  I've been struggling to find a proper way to set up DYLDLIBRARYPATH variable on Mountain Lion. Second method is downloading the module package from cpansearch.pearl.org and then pointing the terminal to package path,executing 'perl Makefile.PL' and then 'make install'. How to set DYLDLIBRARYPATH on Mac OS X Mountain Lion? I'm able to set PATH in a Makefile on Linux but not Mac OS X. With OS X, the PATH gets set but doesn't get used. Here's a demonstration: On CentOS 6 with bash 4.1.2(1)-release and GNU Make 3.81.

Permalink

Join GitHub today

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

PathSign up
Branch:master
Find file Copy path
Fetching contributors…
# -*- makefile -*-
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# Tested on macOS Sierra (10.12.2) with llvm installed using Homebrew (https://brew.sh)
# brew install llvm
CXX = /usr/local/opt/llvm/bin/clang++ -std=c++11
CXXFLAGS = -fPIC -m64 -Wall -g -O3 -fopenmp -Wno-sign-compare -I/usr/local/opt/llvm/include
CPUFLAGS = -msse4 -mpopcnt
LLVM_VERSION_PATH=$(shell ls -rt /usr/local/Cellar/llvm/ tail -n1)
LDFLAGS = -fPIC -fopenmp -L/usr/local/opt/llvm/lib -L/usr/local/Cellar/llvm/${LLVM_VERSION_PATH}/lib
# common mac flags
SHAREDEXT = dylib
SHAREDFLAGS = -dynamiclib
MKDIR_P = mkdir -p
prefix ?= /usr/local
exec_prefix ?= ${prefix}
libdir = ${exec_prefix}/lib
includedir = ${prefix}/include
##########################################################################
# Uncomment one of the 4 BLAS/Lapack implementation options
# below. They are sorted # from fastest to slowest (in our
# experiments).
##########################################################################
#
# 1. Intel MKL
#
# This is the fastest BLAS implementation we tested. Unfortunately it
# is not open-source and determining the correct linking flags is a
# nightmare. See
#
# https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor
#
# The latest tested version is MKL 2017.0.098 (2017 Initial Release) and can
# be downloaded here:
#
# https://registrationcenter.intel.com/en/forms/?productid=2558&licensetype=2
#
# The following settings are working if MKL is installed on its default folder:
#
# MKLROOT = /opt/intel/compilers_and_libraries/linux/mkl/
#
# LDFLAGS += -Wl,--no-as-needed -L$(MKLROOT)/lib/intel64
# LIBS += -lmkl_intel_ilp64 -lmkl_core -lmkl_gnu_thread -ldl -lpthread
#
# CPPFLAGS += -DFINTEGER=long
#
# You may have to set the LD_LIBRARY_PATH=$MKLROOT/lib/intel64 at runtime.
#
# 2. Openblas
#
# The library contains both BLAS and Lapack. Install with brew install OpenBLAS
#
# CPPFLAGS += -DFINTEGER=int
# LIBS += /usr/local/opt/openblas/lib/libblas.dylib
#
#
# 3. Apple's framework accelerate
#
# This has the advantage that it does not require to install anything,
# as it is provided by default on the mac. It is not very fast, though.
#
CPPFLAGS += -DFINTEGER=int
LIBS += -framework Accelerate
##########################################################################
# SWIG and Python flags
##########################################################################
# SWIG executable. This should be at least version 3.x
# brew install swig
SWIG = /usr/local/bin/swig
# The Python include directories for the current python executable
PYTHON_INC=$(shell python -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())')
NUMPY_INC=$(shell python -c 'import numpy ; print(numpy.get_include())')
PYTHONCFLAGS=-I${PYTHON_INC} -I${NUMPY_INC}
PYTHONLIB=-lpython
##########################################################################
# Faiss GPU
##########################################################################
# As we don't have access to a Mac with nvidia GPUs installed, we
# could not validate the GPU compile of Faiss.

Mac Makefile Set Library Path Map

  • Copy lines
  • Copy permalink
July 24th, 2015

Makefile Export Path

A recent (and even more recently reverted) change to Homebrew highlighted an interesting (read: maddening) quirk of clang on OS X. Here’s the background.

Makefile Add Library

When you compile something using clang on OS X there are (roughly speaking) two stages to the compile. In the first, your source code is loaded and the compiler searches its include paths to find your includes. Here’s what clang’s defaults look like for the Xcode 6.4 command line tools:

Makefile Header File Path

As you can see, the include search starts with /usr/local/include and /usr/include is the fourth item. So, in the case of a vanilla OS X install a binary attempting to compile using OpenSSL (let’s say #include <openssl/x509.h>) would find the OpenSSL headers in /usr/include after searching the previous 3 locations fruitlessly.

Mac Makefile Set Library Path Map

Once it’s found (and the C preprocessor has run and all the objects have been compiled) we now need to link it. When compiling something against OpenSSL you’ll link against -lssl, -lcrypto, or both. These command line flags simply tell the linker to look for something named “libssl.dylib” or “libcrypto.dylib” in the library search paths. But what are those paths?

This time we see two primary library search paths, /usr/lib and /usr/local/lib…which are reversed in priority from our include search path.

The result of this is that if you have something (like OpenSSL) that is present in both /usr/local/{include,lib} and /usr/{include,lib} you’ll end up with the compiler using the headers from /usr/local/include and then linking against the library in /usr/lib. This can result in a variety of problems, the severity of which depend on how different the two versions of the library are and what features the binary you’re compiling is using.

So why does this matter? Well, in El Capitan (10.11) Apple has chosen to remove the OpenSSL development headers, but not remove the dylibs. They deprecated use of system OpenSSL in Lion (10.7) so this makes sense on the surface, but the weird include/linker ordering means that if homebrew (or anything else living in your include/search paths) duplicates a system library bad things may occur. There are four possible paths (all of which are under the control of Apple and not us plebes):

Jan 18, 2017  Libraries have many parts. It is like a city library which is more than just a pile of books on a street corner somewhere. The main parts are the catalog file (the iTunes Library.itl or.xml file) and the media folder which has many folders of media track files. Mac merge itunes libraries. This guide will show you how to merge two iTunes libraries as easily as possible, either between users or same, with Mac OS X (MacOS 10.12 Sierra, Snow Leopard, Lion included). This can be very useful for those who have one iTunes library at home Mac, say iMac, and a MacBook for work, for example. Open iTunes for me. In the iTunes app on your Mac, choose iTunes Quit iTunes. Hold down the Option key while you open iTunes. In the window that appears, do one of the following: Create a new library: Click Create Library. Choose a different library: Click Choose Library. Jul 27, 2019  Click on the “Consolidate Files” option, and click “OK”. Step #4 – Now, take the “Library.xml” file which is the second iTunes library and have it in an accessible location. Step #5 – On iTunes, click on the “File” tab, followed by the “Library” option, and finally click on the “Import Playlist” option.

Mac Makefile Set Library Path System

Mac Makefile Set Library Path
  • Change the linker order preference. Probably a good idea long term but likely to cause all sorts of unintended breakage as we find things that are implicitly depending on this crazy ordering.
  • Re-add the OpenSSL headers for 0.9.8. Not a great option since 0.9.8 is scheduled for EOL at the end of this year and Apple has marked it deprecated in OS X since Lion (originally released July 20, 2011), but probably the safest and lowest friction option.
  • Remove OpenSSL entirely. This would break any OS X app that links against it and would require Apple to ship updates to Ruby, Python, Apache, etc that statically link OpenSSL (or go down the route of a “private” dylib like they’ve done with OpenSSH in El Capitan)
  • Do nothing and let this be a significant source of pain for developers during El Capitan’s lifecycle. This is the most likely scenario.

I favor either removing the OpenSSL dylibs entirely for El Capitan or re-adding the OpenSSL headers and then removing everything in the next major release, but I don’t envy whoever has to make this choice. Everything has downsides.