IT한 것/Mobile (iOS, AOS)

Redundant #include of module 'A' appears within 'B' 오류 해결 과정

lovian 2022. 10. 4. 15:57

 

레거시 C 모듈을 objective c 에서 사용하고 있었는데, Xcode를 업데이트 하면서 이런 오류가 발생하기 시작했다.

 

직역해보자면

B라는 곳에서 A 모듈에 대한 헤더포함(include)이 중복되었다

정도로 읽힌다.

맞다. 내가 사용하던 레거시 C모듈은 수많은 C 함수를 구조체에 함수 포인터 목록으로 만들어주는 작업을 전처리기만으로 수행한다.

그러다보니, 한 헤더에서 A.h를 여러번 include 하여 사용하고 있다. (이거 하느라 삽질 엄청한 과거의 기록이 새록새록)

 

그런데 왜 갑자기 이런 오류를 발생시켰을까? (예전까지 잘 사용했었음)

 

가장 먼저 찾아낸 것은 이 옵션이다.

모듈이 뭔지는 모르겠으나 C나 Objective C 코드도  모듈로 사용하게 한다고 한다. (이 옵션을 끄면 빌드문제는 해결됨)

 

내가 만드는것은 framework이고 외부에 배포할 예정이므로 고객에게 이 옵션을 끄라고 강요하기 곤란하다.

그럼 한번 더 파고 들어가 봐야한다.

 

-Wmodules-import-nested-redundant 옵션을 찾았고 기본적으로 오류로 처리된다고 명시되어 있다.

그리고 -Wno-modules-import-nested-redundant를 사용하면 끌 수 있다고 한다.

 

그러나 framework 사용자에게 해당 옵션 설정을 강요하는 것도 좋은 선택은 아님..

하여 해당 옵션을 일시적으로 켜고 끄는 방법을 찾아보게 되었다.

 

https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas

 

Clang Compiler User’s Manual — Clang 16.0.0git documentation

Sampling profilers are used to collect runtime information, such as hardware counters, while your application executes. They are typically very efficient and do not incur a large runtime overhead. The sample data collected by the profiler can be used durin

clang.llvm.org

위의 내용에 의하면 방법이 있다. 

 

최종으로 내 framework 헤더에 pragma로 감싸서 문제를 잘 해결하였다.

 

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmodules-import-nested-redundant"

#include <MyHeader.h>

#pragma clang diagnostic pop