Mac OS 10.16 Linking Homebrew installed libraries - macos

I have been using homebrew for long time and never faced this strange issue. For some reason I will not explain here am using MacOS 10.16 (Big Sur), a Beta version of latest MacOS and have installed libraries using homebrew. One of those library is zlib. But building with CMake, It cannot find the library. I have tried to build wxWidgets as well as libcurl. Both have failed with similar error:
-- make[2]: *** No rule to make target `/usr/lib/libz.dylib', needed by `lib/libwx_baseu-3.1.dylib'. Stop.
make[1]: *** [libs/base/CMakeFiles/wxbase.dir/all] Error 2
make: *** [all] Error 2
it seems like the libraries search path does not include /usr/local/opt/zlib/lib where the library is found. In another machine running 10.13 High Sierra it works fine.
brew info zlib
zlib: stable 1.2.11 (bottled) [keg-only]
General-purpose lossless data-compression library
https://zlib.net/
/usr/local/Cellar/zlib/1.2.11 (12 files, 376.4KB)
Poured from bottle on 2020-07-02 at 11:34:14
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/zlib.rb
==> Caveats
zlib is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
For compilers to find zlib you may need to set:
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
For pkg-config to find zlib you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
Relevant contents of CMakeList.txt
cmake_minimum_required(VERSION 2.8.11)
# Project name
project(MyApp)
# This setting is useful for providing JSON file used by CodeLite for code completion
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CONFIGURATION_NAME "MacOSXDebug")
set(CL_WORKSPACE_DIRECTORY ..)
# Set default locations
set(CL_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/${CL_WORKSPACE_DIRECTORY}/cmake-build-${CONFIGURATION_NAME}/output)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CL_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CL_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CL_OUTPUT_DIRECTORY})
set(PROJECT_Studio_PATH "${CMAKE_CURRENT_LIST_DIR}")
set(WORKSPACE_PATH "${CMAKE_CURRENT_LIST_DIR}/..")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#Build wxWidgets first
message("Building wxWidgets Libraries")
execute_process(COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets)
execute_process(COMMAND git submodule update --init
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../dependencies/wxWidgets
)
find_program(CMAKE_EXE cmake HINTS "/usr/local/bin/")
message("CMake executable at: ${CMAKE_EXE}")
execute_process(
COMMAND ${CMAKE_EXE} -DCMAKE_BUILD_TYPE=Debug -DwxUSE_EXPAT=builtin -DwxBUILD_PRECOMP=OFF ${CMAKE_SOURCE_DIR}/../dependencies/wxWidgets -B ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets
ERROR_VARIABLE WX_BUILD_ERROR
COMMAND_ECHO STDOUT
)
message(STATUS ${WX_BUILD_OUTPUT})
message(STATUS ${WX_BUILD_ERROR})
execute_process(
COMMAND make -j4 #VERBOSE=1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets
ERROR_VARIABLE WX_BUILD_ERROR
COMMAND_ECHO STDOUT
)
message(STATUS ${WX_BUILD_OUTPUT})
message(STATUS ${WX_BUILD_ERROR})
#Setup wxWidgets
set(ENV{PATH} "${CMAKE_CURRENT_BINARY_DIR}/wxWidgets:$ENV{PATH}")
set(WXWIN ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets)
set(CMAKE_MACOSX_RPATH TRUE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_NAME_DIR "#rpath")
CMake Log
Log is so big that cannot be pasted here. See it here: https://pastebin.com/Mk4NrQgX
UPDATE
So I checked out and there is this strange thing happening. When I list with ls, I can see library exists:
ls /usr/lib/|grep libz
libz.1.1.3.dylib
libz.1.2.11.dylib
libz.1.2.5.dylib
But when I try for example to examine the library with otool
otool -L /usr/lib/libz.dylib
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: error: '/usr/lib/libz.dylib': No such file or directory
I guess the problem lies here, though am yet to crack the code
UPDATE 2
So ran ls -la /usr/lib | grep libz and as you can see it's all linking back to libz.1.dylib but that file does not exist.
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.1.3.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.2.11.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.2.5.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.2.8.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.dylib -> libz.1.dylib

We have a big epic tracker in here for MacOS 10.16/11.0 compatibility check.
https://github.com/Homebrew/brew/issues/7857
Feel free to escalate the issue in there (I actually saw the zlib marked as 🥇)

It seems some libraries in /usr/lib/are pure garbage. I can confirm zliband libiconvare corrupt, linked to non existing library. No much complain since it is a beta version. So the solution was to install brew version with brew install zlib and then overwrite terminal's current system path with
export PATH=/usr/local/opt/zlib/lib:/usr/local/opt/zlib/include:$PATH

Related

Upgrade ffmpeg (or rust) on OSX 10.12 cannot find make

Trying to brew upgrade ffmpeg on OSX 10.12 Sierra but when it arrived to install rust I had the following error:
make: error: unable to find utility "make", not a developer tool or in PATH
xcodebuild: error: SDK "/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk" cannot be located.
clang: error: unable to find utility "clang", not a developer tool or in PATH
But which make gives /usr/bin/make and xcrun make is recognized and
ls -l /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk gives
lrwxr-xr-x 1 root wheel 10 Dec 21 2017 /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk -> MacOSX.sdk
How can I force the rust install to use /usr/bin/make instead of the XTools one? Or something else.
EDIT
I have rustc 1.46.0 which is the dependency that Homebrew wants ./configure --prefix=/usr/local/Cellar/rust/1.46.0 --release-channel=stable
Edit the Homebrew formulae
brew edit rust
and comment the line
ENV["SDKROOT"] = MacOS.sdk_path
then Rust can be installed (it's quite long).

conflicting types for '__readlink' during make glibc 2.14

I made a softwareupdate on a simulationsoftware which needs a newer version of glibc. Therefore I wanted to install the glibc version 2.14 on a new prefix.
According to How to upgrade glibc from version 2.12 to 2.14 on CentOS?
i tried to install it on a sles11sp3
mkdir /var/mpi/Libraries/glibc_install; cd /var/mpi/Libraries/glibc_install
wget http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz
tar zxvf glibc-2.14.tar.gz
cd glibc-2.14
mkdir build
cd build
../configure --prefix=/var/mpi/Libraries/glibc-2.14
make -j4
During the make I get the following error:
readlink.c:26: error: conflicting types for ‘__readlink’
../include/unistd.h:120: error: previous declaration of ‘__readlink’ was here
make[2]: *** [/var/mpi/Libraries/glibc_install/glibc-2.14/build/io/readlink.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory `/var/mpi/Libraries/glibc_install/glibc-2.14/io'
make[1]: *** [io/subdir_lib] Error 2
make[1]: Leaving directory `/var/mpi/Libraries/glibc_install/glibc-2.14'
make: *** [all] Error 2
Do you have a clue how to solve this problem?
io/readlink.c is just a stub implementation which always fails at run time. It is not supposed to be compiled at all when building for GNU/Linux. Instead, the implementation should come from the generic system call wrapper in sysdeps/unix/syscalls.list:
readlink - readlink i:spi __readlink readlink
However, recent Linux architectures (those called generic in Linux parlance, currently aarch64, csky, nios2, and riscv) no longer have a readlink system call, and the function as to be implemented using readlinkat. This implementation is in the file sysdeps/unix/sysv/linux/generic/readlink.c.
It's not clear what you are doing so that the wrong file is compiled. Are you sure you have installed compatible kernel headers?
The particular upstream commit (which went into glibc 2.15):
commit 95b7042bac3e2cfc6fef7aec6acc7d46dd50eba5
Author: Roland McGrath <roland#hack.frob.com>
Date: Fri Nov 11 10:02:42 2011 -0800
Fix __readlink declaration.
But given the fundamental nature of the build problem you encountered, I doubt that applying this patch, while addressing the immediate build failure, will give you a functional glibc build in the end.
GLIBC : 2.14 → 2011-06-01. The "bugfix version" 2.14.1 → 2011-10-07 https://ftp.gnu.org/gnu/glibc/
Note : make -j4 is not recommended for glibc, as far as I remember.
My tests (old SLE11 SP2) : The SLE 11 SP2 gcc 4.3.2 is too old for glibc-2.14.1, may be the SP3 minor gcc update (to 4.3.4) is also too old?
Using the "extra EL 6 gcc-4.9.3" .... for glibc-2.14.1 :
cd build-glibc214/ # the recommended build directory outside the glibc source
export CC=gcc49 CXX=g++49 && ../glibc-2.14.1/configure --prefix=/opt/glibc214
make # no errors
# make install # OK
Extra gcc´s : how to install gcc 4.9.2 on RHEL 7.4

c++11 std::unique_ptr error cmake 3.11.3 bootstrap

I am trying to bootstrap cmake 3.11.3 on Ubuntu 16.04.4 LTS xenial.
I have upgrade my gnu g++ compiler as follows:
> $ g++ --version
g++ (Ubuntu 8.1.0-5ubuntu1~16.04) 8.1.0 Copyright (C) 2018 Free
Software Foundation, Inc. This is free software; see the source for
copying conditions. There is NO warranty; not even for MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
And manually re-pointed the symbolic links:
$ ll /usr/bin/*g++*
lrwxrwxrwx 1 root root 5 Jun 8 16:57 /usr/bin/g++ -> g++-8*
-rwxr-xr-x 1 root root 919832 Apr 24 15:02 /usr/bin/g++-5*
lrwxrwxrwx 1 root root 22 Jun 6 04:26 /usr/bin/g++-8 -> x86_64-linux-gnu-g++-8*
lrwxrwxrwx 1 root root 22 Jun 8 16:58 /usr/bin/x86_64-linux-gnu-g++ -> x86_64-linux-gnu-g++-8*
lrwxrwxrwx 1 root root 5 Apr 24 15:02 /usr/bin/x86_64-linux-gnu-g++-5 -> g++-5*
-rwxr-xr-x 1 root root 1071984 Jun 6 04:26 /usr/bin/x86_64-linux-gnu-g++-8*
However, I get the following error in the configuration of cmake:
$ sudo ./bootstrap
---------------------------------------------
CMake 3.11.3, Copyright 2000-2018 Kitware, Inc. and Contributors
Found GNU toolchain
C compiler on this system is: gcc
C++ compiler on this system is: g++
Makefile processor on this system is: make
g++ has setenv
g++ has unsetenv
g++ does not have environ in stdlib.h
g++ has stl wstring
g++ has <ext/stdio_filebuf.h>
---------------------------------------------
make: Warning: File 'Makefile' has modification time 2.3 s in the future
make: 'cmake' is up to date.
make: warning: Clock skew detected. Your build may be incomplete.
loading initial cache file /mnt/ganymede/user/gpeytavi/srv_admin/software/cmake-3.11.3/Bootstrap.cmk/InitialCacheFlags.cmake
CMake Error at CMakeLists.txt:92 (message):
The C++ compiler does not support C++11 (e.g. std::unique_ptr).
-- Configuring incomplete, errors occurred!
See also "/mnt/ganymede/user/gpeytavi/srv_admin/software/cmake-3.11.3/CMakeFiles/CMakeOutput.log".
See also "/mnt/ganymede/user/gpeytavi/srv_admin/software/cmake-3.11.3/CMakeFiles/CMakeError.log".
---------------------------------------------
Error when bootstrapping CMake:
Problem while running initial CMake
---------------------------------------------
Any idea why I get a c++11 std::unique_ptr non-compliant error?
In my case, the issue is because of the folder where I have CMake source code is in a mounted directory (in fact my entire rootfs is mounted over NFS)
So, I looked in 'mount' command output and selected '/run/user/1000' location as a local location as this is mounted using tmpfs and moved my CMake source code to this location.
with this, ./bootstrap && make && sudo make install executed successfully.
Actually the ./bootstrap script does try the different C++ standard flags with the compiler. So it should detect its capabilities automatically.
Please make sure you don't have any CXXFLAGS environment variable set and try from scratch again (the messages/warnings you get indicate several tries/errors in the same directory).
Output when Successful
As a reference on my Ubuntu calling CMake's ./bootstrap looks like this:
---------------------------------------------
CMake 3.11.20180423, Copyright 2000-2018 Kitware, Inc. and Contributors
Warning: This is an in-source build
Found GNU toolchain
C compiler on this system is: gcc
C++ compiler on this system is: g++ -std=gnu++1y
Makefile processor on this system is: make
g++ has setenv
g++ has unsetenv
g++ does not have environ in stdlib.h
g++ has stl wstring
g++ has <ext/stdio_filebuf.h>
---------------------------------------------
Debugging
For debugging your problem you also could:
Call ./bootstrap --verbose
Look into Bootstrap.cmk/cmake_bootstrap.log
Known Problem
I only once had a problem with bootstrap using clang compilers where I needed to do the following call:
export CXXFLAGS=-Xclang -std=c++1z -Xclang -stdlib=libc++
Alternative
If you just want to install the latest version see How to specify where CMake is installed in Ubuntu?
I was able to resolve the issue by ensuring that both the build machine and the NFS file server were synchronized by running ntpd on both.
For me it was clock skew. I use the below command :
date -s "2021-11-30 15:08:21"
to set the time to now for the server. Then it work, thanks...

How can I create static executables on OS X with Stack?

I would like to create a static executable for Darwin for a small utility I wrote called difftodo. difftodo depends indirectly on pcre, and I would like people to be able to download a binary and run it without having to brew install pcre first.
If I compile without options, I get a binary that dynamically links pcre:
$ otool -L /Users/jml/src/difftodo/.stack-work/install/x86_64-osx/lts-7.1/8.0.1/bin/git-todo
/Users/jml/src/difftodo/.stack-work/install/x86_64-osx/lts-7.1/8.0.1/bin/git-todo:
/usr/local/opt/pcre/lib/libpcre.1.dylib (compatibility version 4.0.0, current version 4.7.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
Following instructions at https://github.com/commercialhaskell/stack/issues/1032, I tried the following:
$ stack build --ghc-options -static --ghc-options -optl-static
difftodo-0.2.0: configure
Configuring difftodo-0.2.0...
difftodo-0.2.0: build
Preprocessing library difftodo-0.2.0...
ld: illegal text reloc in '_c1TGM_info' to '_stg_sel_1_upd_info' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
-- While building package difftodo-0.2.0 using:
/Users/jml/.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.24.0.0-ghc-8.0.1 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.0.0 build lib:difftodo exe:all-todos exe:diff-todo exe:git-todo --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
I don't understand this failure at all.
Creating static Mac OS X C build implies that creating fully static binary on OS X is impossible and undesirable. However, I am content to have dynamic links to libSystem etc., just not to the third-party libraries I am depending on.
Note that I have a static version of pcre available:
$ ls -la /usr/local/opt/pcre/lib/
total 2700
drwxr-xr-x 18 jml admin 612 Oct 1 11:02 .
drwxr-xr-x 13 jml admin 442 Oct 1 11:02 ..
-r--r--r-- 1 jml admin 443872 Oct 1 11:02 libpcre.1.dylib
-r--r--r-- 1 jml admin 492016 Oct 1 11:02 libpcre.a
...
http://gelisam.blogspot.co.uk/2014/12/how-to-package-up-binaries-for.html describes a method for working around this problem: edit the link tables in the executable and ship it together with the libraries. I would much rather have a single executable.

Setting GCC 4.2 as the default compiler on Mac OS X Leopard

I'm sure there must be a way to do this. As you are probably aware the latest versions of Xcode (and in fact I think all versions of Xcode) on Leopard come with GCC 4.0.1 and GCC 4.2. GCC 4.0.1 is the default system compiler while GCC 4.2 is an optional compiler you can set in the Xcode project settings.
Does anyone know how to set GCC 4.2 as the default compiler for all options? Preferably command line use as well as configure scripts still use GCC 4.0.1 rather than GCC 4.2 no matter what I do in Xcode. I'm assuming it is simply a case of changing a path variable or some such but I am stumped on this one.
Any help is appreciated. Thanks.
Command line usage for all configure scripts:
cd /usr/bin
rm cc gcc c++ g++
ln -s gcc-4.2 cc
ln -s gcc-4.2 gcc
ln -s c++-4.2 c++
ln -s g++-4.2 g++
Make a record of the current link targets, so you can restore them if you want to.
If you don't want to change the system wide settings, add a directory into PATH before /usr/bin (say, $HOME/bin), and make the symlinks there
I haven't tested whether this affects Xcode projects, since I don't use Xcode (only command line).
In the Project or Target Info Window set the build setting "C/C++ compiler version" (GCC_VERSION).
Or in the Target Info Window you can change the "System C rule" to your favorite GCC version.
Update: Regarding the command line I would leave to Leopard the decision of what should be the default compiler. If you want to use a different compiler with tools like Autotools configure you had better to define the CC variable.
CC=gcc-4.2 ./configure
or
export CC=gcc-4.2
Since neither Apple nor Darwin Ports have the gcc_select program to change the default version of the System compiler (as exists on GNU/Linux), I would like to be on the safe side with XCode (and the rest of the system) and would recommend to leave the symbolic links as they are and instead setup environment variables that overrides which version of GCC to use.
In my .profile file I have the following
export CC=/usr/bin/gcc-4.2
export CPP=/usr/bin/cpp-4.2
export CXX=/usr/bin/g++-4.2
And I successfully compiled the following libraries with GCC 4.2 from source.
OpenSSL
libjpeg
libpng
zlib
gst
However... I could not get Boost 1.39 to acknowledge the environment variables, so to compile Boost with GCC 4.2 I needed to change the symbolic links in /usr/bin/ so they pointed to gcc v4.2
After the long while the Boost libraries were finished compiling with GCC 4.2 I restored the symbolic links back to the original System version gcc-4.0.
Im my experience (limited), changing CC in .profile does not change Lion's (10.7.2) defaulting to i686-apple-darwin11-llvm-gcc-4.2. I wonder if this has anything to do with Apple's own sym linking:
a partial: ls -la /usr/bin | grep .*gcc.* :
lrwxr-xr-x 1 root wheel 12 25 oct 19:31 cc -> llvm-gcc-4.2
lrwxr-xr-x 1 root wheel 12 25 oct 19:31 gcc -> llvm-gcc-4.2
lrwxr-xr-x 1 root admin 32 25 oct 19:31 llvm-gcc-4.2 -> ../llvm-gcc-4.2/bin/llvm-gcc-4.2
I am wary about breaking these and adding my own to usr/bin/gcc-4.2 per Martin v. Löwis's answer.
Since I need to build things where CC env is ignored and I end up switching often, I wrote a simple minded gcc_select in Python. Thought I may as well post it here. Invoke it with arg either 4.0 or 4.2 or no arg to see current symlinks. Would need modification if you have versions other than 4.0 and 4.2:
#!/usr/bin/python
import sys
import os
os.chdir('/usr/bin')
files = ['cc', 'gcc', 'c++', 'g++']
if '4.0' in sys.argv:
ver = '4.0'
elif '4.2' in sys.argv:
ver = '4.2'
else:
print "Unknown gcc version. Current setting:"
os.system('ls -al %s' % ' '.join(files))
sys.exit(1)
os.system('rm %s' % ' '.join(files))
for f in files:
os.system('ln -s %s-%s %s' % (f, ver, f))
print "Changed to gcc version %s" % ver
I might be wrong, but I thought that was what Xcode-select was for?
xcode-select --switch /path_to_tool_suite
As I said, I'm not 100% on this, but I believe it will set the default for all programs including Terminal and other apps that calls into the OS to use a compiler.

Resources