Develog
catch2, Undefined symbols for architecture 에러 극복기 본문
1. C++ 진짜 싫다
아니 대체 이런 언어를 왜 쓰는 거죠.
프레임워크를 설치하든, 코드를 짜든, 문법 배운 거 실습을 하든 도통 뭘 하든 간에 제대로 돌아가는 꼴을 못 봤습니다.
버전은 어마어마하고, 책임은 몽땅 프로그래머한테 떠넘기고, OS마다 컴파일러마다 파편화는 아찔한 수준이고, 패키지든 프레임워크든 뭐 하나 설치만 하면 에러부터 뿜어대고...
Catch2요?
아니 유닛 테스트를 위해서 쓸 수 있는 좋은 프레임워크라고 소개하면 뭐 합니까, 설치해서 쓸려고 해도 에러만 토해내는데!
초보자 입장인 저에게는 C++이 너무나도 싫습니다. 문법 괴팍하다고 한동한 멀리하던 Python이 선녀로 보이는 수준입니다.
아니 패키지 설치하라고 할 때마다, 새로운 문법을 하나씩 배울 때마다 늘 새롭고 재밌지가 않아요. 겁부터 난다고요. 이게 맞아요, 진짜?!
2. Catch2
Catch2는 C++에서 사용할 수 있는 유닛 테스트용 프레임워크입니다.
책에서 그렇게 말하더군요. 설치했죠. 샘플 코드가 깃허브에 있길래 그대로 받아 적었습니다.
#define CATCH_CONFIG_MAIN
#include <catch2/catch_test_macros.hpp>
#include <cstdint>
uint32_t factorial( uint32_t number ) {
return number <= 1 ? number : factorial(number-1) * number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( factorial( 1) == 1 );
REQUIRE( factorial( 2) == 2 );
REQUIRE( factorial( 3) == 6 );
REQUIRE( factorial(10) == 3'628'800 );
}
====================[ Build | C_pp_Study | Debug ]==============================
/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake --build /Users/___/Documents/GitHub/___/C-pp-Study/cmake-build-debug --target C_pp_Study -j 6
[2/2] Linking CXX executable C_pp_Study
FAILED: C_pp_Study
: && /usr/bin/c++ -g -arch arm64 -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/C_pp_Study.dir/main.cpp.o -o C_pp_Study && :
Undefined symbols for architecture arm64:
"Catch::makeTestInvoker(void (*)())", referenced from:
___cxx_global_var_init in main.cpp.o
"Catch::AutoReg::AutoReg(Catch::Detail::unique_ptr<Catch::ITestInvoker>, Catch::SourceLineInfo const&, Catch::StringRef, Catch::NameAndTags const&)", referenced from:
___cxx_global_var_init in main.cpp.o
"Catch::StringRef::StringRef(char const*)", referenced from:
___cxx_global_var_init in main.cpp.o
"_main", referenced from:
<initial-undefines>
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
완벽하게도 에러를 뱉습니다.
조금 검색을 해보니 심볼 링크가 제대로 안 돼서 그렇다고 합니다.
이때부터 억울해졌습니다. homebrew에서 패키지 형태로 설치하고, 샘플 코드를 그대로 복사해 실행한 게 다였다고요.
chatGPT는 신기하게 C++ 관련 질문을 던지면 바보가 되어버립니다. 처음부터 포기하고 Gemini를 열심히 괴롭혔죠.
그랬더니 설치된 패키지를 찾을 수 있도록 CMAKE 텍스트를 수정해야 한다면서 아래와 같은 코드를 적어줍니다.
cmake_minimum_required(VERSION 3.10)
project(프로젝트이름)
set(CMAKE_CXX_STANDARD 17)
# Homebrew로 설치된 Catch2를 찾습니다.
# Catch2가 설치되어 있지 않으면 오류가 발생할 수 있습니다.
find_package(Catch2 REQUIRED)
add_executable(프로젝트이름
main.cpp
)
# Catch2 라이브러리를 실행 파일에 연결합니다.
# Catch2::Catch2WithMain은 main() 함수가 포함된 라이브러리입니다.
target_link_libraries(프로젝트이름 PRIVATE Catch2::Catch2WithMain)
그랬더니 세상에, 진짜 됩니다.
혹시나 싶어서 프로젝트 이름 부분만 바꿔 처음 시도했던 'AutoBrake' 부분에도 적용해 보았습니다.
/Users/____/Documents/GitHub/____/C-pp-Study/cmake-build-debug/C_pp_Study -r xml -d yes --order lex AutoBrake
Testing started at 16:31 ...
Run with rng-seed=2448172018
Process finished with exit code 0
...되네요. AI 없었으면 진작에 "이런 미친!" 하면서 때려치웠을 겁니다.
3. 진짜?
Catch2/docs/cmake-integration.md at devel · catchorg/Catch2
A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch) - catchorg/Catch2
github.com
설마요. 진짜 때려치웠다가는 CS 전공생 주제에 C++도 못 다루는 허접이 되어버립니다.
나중에 알았습니다. Catch2 도큐먼트를 다시 자세히 찾아보니까 Gemini가 답변해 준 사항과 동일한 코드를 정리해 둔 페이지가 있더군요.
뭐가 됐든 AI 없이도 답은 찾았겠지만, 여태 접해본 언어 중에서 C++가 가장 피곤하고 어려운 언어라는 생각은 변함없을 것 같습니다.
수고하셨습니다!
'Technology > C++' 카테고리의 다른 글
템플릿 클래스의 람다식 형식 추론 (0) | 2025.08.20 |
---|---|
const와 constexpr (0) | 2025.08.06 |
C++의 포인터 (0) | 2025.08.03 |
static_assert와 non-type template (0) | 2025.07.30 |
strcpy() 와 strncpy() (0) | 2025.07.14 |