Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i build source on Apple M1? #3071

Closed
huwei1024 opened this issue Jan 18, 2021 · 18 comments
Closed

How can i build source on Apple M1? #3071

huwei1024 opened this issue Jan 18, 2021 · 18 comments

Comments

@huwei1024
Copy link

How can i build source on Apple M1?

@martin-frbg
Copy link
Collaborator

As far as I know you will need a specially patched GCC , see #2814

@huwei1024
Copy link
Author

I build GCC error too :<

@martin-frbg
Copy link
Collaborator

Can you post the error message (or attach the complete build log) here ?

@huwei1024
Copy link
Author

This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by configure, which was
generated by GNU Autoconf 2.69. Invocation command line was

$ ./configure

---------

Platform.

---------

hostname = HuweideMBP-2.lan
uname -m = arm64
uname -r = 20.2.0
uname -s = Darwin
uname -v = Darwin Kernel Version 20.2.0: Wed Dec 2 20:40:21 PST 2020; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101

/usr/bin/uname -p = arm
/bin/uname -X = unknown

/bin/arch = unknown
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo = Mach kernel version:
Darwin Kernel Version 20.2.0: Wed Dec 2 20:40:21 PST 2020; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101
Kernel configured for up to 8 processors.
8 processors are physically available.
8 processors are logically available.
Processor type: arm64e (ARM64E)
Processors active: 0 1 2 3 4 5 6 7
Primary memory available: 16.00 gigabytes
Default processor set: 549 tasks, 2893 threads, 8 processors
Load average: 2.33, Mach factor: 5.66
/bin/machine = unknown
/usr/bin/oslevel = unknown
/bin/universe = unknown

PATH: /Users/huwei/miniforge3/condabin
PATH: /Users/huwei/.rustup/toolchains/dev/bin
PATH: /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin
PATH: /usr/local/bin
PATH: /usr/bin
PATH: /bin
PATH: /usr/sbin
PATH: /sbin
PATH: /Users/huwei/Documents/Env/apache-maven-3.6.3/bin
PATH: /opt/homebrew/bin
PATH: /Users/huwei/Documents/Env/sonar-scanner-4.5.0.2216-macosx/bin/
PATH: .

-----------

Core tests.

-----------

configure:2366: checking build system type
configure:2380: result: aarch64-apple-darwin20.2.0
configure:2427: checking host system type
configure:2440: result: aarch64-apple-darwin20.2.0
configure:2460: checking target system type
configure:2473: result: aarch64-apple-darwin20.2.0
configure:2527: checking for a BSD-compatible install
configure:2595: result: /usr/bin/install -c
configure:2606: checking whether ln works
configure:2628: result: yes
configure:2632: checking whether ln -s works
configure:2636: result: yes
configure:2643: checking for a sed that does not truncate output
configure:2707: result: /usr/bin/sed
configure:2716: checking for gawk
configure:2746: result: no
configure:2716: checking for mawk
configure:2746: result: no
configure:2716: checking for nawk
configure:2746: result: no
configure:2716: checking for awk
configure:2732: found /usr/bin/awk
configure:2743: result: awk
configure:3237: checking for libatomic support
configure:3247: result: yes
configure:3275: checking for libitm support
configure:3285: result: yes
configure:3294: checking for libsanitizer support
configure:3300: result: no
configure:3313: checking for libvtv support
configure:3319: result: no
configure:3333: checking for libhsail-rt support
configure:3339: result: no
configure:3466: checking for libphobos support
configure:3472: result: no
configure:4181: checking for gcc
configure:4197: found /usr/bin/gcc
configure:4208: result: gcc
configure:4437: checking for C compiler version
configure:4446: gcc --version >&5
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: arm64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
configure:4457: $? = 0
configure:4446: gcc -v >&5
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: arm64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
configure:4457: $? = 0
configure:4446: gcc -V >&5
clang: error: argument to '-V' is missing (expected 1 value)
clang: error: no input files
configure:4457: $? = 1
configure:4446: gcc -qversion >&5
clang: error: unknown argument '-qversion'; did you mean '--version'?
clang: error: no input files
configure:4457: $? = 1
configure:4477: checking whether the C compiler works
configure:4499: gcc conftest.c >&5
configure:4503: $? = 0
configure:4551: result: yes
configure:4554: checking for C compiler default output file name
configure:4556: result: a.out
configure:4562: checking for suffix of executables
configure:4569: gcc -o conftest conftest.c >&5
configure:4573: $? = 0
configure:4595: result:
configure:4617: checking whether we are cross compiling
configure:4625: gcc -o conftest conftest.c >&5
conftest.c:9:10: fatal error: cannot open file '/usr/local/include/stdio.h': Permission denied
#include <stdio.h>
^
1 error generated.
configure:4629: $? = 1
configure:4636: ./conftest
./configure: line 4638: ./conftest: No such file or directory
configure:4640: $? = 127
configure:4647: error: in /Users/huwei/Documents/Dev/github/gcc-darwin-arm64': configure:4649: error: cannot run C compiled programs. If you meant to cross compile, use --host'.
See `config.log' for more details

----------------

Cache variables.

----------------

ac_cv_build=aarch64-apple-darwin20.2.0
ac_cv_env_AR_FOR_TARGET_set=
ac_cv_env_AR_FOR_TARGET_value=
ac_cv_env_AR_set=
ac_cv_env_AR_value=
ac_cv_env_AS_FOR_TARGET_set=
ac_cv_env_AS_FOR_TARGET_value=
ac_cv_env_AS_set=
ac_cv_env_AS_value=
ac_cv_env_CCC_set=
ac_cv_env_CCC_value=
ac_cv_env_CC_FOR_TARGET_set=
ac_cv_env_CC_FOR_TARGET_value=
ac_cv_env_CC_set=
ac_cv_env_CC_value=
ac_cv_env_CFLAGS_set=
ac_cv_env_CFLAGS_value=
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_CXXFLAGS_set=
ac_cv_env_CXXFLAGS_value=
ac_cv_env_CXX_FOR_TARGET_set=
ac_cv_env_CXX_FOR_TARGET_value=
ac_cv_env_CXX_set=
ac_cv_env_CXX_value=
ac_cv_env_DLLTOOL_FOR_TARGET_set=
ac_cv_env_DLLTOOL_FOR_TARGET_value=
ac_cv_env_DLLTOOL_set=
ac_cv_env_DLLTOOL_value=
ac_cv_env_DSYMUTIL_FOR_TARGET_set=
ac_cv_env_DSYMUTIL_FOR_TARGET_value=
ac_cv_env_DSYMUTIL_set=
ac_cv_env_DSYMUTIL_value=
ac_cv_env_GCC_FOR_TARGET_set=
ac_cv_env_GCC_FOR_TARGET_value=
ac_cv_env_GDC_FOR_TARGET_set=
ac_cv_env_GDC_FOR_TARGET_value=
ac_cv_env_GFORTRAN_FOR_TARGET_set=
ac_cv_env_GFORTRAN_FOR_TARGET_value=
ac_cv_env_GOC_FOR_TARGET_set=
ac_cv_env_GOC_FOR_TARGET_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LD_FOR_TARGET_set=
ac_cv_env_LD_FOR_TARGET_value=
ac_cv_env_LD_set=
ac_cv_env_LD_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_LIPO_FOR_TARGET_set=
ac_cv_env_LIPO_FOR_TARGET_value=
ac_cv_env_LIPO_set=
ac_cv_env_LIPO_value=
ac_cv_env_NM_FOR_TARGET_set=
ac_cv_env_NM_FOR_TARGET_value=
ac_cv_env_NM_set=
ac_cv_env_NM_value=
ac_cv_env_OBJCOPY_FOR_TARGET_set=
ac_cv_env_OBJCOPY_FOR_TARGET_value=
ac_cv_env_OBJCOPY_set=
ac_cv_env_OBJCOPY_value=
ac_cv_env_OBJDUMP_FOR_TARGET_set=
ac_cv_env_OBJDUMP_FOR_TARGET_value=
ac_cv_env_OBJDUMP_set=
ac_cv_env_OBJDUMP_value=
ac_cv_env_OTOOL_FOR_TARGET_set=
ac_cv_env_OTOOL_FOR_TARGET_value=
ac_cv_env_OTOOL_set=
ac_cv_env_OTOOL_value=
ac_cv_env_RANLIB_FOR_TARGET_set=
ac_cv_env_RANLIB_FOR_TARGET_value=
ac_cv_env_RANLIB_set=
ac_cv_env_RANLIB_value=
ac_cv_env_READELF_FOR_TARGET_set=
ac_cv_env_READELF_FOR_TARGET_value=
ac_cv_env_READELF_set=
ac_cv_env_READELF_value=
ac_cv_env_STRIP_FOR_TARGET_set=
ac_cv_env_STRIP_FOR_TARGET_value=
ac_cv_env_STRIP_set=
ac_cv_env_STRIP_value=
ac_cv_env_WINDMC_FOR_TARGET_set=
ac_cv_env_WINDMC_FOR_TARGET_value=
ac_cv_env_WINDMC_set=
ac_cv_env_WINDMC_value=
ac_cv_env_WINDRES_FOR_TARGET_set=
ac_cv_env_WINDRES_FOR_TARGET_value=
ac_cv_env_WINDRES_set=
ac_cv_env_WINDRES_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_build_configargs_set=
ac_cv_env_build_configargs_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_host_configargs_set=
ac_cv_env_host_configargs_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_env_target_configargs_set=
ac_cv_env_target_configargs_value=
ac_cv_host=aarch64-apple-darwin20.2.0
ac_cv_path_SED=/usr/bin/sed
ac_cv_path_install='/usr/bin/install -c'
ac_cv_prog_AWK=awk
ac_cv_prog_ac_ct_CC=gcc
ac_cv_target=aarch64-apple-darwin20.2.0
acx_cv_prog_LN=ln

-----------------

Output variables.

-----------------

AR=''
AR_FOR_BUILD='$(AR)'
AR_FOR_TARGET=''
AS=''
AS_FOR_BUILD='$(AS)'
AS_FOR_TARGET=''
AWK='awk'
BISON=''
BUILD_CONFIG=''
CC='gcc'
CC_FOR_BUILD='$(CC)'
CC_FOR_TARGET=''
CFLAGS=''
CFLAGS_FOR_BUILD=''
CFLAGS_FOR_TARGET=''
COMPILER_AS_FOR_TARGET=''
COMPILER_LD_FOR_TARGET=''
COMPILER_NM_FOR_TARGET=''
CONFIGURE_GDB_TK=''
CPPFLAGS=''
CXX=''
CXXFLAGS=''
CXXFLAGS_FOR_BUILD=''
CXXFLAGS_FOR_TARGET=''
CXX_FOR_BUILD='$(CXX)'
CXX_FOR_TARGET=''
DEBUG_PREFIX_CFLAGS_FOR_TARGET=''
DEFS=''
DLLTOOL=''
DLLTOOL_FOR_BUILD='$(DLLTOOL)'
DLLTOOL_FOR_TARGET=''
DSYMUTIL=''
DSYMUTIL_FOR_BUILD='$(DSYMUTIL)'
DSYMUTIL_FOR_TARGET=''
ECHO_C='\c'
ECHO_N=''
ECHO_T=''
EXEEXT=''
EXPECT=''
FLAGS_FOR_TARGET=''
FLEX=''
GCC_FOR_TARGET=''
GCC_SHLIB_SUBDIR=''
GDB_TK=''
GDC_FOR_BUILD='$(GDC)'
GDC_FOR_TARGET=''
GFORTRAN_FOR_BUILD='$(GFORTRAN)'
GFORTRAN_FOR_TARGET=''
GNATBIND=''
GNATMAKE=''
GOC_FOR_BUILD='$(GOC)'
GOC_FOR_TARGET=''
HAVE_CXX11=''
HAVE_CXX11_FOR_BUILD=''
INSTALL_DATA='${INSTALL} -m 644'
INSTALL_GDB_TK=''
INSTALL_PROGRAM='${INSTALL}'
INSTALL_SCRIPT='${INSTALL}'
LD=''
LDFLAGS=''
LDFLAGS_FOR_BUILD=''
LDFLAGS_FOR_TARGET=''
LD_FOR_BUILD='$(LD)'
LD_FOR_TARGET=''
LEX=''
LIBOBJS=''
LIBS=''
LIPO=''
LIPO_FOR_TARGET=''
LN='ln'
LN_S='ln -s'
LTLIBOBJS=''
M4=''
MAINT=''
MAINTAINER_MODE_FALSE=''
MAINTAINER_MODE_TRUE=''
MAKEINFO=''
NM=''
NM_FOR_BUILD='$(NM)'
NM_FOR_TARGET=''
OBJCOPY=''
OBJCOPY_FOR_TARGET=''
OBJDUMP=''
OBJDUMP_FOR_TARGET=''
OBJEXT=''
OTOOL=''
OTOOL_FOR_TARGET=''
PACKAGE_BUGREPORT=''
PACKAGE_NAME=''
PACKAGE_STRING=''
PACKAGE_TARNAME=''
PACKAGE_URL=''
PACKAGE_VERSION=''
PATH_SEPARATOR=':'
RANLIB=''
RANLIB_FOR_BUILD='$(RANLIB)'
RANLIB_FOR_TARGET=''
RAW_CXX_FOR_TARGET=''
READELF=''
READELF_FOR_TARGET=''
RPATH_ENVVAR=''
RUNTEST=''
SED='/usr/bin/sed'
SHELL='/bin/sh'
STRIP=''
STRIP_FOR_TARGET=''
SYSROOT_CFLAGS_FOR_TARGET=''
TOPLEVEL_CONFIGURE_ARGUMENTS='./configure'
WINDMC=''
WINDMC_FOR_BUILD='$(WINDMC)'
WINDMC_FOR_TARGET=''
WINDRES=''
WINDRES_FOR_BUILD='$(WINDRES)'
WINDRES_FOR_TARGET=''
YACC=''
ac_ct_CC='gcc'
ac_ct_CXX=''
bindir='${exec_prefix}/bin'
build='aarch64-apple-darwin20.2.0'
build_alias=''
build_configargs=''
build_configdirs='build-libiberty build-libcpp build-texinfo build-flex build-bison build-m4 build-fixincludes'
build_cpu='aarch64'
build_libsubdir='build-aarch64-apple-darwin20.2.0'
build_noncanonical='aarch64-apple-darwin20.2.0'
build_os='darwin20.2.0'
build_subdir='build-aarch64-apple-darwin20.2.0'
build_tooldir=''
build_vendor='apple'
compare_exclusions=''
configdirs='intl libiberty opcodes bfd readline tcl tk itcl libgui zlib libbacktrace libcpp libcody libdecnumber gmp mpfr mpc isl libelf libiconv libctf texinfo flex bison binutils gas ld fixincludes gcc cgen sid sim gdb gdbserver gprof etc expect dejagnu m4 utils guile fastjar gnattools libcc1 gotools c++tools'
datadir='${datarootdir}'
datarootdir='${prefix}/share'
do_compare=''
docdir='${datarootdir}/doc/${PACKAGE}'
dvidir='${docdir}'
exec_prefix='NONE'
extra_host_libiberty_configure_flags=''
extra_host_zlib_configure_flags=''
extra_isl_gmp_configure_flags=''
extra_liboffloadmic_configure_flags=''
extra_linker_plugin_configure_flags=''
extra_linker_plugin_flags=''
extra_mpc_gmp_configure_flags=''
extra_mpc_mpfr_configure_flags=''
extra_mpfr_configure_flags=''
get_gcc_base_ver=''
gmpinc=''
gmplibs=''
host='aarch64-apple-darwin20.2.0'
host_alias=''
host_configargs=''
host_cpu='aarch64'
host_noncanonical='aarch64-apple-darwin20.2.0'
host_os='darwin20.2.0'
host_shared=''
host_subdir='host-aarch64-apple-darwin20.2.0'
host_vendor='apple'
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
islinc=''
isllibs=''
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
oldincludedir='/usr/include'
pdfdir='${docdir}'
poststage1_ldflags=''
poststage1_libs=''
prefix='NONE'
program_transform_name='s,y,y,'
psdir='${docdir}'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
stage1_cflags=''
stage1_checking=''
stage1_languages=''
stage1_ldflags=''
stage1_libs=''
stage2_werror_flag=''
sysconfdir='${prefix}/etc'
target='aarch64-apple-darwin20.2.0'
target_alias=''
target_configargs=''
target_configdirs='target-libgcc target-libbacktrace target-libgloss target-newlib target-libgomp target-liboffloadmic target-libhsail-rt target-libatomic target-libitm target-libstdc++-v3 target-libsanitizer target-libvtv target-libssp target-libquadmath target-libgfortran target-libffi target-libobjc target-libada target-libgo target-libphobos target-zlib target-rda'
target_cpu='aarch64'
target_noncanonical='aarch64-apple-darwin20.2.0'
target_os='darwin20.2.0'
target_subdir='aarch64-apple-darwin20.2.0'
target_vendor='apple'
tooldir=''

-------------------

File substitutions.

-------------------

alphaieee_frag=''
host_makefile_frag='/dev/null'
ospace_frag=''
serialization_dependencies=''
target_makefile_frag=''

-----------

confdefs.h.

-----------

/* confdefs.h */
#define PACKAGE_NAME ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
#define PACKAGE_STRING ""
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""

configure: exit 1

@brada4
Copy link
Contributor

brada4 commented Jan 19, 2021

What happens when you run
/Users/huwei/Documents/Dev/github/gcc-darwin-arm64 --version

@martin-frbg
Copy link
Collaborator

@brada4 I do not think "gcc-darwin-arm64" exists there as an executable yet, this is an attempt to build it from source using the system compiler (for which clang 12.0.0 was reported somewhere in the configure output).
Possibly building the modified compiler is not as simple as with the regular gcc builds, but I do note that gcc is normally built out-of-tree, that is create a separate directory for building and call configure from there like mkdir gccbuild; cd gccbuild; ../gcc-darwin-arm64/configure

@brada4
Copy link
Contributor

brada4 commented Jan 19, 2021

That formatting. If clang cannot create executables then something is missing xcode-install --help like binutils or so.

@brada4
Copy link
Contributor

brada4 commented Jan 20, 2021

Please check clang works:
Make a minimal.c file

int main(){};

clang minimal.c
should make a native executable ./a.out in current directory that does exactly nothing
if compiler shows half-screen of errors, it is probably worth googling around for them.

@huwei1024
Copy link
Author

@brada4
i got a.out, it works;

@brada4
Copy link
Contributor

brada4 commented Jan 20, 2021

So you can use clang to build BLAS and CBLAS APIs out of OpenBLAS. LAPACK components will not build without fortran.

Why gcc ./configure looks for stdio.h in a weirdest place cannot be figured out here. Probably carefully re-reading documents around that compiler or getting successfully pre-built compiler package is of help.

@martin-frbg
Copy link
Collaborator

https://stackoverflow.com/questions/65276102/compilation-errors-with-m1-macbook-pro-and-cmake suggests the SDKROOT variable may not be set correctly if stdio.h is not found.

@huwei1024
Copy link
Author

sudo ./configure --with-gmp=/opt/homebrew/Cellar/gmp/6.2.1 --with-mpfr=/opt/homebrew/Cellar/mpfr/4.1.0 --with-mpc=/opt/homebrew/Cellar/mpc/0.33

then i got this:

checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... yes
checking for the correct version of mpc.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations. Source code for these libraries can be found at
their respective hosting sites as well as at
https://gcc.gnu.org/pub/gcc/infrastructure/. See also
http://gcc.gnu.org/install/prerequisites.html for additional info. If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header

@martin-frbg
Copy link
Collaborator

It looks like you need to install the package "libmpc" from homebrew, searching for "mpc" on formulae.brew.sh tells me that what they call "mpc 0.33" is actually some music player client and not the multi-precision complex numbers library needed by gcc.

@isuruf
Copy link
Contributor

isuruf commented Jan 21, 2021

If you don't mind using conda package manager, you can use https://github.com/conda-forge/miniforge#download and run conda install fortran-compiler to install gfortran and conda install openblas to install openblas.

@martin-frbg
Copy link
Collaborator

Oh, great - did not know that conda already has packages for the M1. Need to update the wiki...

@brada4
Copy link
Contributor

brada4 commented Jan 21, 2021

You can untar those library tarballs and make unversioned symlinks inside gcc source directory.

@dnoan
Copy link
Contributor

dnoan commented Feb 28, 2021

@martin-frbg , maybe it is a good idea to add support for nagfort. It has native M1 support. See https://www.nag.com/news/first-fortran-compiler-apple-silicon-macs

@martin-frbg
Copy link
Collaborator

Maybe, but probably makes less sense while I lack both the hardware and that particular compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants