Cannot get parallel letter frequency to link

I’m on Ubuntu 22.04 using WSL2 in Windows 11. I have catch2 version 2.13.8 installed locally. I’m building the parallel-letter-frequency exercise with this Bash script:

#!/bin/bash
if [ ! -d build ]
then
    mkdir build
    cd build
    cmake -D EXERCISM_TEST_SUITE=1 -DEXERCISM_INCLUDE_BENCHMARK=1 -G "Unix Makefiles" ..
    cd -
fi

if [ -d test ]
then
    rm -rf test
fi

make -C build

I’ve used the above script (excluding the -DEXERCISM_INCLUDE_BENCHMARK=1 argument) in all other exercises without issue.

I’m getting these linker errors:

/usr/bin/ld: CMakeFiles/parallel-letter-frequency.dir/parallel_letter_frequency_test.cpp.o: in function `Catch::Benchmark::OutlierClassification Catch::Benchmark::Detail::classify_outliers<__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > > >(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >)':
parallel_letter_frequency_test.cpp:(.text._ZN5Catch9Benchmark6Detail17classify_outliersIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEEEENS0_21OutlierClassificationET_SB_[_ZN5Catch9Benchmark6Detail17classify_outliersIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEEEENS0_21OutlierClassificationET_SB_]+0x6f): undefined reference to `Catch::Benchmark::Detail::weighted_average_quantile(int, int, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >)'
/usr/bin/ld: parallel_letter_frequency_test.cpp:(.text._ZN5Catch9Benchmark6Detail17classify_outliersIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEEEENS0_21OutlierClassificationET_SB_[_ZN5Catch9Benchmark6Detail17classify_outliersIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEEEENS0_21OutlierClassificationET_SB_]+0x8a): undefined reference to `Catch::Benchmark::Detail::weighted_average_quantile(int, int, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >)'
/usr/bin/ld: CMakeFiles/parallel-letter-frequency.dir/parallel_letter_frequency_test.cpp.o: in function `void Catch::Benchmark::Benchmark::run<std::chrono::_V2::steady_clock>()':
parallel_letter_frequency_test.cpp:(.text._ZN5Catch9Benchmark9Benchmark3runINSt6chrono3_V212steady_clockEEEvv[_ZN5Catch9Benchmark9Benchmark3runINSt6chrono3_V212steady_clockEEEvv]+0x354): undefined reference to `Catch::Benchmark::Detail::analyse_samples(double, int, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/parallel-letter-frequency.dir/build.make:115: parallel-letter-frequency] Error 1

What am I doing wrong?

-DEXERCISM_TEST_SUITE=1 tells cmake to link with the compiled version of Catch2 that is installed on the system, instead of having to compile Catch2 itself.
I think that version does not contain the parts for the benchmark.

Do you mind replacing -D EXERCISM_TEST_SUITE=1 with -DEXERCISM_RUN_ALL_TESTS=1 and trying again?

Yes, I can get that to work if I don’t delete the test directory. However, I would like to avoid having to have the test directory. Is there a way to do that?

@siebenschlaefer I figured it out. I just had to cobble together a solution where I can use my own catch2/catch.hpp file.

build.sh:

#!/bin/bash
if [ ! -d build ]
then
    mkdir build
    cd build
    cmake -DEXERCISM_RUN_ALL_TESTS=1 -DEXERCISM_INCLUDE_BENCHMARK=1 -G "Unix Makefiles" ..
    cd -
fi

make -C build

test/tests-main.cpp:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

tests/catch.hpp:

#include <catch2/catch.hpp>

Great that you could figure something out that works for you.
Happy coding!