linking error

손호준·2023년 9월 1일

linking에러 트러블 슈팅

cargo run 을 실행하자 linking 에러가 발생했는데,

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="..."
  = note: ...
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

warning: `hudsucker` (example "log") generated 4 warnings
error: could not compile `hudsucker` (example "log") due to previous error; 4 warnings emitted

대충 이런 식으로 나온다.
문제는 reqwest 크레이트를 쓰려고 하는데, 이때 Rust 컴파일러가 연결에 필요한 C 라이브러리를 찾을 수 없어서 발생. 여기서는 OpenSSL 관련 라이브러리 때문인 것으로 추정

step 1. sudo dnf install openssl-devel 명령어로 OpenSSL 개발 패키지를 설치

step 2. Rust가 설치된 OpenSSL를 가리키도록 환경 변수를 설정

openssl이 설치된 경로 찾기
> find /usr -name 'openssl' -type d 2>/dev/null
해당 명령어를 입력했을때 openssl이 여러개 존재한다면,
아래 디렉토리들을 포함하는 openssl 디렉토리를 찾는다.
bin  include  lib  share  ssl 

환경변수 설정
> export OPENSSL_DIR=/usr/local/opt/openssl
> export OPENSSL_LIB_DIR=$OPENSSL_DIR/lib
> export OPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include
> export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH    -> library path 까지 지정해줘야 해결됨

환경 변수 설정 확인
> echo $OPENSSL_DIR

환경 변수 삭제
> unset $OPENSSL_DIR
profile
Rustacean🦀

0개의 댓글