/usr/lib/libstdc++.6.dylib: mach-o, but wrong architecture - macos

I've just update my MAC OS Mountain Lion's compiler to gcc 4.8.1, the configure & install process is:
./configure --prefix=/usr
make
sudo make install
the GCC 4.8.1 was installed completely, but then I found I cannot open my Chrome, as well as several other programs. I've check the error report, the most important information is:
Dyld Error Message:
Library not loaded: /usr/lib/libstdc++.6.dylib
Referenced from: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Reason: no suitable image found. Did find:
/usr/lib/libstdc++.6.dylib: mach-o, but wrong architecture
/usr/lib/libstdc++.6.dylib: mach-o, but wrong architecture
So what should I do to solve this? Recompile GCC with proper architecture? But how to do this?

You have overwritten several system libraries with incompatible versions. You will need to reinstall Mac OS X.
Don't install software with --prefix=/usr. That prefix is reserved for software distributed with the operating system. Use /usr/local for software you install yourself. You may want to try Homebrew instead once you've reinstalled.

Since libstdc is deprecated and removed in iOS12, you need to update your dependencies to use libc++ or manually add libstdc. For manually adding refer this - answer

Related

How to build an application for both architectures depending on some external library OR to install library for both architectures?

I have a Mac which architecture is:
$ arch
arm64
(it supports x86_64 and aarch64).
And I have installed openssl library with brew tool. Now I try to build my application for x86_64 platform (it's Haskell application and the build script is large and complex, so I cannot show it here) and I get an error:
...
<command line>: dlopen(/MyWork/.stack/snapshots/x86_64-osx/b1d675598b9b6c5f516e03f82c45d01becd6003e6128005b2b4acb8628b0f350/9.2.5/lib/x86_64-osx-ghc-9.2.5/libHSHsOpenSSL-0.11.7.2-1JX1qBi8YfpGDjk1ra3OXq-ghc9.2.5.dylib, 0x0005): symbol not found in flat namespace '_DSA_free'
...
However, it works fine for aarch64 platform. After little research I see that my OpenSSL libraries are:
$ file /opt/homebrew/opt/openssl#3/3.0.7/lib/libssl.3.dylib
/opt/homebrew/opt/openssl#3/3.0.7/lib/libssl.3.dylib: Mach-O 64-bit dynamically linked shared library arm64
which seems that it is a library for arm64 and not x86_64, so maybe this is the reason of the error "symbol not found in flat namespace '_DSA_free'".
How to fix it? I guess I need to install the second openssl - for x86_64, I tried arch -x86_64 brew install openssl but I get:
Warning: openssl#3 3.0.7 is already installed and up-to-date.
To reinstall 3.0.7, run:
brew reinstall openssl#3
which makes sense - it is installed already (but for arm64).
How to fix/workaround this problem, so to be able to build the application for both platform while it depends on external libraries like openssl? Maybe there is a way to install openssl for both platform?
EDIT:
Currently I found 2 solutions:
to install libraries from sources setting prefix=/unique/folder/for/arch and to prefix ./configure ..., make, make install by arch -ARCH (where ARCH is x86_64 or arm64).
Another way is to have 2nd Homebrew, it's described here

dyld: Library not loaded, Reason: image not found

I used gdb normally until this week. Now running gdb I see:
(gdb) r
Starting program: /Volumes/MyProg
dyld: Library not loaded: #rpath/libCore.so
Referenced from: /Volumes/MyProg
Reason: image not found
(gdb)
How to fix it?
I have:
OSX 10.9
GNU gdb (GDB) 7.6 installed with MacPorts
P.S.
I have reinstalled gdb and Xcode. This does not help.
I see a lot of questions about dyld issues, but obviously I lack experience with libraries on OSX, and they appears to be useless for me.
For example this topic: dyld issues library not loaded
But how to download library again?
Or this topic: Dyld: Library not loaded
But how to find out install name? What is #rpath?
I solved this issue with "Embedded Binaries" in the General project settings.
i have solved this issue by changing the following settings
Go to Project Setting Your_Target->General->Embedded Binaries-> Click on + button and add your library here
How I fixed it:
libCore.so is a library from ROOT framework, which MyProg uses.
If I understand correctly, the message Library not loaded: #rpath/libCore.so Referenced from: /Volumes/MyProg Reason: image not found means that linker found the library, but can't use it.
Root, during installation uses clang by default. Meanwhile as I prefer gcc and MyProg uses gcc.
I have reinstalled root with gcc compiler:
./configure --with-cxx=g++ --with-cc=gcc --with-ld=g++
I have recompiled MyProg.
and now I can debug it with gdb.
You can find more information about rpath here: link
So you need to point the path to your libCore.so, but honestly I have not faced with this library so I don't know where is it located.
You can check also this answer to understand what it is rpath: answer
For Xcode 11 or above, there is another simpler solution which worked for me if you are using Cocoapods.
In your Podfile, add use_frameworks! after your Target line like this -
target 'YourAppName' do
use_frameworks!
Basically it adds all your pods as a framework in your framework folder.

Library not loaded: /usr/lib/libxslt.1.dylib error loading library after installing with CPAN

I was attempting to install XML::LibXSLT via CPAN, this seemed to work fine, until I attempted to load Google Chrome, or Microsoft Office. I am getting an error launching these programs with the following errors:
Dyld Error Message:
Library not loaded: /usr/lib/libxslt.1.dylib
Referenced from: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks
/DictionaryServices.framework/Versions/A/DictionaryServices
Reason: no suitable image found. Did find:
/usr/lib/libxslt.1.dylib: mach-o, but wrong architecture
/usr/lib/libxslt.1.dylib: mach-o, but wrong architecture
Obviously the problem is the new dylibs that XSLT installed, but these all seem to be X86_64 so I shouldn't be seeing any issues with this, I am running Mac OS X 10.6.8.
When running file /opt/local/lib/libxslt.dylib
I get:
/opt/local/lib/libxslt.dylib: Mach-O 64-bit dynamically linked shared library x86_64
as is the same with the libxslt.1.dylib.
Is there a way to solve this issue, and reinstate the original files that must have been replaced?
Edit: If were to get a copy of these Libraries from another Mac 10.6.8 64 bit and replace my apparantly confused ones with these, would this at least solve the issue of them being all mixed up.
Also running
[/usr/lib]$ ls | grep libxslt gives me :
libxslt 2.dylib
libxslt-plugins
libxslt.1.dylib
libxslt.a
libxslt.dylib
libxslt.la
libxslt.pc
Did you install into or otherwise replace the original Apple-supplied libraries in /usr/lib? You should never do that. Otherwise, you'll likely break other parts of OS X that depend on those libraries. You should restore the original libraries from a backup or reinstall OS X. If you want newer versions, you should install them elsewhere, like in /usr/local/lib. Or better yet you should be using a third-party package manager, like Homebrew or MacPorts; in fact, you appear to be using MacPorts, judging from the /opt/local/lib path. Use that and don't alter system files in /usr (other than /usr/local) or /System/Library.
This may be relevant: How to compile universal binaries on Mac OS X.
I ran into this same issue where I had re-compiled libxslt and libxml to support python bindings, then started getting the /usr/lib/libxslt.1.dylib: mach-o, but wrong architecture error and an immediate crash when starting some apps (Specifically Synergy, which is a 32-bit/i386 app)
I solved this by recompiling libxml2 and libxslt using these configure options:
./configure CFLAGS="-arch i386 -arch x86_64" \
CXXFLAGS="-arch i386 -arch x86_64" \
LDFLAGS="-arch i386 -arch x86_64" \
--disable-dependency-tracking
Now libxml2 and libxslt libraries are properly showing as universal binaries:
$ file /usr/local/lib/libxslt.1.dylib /usr/local/lib/libxslt.1.dylib: Mach-O universal binary with 2 architectures
/usr/local/lib/libxslt.1.dylib (for architecture i386): Mach-O dynamically linked shared library i386
/usr/local/lib/libxslt.1.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
$ file /usr/local/lib/libxml2.2.dylib
/usr/local/lib/libxml2.2.dylib: Mach-O universal binary with 2 architectures
/usr/local/lib/libxml2.2.dylib (for architecture i386): Mach-O dynamically linked shared library i386
/usr/local/lib/libxml2.2.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64

How can I update clang to 3.3 on Mac OS X 10.6

I'm running Mac OS X 10.6 and want to install TextMate 2, which is for Mac OS X 10.7+.
But all what it needs is a newer version of clang (LLVM), which is included in Lion and Mountain Lion. I read before here I can do that with MacPorts. So I used port install clang and MacPorts updated to clang-2.9, then clang-3.2 and finally clang-3.3. I thought, its updated now and I checked the version: clang --version. And it's not updated:
Apple clang version 2.0 (tags/Apple/clang-139) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix
So I copied the new clang file in this path (/opt/local/libexec/llvm-3.3/bin) to/usr/bin`. But now there's a fail :( :
dyld: Library not loaded: #executable_path/../lib/libLLVM-3.3svn.dylib
Referenced from: /usr/bin/clang
Reason: image not found Trace/BPT trap
The libLLVM-3.3svn.dylib is at /opt/local/libexec/llvm-3.3/lib. What can I do now, that
it runs clang-3.3? Sorry for my not perfect english ;) Thank you!
If you run clang from /usr/bin, it will be looking for the LLVM library in /usr/bin/../lib/libLLVM-3.3svn.dylib, i.e., /usr/lib/libLLVM-3.3svn.dylib (at least that's what the dynamic loader is telling you). You could try to copy the lib file into /usr/lib.
Alternatively, you can just download a more recent official build of Clang here:
http://llvm.org/releases/download.html
As far as I know, these builds are self-contained and do not need any dynamic libraries. However, it could be necessary to copy Apple's ARC libraries into a certain directory. If you run into trouble, please ask again.
Another approach is to build Clang and LLVM from source. You can find the repository URLs and instructions here:
http://clang.llvm.org/get_started.html
This should also build Clang with the LLVM libraries statically linked.
3.3, by the way, has not been officially released, so I would recommend using 3.2 unless you need any specific new features.

Linking Boost Filesystem in XCode 3.2 (MacPorts)

I am using XCode 3.2 and have installed boost using the MacPorts project (both release and debug) however I am at a loss to get my application to link with boost::filesystem
I have set my library search path to /opt/local/lib but I still get unresolved references when linking the project.
I noticed in another post to add -lboost_system to the "other linker flags" but when I do this I get - libboost_system.dylib, file was built for unsupported file format which is not the architecture being linked (i386).
Is MacPorts not installing the right libraries or am I missing something else?
Martin
You didn't indicate what OS version you are build it with. My guess is MacPort defaults to x64 when building and installing ports. Uninstall boost from MacPort then re-install it with universal variant.
%% sudo port uninstall boost
%% sudo port install boost +universal
It is possible that the name of the library is not exactly boost_system but maybe boost_system-mt (the -mt is because boost was compiled with thread safety) or even some other suffix.
To be sure, you can look up the name in /opt/local/lib:
find /opt/local/lib -name "libboost_system*"

Resources