8
submitted 1 week ago* (last edited 1 week ago) by ComicalMayhem@lemmy.world to c/techsupport@lemmy.world

I'm so utterly flabbergasted. The tutorial page says to use the CMake integration and includes a link, but the link sends me to a page with a ton of hyper specific information that doesn't exactly walk me through set up, and I actually cannot find any real guides to help with this. I tried copy pasting the Cmake snippet into the CMakeLists.txt and running cmake -B build but it broke, with 3 errors: Cannot find source file: test.cpp, No SOURCES given to target: tests, and No SOURCES given to target: custom-main-tests. When I comment out the offending line (add_executable(tests test.cpp)) I end up with the error Cannot specify link libraries for target "tests" which is not built by this project. I've already installed Catch2 as a system package via my software manager (Linux Mint). Is this a directory issue? Am I supposed to clone a git repo or copy-paste libraries in somewhere? I don't understand and the CMake integration link on Catch2's tutorial page is seemingly of no help.

Not using any IDEs, just my default text editor and Xed. I am also not at all versed in CMake whatsoever, like, at all. No real understanding of what it is or what it does or how it works, it's basically magic to me.

you are viewing a single comment's thread
view the rest of the comments
[-] ImgurRefugee114@reddthat.com 2 points 1 week ago* (last edited 1 week ago)

This issue doesn't sound specific to catch2; it sounds like a misconfiguration of your project's CMake / file directory.

The first error says it can't find test.cpp ; if just a bare relative path, then it should be right beside the CMakeLists.txt

Its been a while since I messed with Catch2, but it may be worthwhile trying to use it without CMake first just to separate the concerns

E.g. test.cpp

#include <catch2/catch_test_macros.hpp>

TEST_CASE("Arithmetic") {
    REQUIRE(2 + 2 == 4);
}

Compile (e.g. with gnu toolchain; Assuming g++ and catch2 are installed system-wide and properly integrated into the environment by your package manager)

g++ -std=c++17 test.cpp -o tests -lCatch2Main -lCatch2

Then just run ./tests

this post was submitted on 08 Nov 2026
8 points (90.0% liked)

techsupport

3260 readers
8 users here now

The Lemmy community will help you with your tech problems and questions about anything here. Do not be shy, we will try to help you.

If something works or if you find a solution to your problem let us know it will be greatly apreciated.

Rules: instance rules + stay on topic

Partnered communities:

You Should Know

Reddit

Software gore

Recommendations

founded 3 years ago
MODERATORS