ld can't find X11 library on OSX Leopard - macos

I have a pretty basic X11 app that I run on Linux that I'm trying to get compiled under OSX 10.5.8. I have X11 and the X11 SDK installed, and modified the makefile as follows:
CFLAGS = -L/usr/X11/lib -I/usr/X11/include
Everything compiles fine, but the linker can't find the X11 lib.
ld: library not found for -lX11
I've looked on google, but the only other people I've found with this problem so far either didn't have the X11 SDK installed or didn't know about the -L flag.
Any ideas?

gcc SimpleXlibApp.c -o SimpleXlibApp -lX11 -L/usr/X11/lib -I/usr/X11/include
That line compiles the example here: http://en.wikipedia.org/wiki/Xlib

You may be looking in the wrong location for the library; it's certainly in a different location on my OS X box. Try typing:
locate libX11.dylib
and adding an appropriate path. E.g. on my system you'd need -L/usr/X11/lib/ in you CFLAGS.

-L/usr/X11/lib doesn't work with OSX 10.6 and it has libX11.dylib :
% ls -l /usr/X11/lib/libX11.*
lrwxr-xr-x 1 root wheel 14 Jul 21 17:46 /usr/X11/lib/libX11.6.2.0.dylib# -> libX11.6.dylib
-rwxr-xr-x 1 root wheel 3578368 Jul 12 2010 /usr/X11/lib/libX11.6.dylib*
lrwxr-xr-x 1 root wheel 14 Jul 21 17:46 /usr/X11/lib/libX11.dylib# -> libX11.6.dylib

Related

Mac OS 10.16 Linking Homebrew installed libraries

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

Ubuntu 18.04: No CMAKE_C_COMPILER could be found

I am trying to install gtest from Google but even though I have gcc and g++ installed, I get this error for some reason. I am on Ubuntu 18.04 64 bit. And I don't have anything to do with Visual Studio stuff.
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:47 (project):
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/usr/src/googletest/googletest/CMakeFiles/CMakeOutput.log".
See also "/usr/src/googletest/googletest/CMakeFiles/CMakeError.log".
This is there:
$ gcc --version
gcc (GCC) 6.4.0
$ g++ --version
g++ (GCC) 6.4.0
and this:
user#user:/usr/src/gtest$ whereis g++
g++: /usr/bin/g++ /usr/share/man/man1/g++.1.gz
user#user:/usr/src/gtest$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/local/cuda-9.0/bin/gcc /usr/share/man/man1/gcc.1.gz
also:
user#user:/usr/src/gtest$ ls -la /usr/bin | grep gcc-6.4
lrwxrwxrwx 1 root root 16 Nov 12 14:47 gcc -> /usr/bin/gcc-6.4
user#user:/usr/src/gtest$ ls -la /usr/bin | grep g++-6
lrwxrwxrwx 1 root root 14 Nov 12 14:51 g++ -> /usr/bin/g++-6
lrwxrwxrwx 1 root root 22 Apr 24 2018 g++-6 -> x86_64-linux-gnu-g++-6
-rwxr-xr-x 1 root root 953176 Apr 24 2018 x86_64-linux-gnu-g++-6
Given all this, does anyone have a clue?
Thanks in advance.
UPDATE: This seems to have worked:
Okay, this seems to be working:
cmake -D CMAKE_C_COMPILER="/usr/local/cuda-9.0/bin/gcc " -D CMAKE_CXX_COMPILER="/usr/bin/g++" /usr/src/gtest/CMakeLists.txt
which apparently points to the gcc used cuda. Is there a way of setting the one under /usr/bin/ as the default one?

dtruss on OSX 10.9 Mavericks

I'm running OSX Mavericks. As I heard(WWDC 2013, 402-HD.mov) the clang compiler resides now here: -rwxr-xr-x 1 root wheel 29381728 Oct 23 08:40 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
In /usr/bin there's only a wrapper for clang(we can see that from the size):
-rwxr-xr-x 1 root wheel 14224 Oct 22 21:25 /usr/bin/clang
I want to compile one simple C file with clang.
"clang main.c", and I get the a.out (0 errors, 0 warnings). All OK.
Now (the problem) I want to run dtruss on that command line: "sudo dtruss -f clang main.c" but I don't get an a.out. Why? (-f follow children as they are forked). I would have expected that the wrapper does a fork and an exec to the real compiler, but it seems it's not if I run it with dtruss.

lib path on mac osx

I did install the libnfc 1.5.1 in the default directory (/usr/loca/
lib).
if i do an ls i see the libs there:
foo:libnfc-1.5.1 bar$ ls -l /usr/local/lib/libnfc*
-rwxr-xr-x 1 root wheel 62092 Nov 23 09:05 /usr/local/lib/libnfc.2.dylib
-rw-r--r-- 1 root wheel 226696 Nov 23 09:05 /usr/local/lib/libnfc.a
lrwxr-xr-x 1 root wheel 14 Nov 23 09:05 /usr/local/lib/libnfc.dylib ->libnfc.2.dylib
-rwxr-xr-x 1 root wheel 930 Nov 23 09:05 /usr/local/lib/libnfc.la
foo:libnfc-1.5.1 bar$
I did try to run the configure script from mfoc with the following command:
LDFLAGS="-L/usr/local/lib" ./configure
it says that I don't have libnfc >= 1.5.1
checking for LIBNFC... no
configure: error: libnfc >= 1.5.1 is mandatory.
any idea?
This is a guess, but the error looks like it comes from pkg-config. Try:
$ ./configure LDFLAGS=-L/usr/local/lib PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
You really need to look in config.log to see exactly why it cannot find the library.
EDIT: It has often been claimed that pkg-config is fundamentally broken. This case has finally persuaded me that that is indeed true. Setting LDFLAGS should be sufficient, and the fact that it isn't renders this configure script broken. With that in mind, it might be better to disable pkg-config by running configure with the argument PKG_CONFIG=:
Try setting DYLD_LIBRARY_PATH variable and point it to /usr/local/lib before running ./configure:
$ export DYLD_LIBRARY_PATH=/usr/local/lib
$ ./configure

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