GCC m32 option on Apple M1 Chip - gcc

Is there any way to run gcc with the following flags on an apple M1 chip?
gcc -m32 -o test test.c
It outputs the following error:
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)

You may not run 32-bit applications on macos Catalina or newer. The oldest version of macOS supported on any Apple Silicon (M1/M2) systems is Big Sur, which is the release after Catalina.
So use of -m32 on gcc or any other compiler on macOS is a not supported. Well, I suppose you could use a cross compiler to target a different operating system than the machine you are running the compiler.
Fix:
Remove -m32 and fix any issues with the code.

you can try using an IDE like Xcode or CLion as a workaround while they update GCC.

Related

ld linking problem on Mac M1 arm64 architecture, using GNU11 compilers gcc, gfortran

I'm building a set of libraries on Mac M1 (arm64 architecture), Big Sur and use GNU11 compilers (gcc, gfortran, g++), as well as openmpi 4.1.2 for multi-processing. All is done as a command-line using a Terminal.app, which is running as Apple native, and NOT using Rosetta Translation. The steps taken: 1) GCC, g++, gfortran are installed using "brew install gcc#11", then symbolic links created in /opt/homebrew/bin/ for gcc -> gcc-11, g++ -> g++-11 ; 2) openmpi 4.1.2 installed, with mpicc based on gcc, mpixx based on g++, and mpifort/mpif90 based on gfortran; 3) command-line tools installed as "xcode-select --install".
Getting the problem with finally linking of the libraries:
...
/Users/Natalie/openmpi/bin/mpifort -L/opt/homebrew/opt/openssl#3/lib -fallow-argument-mismatch -fallow-invalid-boz -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -mmacosx-version-min=11.6 CMakeFiles/cmTC_9a888.dir/testFortranCompiler.f.o -o cmTC_9a888
Undefined symbols for architecture arm64:
"_sgemm_", referenced from:
_MAIN__ in testFortranCompiler.f.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make[1]: *** [cmTC_9a888] Error 1
make: *** [cmTC_9a888/fast] Error 2 ```

Creating a universal binary using Intel compiler

In MacOSX, gcc command line accepts multiarchitecture options:
gcc -arch i386 -arch x86_64 etc.
... and creates a universal binary by compiling and linking for both archs and running lipo for gluing them together.
However using this command line with Intel, produces a compiler warning:
command line warning #10121: overriding '-arch i386' with '-arch x86_64'
Am I doing something wrong or is this a compiler limitation?
I couldn't find anything about it in the Intel developer zone.

Unable to run gcc on mac

I am trying to compile simple C code on my system. I am running gcc version (4.9.2) on macOS 10.11.6.
ld: library not found for -lgcc
collect2: error: ld returned 1 exit status
I am unable to fix this issue. This problem is not letting me install any ./configure packages as well since they require gcc to work.
Even if there is a program called gcc under macOS, it is not a real gcc compiler. It is just a Clang compiler, as you can prove easily:
gcc --version
will print:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
You should be able to compile and link your program by omitting the -lgcc flag from the command line.

compile opencv with cuda for MAC

I am trying to compile opencv 2.4.5 with CUDA support in Mac OS X. I am using the cmake gui 2.8.10 with Qt 4.8
After a
clang: error: unsupported option '-dumpspecs'
in the make i have set the entry CUDA_HOST_COMPILER to /usr/bin/llvm-g++ . But now I receive this error:
[ 16%] Built target IlmImf
[ 16%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_matrix_operations.cu.o
cc1plus: warning: command line option "-Wmissing-declarations" is valid for C/ObjC but not for C++
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus: error: unrecognized command line option "-Wno-narrowing"
cc1plus: error: unrecognized command line option "-Wno-delete-non-virtual-dtor"
cc1plus: error: unrecognized command line option "-Wno-unnamed-type-template-args"
What can i do now?
SYSTEM SETTINGS
OS X 10.8.3 (12D78)
and
>>> clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
and
>>> g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
>>> ls -al /usr/bin/g++
/usr/bin/g++ -> llvm-g++-4.2
and
>>> cc --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
>>> ls -al /usr/bin/cc
/usr/bin/cc -> clang
Use GCC and G++ to compile. I've used CMake 2.8.11 on OSX Mountain Lion with latest Xcode compilers:
g++ --version returns i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Change the CUDA_HOST_COMPILER from /usr/bin/cc to /usr/bin/gcc
You have to compile the CUDA components using GCC 4.5, while compiling the rest of OpenCV with Clang, otherwise you cannot get the HighGui module to work. HighGui will only compile with the Apple installed compilers because it uses Cocoa. If you do not need HighGui, you can compile OpenCV with GCC. You can specify the proper compilers quite easily with cmake.
I found that the easiest way was to use Homebrew to install cmake and gcc.
I wrote up a detailed gist of how to make it work here that also includes enabling Python support using the Homebrew version.
Disable warning flags in cmake/OpenCVCompilerOptions. Find corresponding warnings and uncomment them using '#'

Problems installing Haskell library regex-pcre on Mac OS X

I'm trying to install the Haskell regex-pcre library using:
cabal install --extra-include-dirs=/usr/local/include \
--extra-include-dirs=/usr/include regex-pcre
However I get this weird error:
Resolving dependencies...
Configuring regex-pcre-0.94.2...
Preprocessing library regex-pcre-0.94.2...
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/HsFFI.h:68,
from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:4,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/float.h:8:24: error: float.h: No such file or directory
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:9,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
compiling dist/build/Text/Regex/PCRE/Wrap_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/build/Text/Regex/PCRE/Wrap_hsc_make.c -o dist/build/Text/Regex/PCRE/Wrap_hsc_make.o -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -D__GLASGOW_HASKELL__=700 -Ddarwin_BUILD_OS -Ddarwin_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -I/usr/include -I/usr/local/include -DHAVE_PCRE_H -DSPLIT_BASE=1 -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/bytestring-0.9.1.10/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/base-4.3.1.0/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/
cabal: Error: some packages failed to install:
regex-pcre-0.94.2 failed during the building phase. The exception was:
ExitFailure 1
The gist of it, seems to be that it can't find a second float.h file:
/usr/include/float.h:8:24: error: float.h: No such file or directory
I've opened /usr/include/float.h and line 8 reads:
#include_next <float.h>
I've done my searching on Google, and although I don't know that much C I think I understand what that line is supposed to say, but... I don't know how to really solve this problem. I don't know where else I have a float.h file on my system.
The GHC and GCC versions I'm using. GCC comes from XCode 4. GHC is 32bit, but I've tried the 64bit version too, with the same results.
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.2
OS X version is 10.6.7.
Any help greatly appreciated.
Looks to me like ticket #5011 - XCode 4 on Mac + GHC 7.0.2 fails to link.
This is fixed in GHC 7.0.3 which will be part of the mid-April release of the Haskell Platform.
And alternative fix is to downgrade to the 2010.2 Haskell Platform.
See this question yesterday: Can't install OpenGLRaw-1.1.0.1 on OS X

Resources