이 게시글에서는 아래 링크의 튜토리얼을 따라 M1에 openssl1.1.1을 설치할 때와 md5, sha1 소스코드를 컴파일할 때 겪은 문제를 정리한다.

https://indiespark.top/programming/compile-open-ssl-apple-silicon/

 

How to Compile OpenSSL 1.1.1 for Apple Silicon

The long-rumored ARM Mac is on the horizon. With this comes the big work of porting and re-compiling current applications. But many Mac App Store apps are dependent on OpenSSL, which doesn’t yet su…

indiespark.top

 

 

1. fatal error: 'inttypes.h' file not found

Building the ARM Half 단계에서 $ caffeniate make 을 입력했더니 다음과 같은 에러가 발생했다.

에러문

더보기

perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" include/crypto/bn_conf.h.in > include/crypto/bn_conf.h
perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" include/crypto/dso_conf.h.in > include/crypto/dso_conf.h
perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" include/openssl/opensslconf.h.in > include/openssl/opensslconf.h
/Applications/Xcode.app/Contents/Developer/usr/bin/make depend && /Applications/Xcode.app/Contents/Developer/usr/bin/make _all
cc  -I. -Iinclude -fPIC -arch arm64 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" -D_REENTRANT -DZLIB -DNDEBUG  -MMD -MF apps/app_rand.d.tmp -MT apps/app_rand.o -c -o apps/app_rand.o apps/app_rand.c
clang: warning: no such sysroot directory: '/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone' [-Wincompatible-sysroot]
In file included from apps/app_rand.c:10:
In file included from apps/apps.h:13:
In file included from ./e_os.h:16:
In file included from include/openssl/e_os2.h:243:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/include/inttypes.h:21:15: fatal error: 'inttypes.h' file not found
#include_next 
              ^~~~~~~~~~~~
1 error generated.
make[1]: *** [apps/app_rand.o] Error 1
make: *** [all] Error 2

해결

"Xcode-beta.app"을 "Xcode.app"으로 수정하면 된다. 자세한 openssl 과정은 링크 참고.

"darwin64-arm64-cc" => {
    inherit_from     => [ "darwin-common", asm("aarch64_asm") ],
    CFLAGS           => add("-Wall"),
    cflags           => add("-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"),
    lib_cppflags     => add("-DL_ENDIAN"),
    bn_ops           => "SIXTY_FOUR_BIT_LONG",
    perlasm_scheme   => "macosx",
},

 

 

2.  md5 관련 컴파일 에러

해결

아래 명령어를 입력해 경로를 변경 해준다.

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl@3/lib/

그런데 이 경우 x86_64에서는 해결이 되는데 arm64에서는 여전히 에러다..

.

.

.

해결!!!!!했다!!!

 

원했던 것

arm64 아키텍처에서도 openssl라이브러리 사용한 c프로그램 정상 실행

 

c프로그램 컴파일 시 에러문

3 warnings generated. ld: warning: ignoring file /usr/local/opt/openssl/lib//libcrypto.dylib, 
building for macOS-arm64 but attempting to link with file built for macOS-x86_64 Undefined symbols 
for architecture arm64: "_MD5_Final", referenced from: _main in md5-46c6b0.o "_MD5_Init", referenced 
from: _main in md5-46c6b0.o "_MD5_Update", referenced from: _main in md5-46c6b0.o 
ld: symbol(s) not found for architecture arm64

 

 

해결

위에서 openssl 설치할 때 만든 ~/openssl-1.1.1g-arm64 폴더로 이동해서 아래 명령어 순서대로 입력

./Configure CC=clang CXX=clang++ CFLAGS="-arch arm64" CXXFLAGS="-arch arm64" LDFLAGS="-L/usr/local/opt/openssl/lib" CPPFLAGS="-I/usr/local/opt/openssl/include"
make
make install

 

3. sha1 관련 컴파일 에러

 

c프로그램 컴파일 시 에러문

Undefined symbols for architecture arm64:
  "_SHA1_Final", referenced from:
      _do_fp in sha1-0d35b4.o
  "_SHA1_Init", referenced from:
      _do_fp in sha1-0d35b4.o
  "_SHA1_Update", referenced from:
      _do_fp in sha1-0d35b4.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

해결

컴파일 할 때 -lcrypto 옵션 붙여줘야 함ㅋㅅㅋ

 

행복해..사실 안 행복해... 이걸 대체 몇 시간을

 

 

 

+ Recent posts