Public bug reported:
From the ubuntu24.04 docker image, trying to compile and link a
catch2-based test program results in undefined references.
Steps to reproduce:
sudo docker run --rm -it ubuntu:24.04
apt update
apt install build-essential g++ catch2
cat > test.cpp << 'EOF'
#include <catch2/catch_test_macros.hpp>
TEST_CASE("test", "[test]") {
int a = 1;
REQUIRE(a == 1);
}
EOF
c++ -lCatch2Main -lCatch2 test.cpp
Expected Results:
It should be able to compile and link and run successfully.
Actual Results:
/usr/bin/ld: /tmp/ccdwjWLo.o: warning: relocation against
`_ZTVN5Catch20ITransientExpressionE' in read-only section
`.text._ZN5Catch20ITransientExpressionC2Ebb[_ZN5Catch20ITransientExpressionC5Ebb]'
/usr/bin/ld: /tmp/ccdwjWLo.o: in function `CATCH2_INTERNAL_TEST_0()':
test.cpp:(.text+0x9a): undefined reference to
`Catch::AssertionHandler::AssertionHandler(Catch::StringRef,
Catch::SourceLineInfo const&, Catch::StringRef,
Catch::ResultDisposition::Flags)'
/usr/bin/ld: test.cpp:(.text+0xef): undefined reference to
`Catch::AssertionHandler::handleExpr(Catch::ITransientExpression const&)'
/usr/bin/ld: test.cpp:(.text+0x10a): undefined reference to
`Catch::AssertionHandler::complete()'
/usr/bin/ld: test.cpp:(.text+0x15f): undefined reference to
`Catch::AssertionHandler::handleUnexpectedInflightException()'
/usr/bin/ld: /tmp/ccdwjWLo.o: in function
`__static_initialization_and_destruction_0()':
test.cpp:(.text+0x269): undefined reference to `Catch::makeTestInvoker(void
(*)())'
/usr/bin/ld: test.cpp:(.text+0x295): undefined reference to
`Catch::AutoReg::AutoReg(Catch::Detail::unique_ptr<Catch::ITestInvoker>,
Catch::SourceLineInfo const&, Catch::StringRef, Catch::NameAndTags const&)'
/usr/bin/ld: /tmp/ccdwjWLo.o: in function
`Catch::ITransientExpression::ITransientExpression(bool, bool)':
test.cpp:(.text._ZN5Catch20ITransientExpressionC2Ebb[_ZN5Catch20ITransientExpressionC5Ebb]+0x1b):
undefined reference to `vtable for Catch::ITransientExpression'
/usr/bin/ld: /tmp/ccdwjWLo.o: in function `Catch::BinaryExpr<int,
int>::~BinaryExpr()':
test.cpp:(.text._ZN5Catch10BinaryExprIiiED2Ev[_ZN5Catch10BinaryExprIiiED5Ev]+0x26):
undefined reference to `Catch::ITransientExpression::~ITransientExpression()'
/usr/bin/ld:
/tmp/ccdwjWLo.o:(.data.rel.ro._ZTIN5Catch10BinaryExprIiiEE[_ZTIN5Catch10BinaryExprIiiEE]+0x10):
undefined reference to `typeinfo for Catch::ITransientExpression'
/usr/bin/ld: /tmp/ccdwjWLo.o: in function `Catch::BinaryExpr<int,
int>::streamReconstructedExpression(std::ostream&) const':
test.cpp:(.text._ZNK5Catch10BinaryExprIiiE29streamReconstructedExpressionERSo[_ZNK5Catch10BinaryExprIiiE29streamReconstructedExpressionERSo]+0x74):
undefined reference to `Catch::formatReconstructedExpression(std::ostream&,
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, Catch::StringRef, std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /tmp/ccdwjWLo.o: in function `std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >
Catch::Detail::stringify<int>(int const&)':
test.cpp:(.text._ZN5Catch6Detail9stringifyIiEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKT_[_ZN5Catch6Detail9stringifyIiEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKT_]+0x33):
undefined reference to `Catch::StringMaker<int, void>::convert[abi:cxx11](int)'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
Info:
# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
# apt-cache policy catch2
catch2:
Installed: 3.4.0-1build1
Candidate: 3.4.0-1build1
Version table:
*** 3.4.0-1build1 500
500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages
100 /var/lib/dpkg/status
** Affects: catch2 (Ubuntu)
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2081647
Title:
Undefined reference when linking to catch2
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/catch2/+bug/2081647/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs