Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

v3: linker error

Open LukashonakV opened this issue 1 year ago • 0 comments

Describe the bug When try to compile catch2 v3 project with libstdc++, linker error cause failure

Expected behavior To compile catch2 v3 project successful

Reproduction steps

#include <catch2/catch_test_macros.hpp>

TEST_CASE() {
  SECTION("simple test") {
    REQUIRE(1 == 1);
  }
}
 g++ main.cpp -o catch2test -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group /usr/lib64/libCatch2Main.a /usr/lib64/libCatch2.a -Wl,--end-group

Get following errors:

/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccXwpYNB.o: in function `Catch::BinaryExpr<int, int>::~BinaryExpr()':
main.cpp:(.text._ZN5Catch10BinaryExprIiiED2Ev[_ZN5Catch10BinaryExprIiiED5Ev]+0x26): undefined reference to `Catch::ITransientExpression::~ITransientExpression()'
collect2: error: ld returned 1 exit status

Platform information:

  • OS: Linux 6.11.0-gentoo-x86_64 86_64 12th Gen Intel(R) Core(TM) i7-1260P GenuineIntel GNU/Linux
  • Compiler+version: gcc (Gentoo 13.3.1_p20240614 p17) 13.3.1 20240614
  • Catch version: v3.7.1

Additional context Meson provides the same

project('catch2test',
'cpp', 'c',
version: '0.0.1',
default_options: [ 'cpp_std=gnu++23', 'c_std=c2x']
)

compiler = meson.get_compiler('cpp')

src_files = files('main.cpp')

catch2 = dependency('catch2-with-main')

executable('catch2test', src_files, dependencies: [catch2])

meson setup --wipe build

The Meson build system
Version: 1.5.1
Source dir: /home/viktar/Documents/git/catch2test
Build dir: /home/viktar/Documents/git/catch2test/build
Build type: native build
Project name: catch2test
Project version: 0.0.1
C compiler for the host machine: cc (gcc 13.3.1 "cc (Gentoo 13.3.1_p20240614 p17) 13.3.1 20240614")
C linker for the host machine: cc ld.bfd 2.42
C++ compiler for the host machine: c++ (gcc 13.3.1 "c++ (Gentoo 13.3.1_p20240614 p17) 13.3.1 20240614")
C++ linker for the host machine: c++ ld.bfd 2.42
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: YES (/usr/bin/pkg-config) 2.2.0
Run-time dependency catch2-with-main found: YES 3.7.1
Build targets in project: 1

Found ninja-1.11.1 at /usr/bin/ninja

ninja -C build

ninja: Entering directory `build'
[2/2] Linking target catch2test
FAILED: catch2test 
c++  -o catch2test catch2test.p/main.cpp.o -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group /usr/lib64/libCatch2Main.a /usr/lib64/libCatch2.a -Wl,--end-group
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: catch2test.p/main.cpp.o: in function `Catch::BinaryExpr<int, int>::~BinaryExpr()':
/usr/local/include/catch2/internal/catch_decomposer.hpp:73:(.text._ZN5Catch10BinaryExprIiiED2Ev[_ZN5Catch10BinaryExprIiiED5Ev]+0x26): undefined reference to `Catch::ITransientExpression::~ITransientExpression()'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

LukashonakV avatar Sep 26 '24 14:09 LukashonakV