I tried to install google benchmark(https://github.com/google/benchmark) in my ubuntu machine by :
Remember I am using windows subsystem for linux.
# Check out the library.
$ git clone https://github.com/google/benchmark.git
# Go to the library root directory
$ cd benchmark
# Make a build directory to place the build output.
$ cmake -E make_directory "build"
# Generate build system files with cmake, and download any dependencies.
$ cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
# or, starting with CMake 3.13, use a simpler form:
# cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
# Build the library.
$ cmake --build "build" --config Release
$ sudo cmake --build "build" --config Release --target install
and my CMakeLists.txt :
cmake_minimum_required(VERSION 3.16)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_FLAGS "-O3 -lbenchmark -pthread")
project(proj)
find_package(benchmark REQUIRED)
set(SOURCES main.cpp)
add_executable(proj ${SOURCES})
target_link_libraries(proj benchmark::benchmark)
main.cpp
#include <benchmark/benchmark.h>
static void BM_StringCreation(benchmark::State& state) {
for (auto _ : state)
std::string empty_string;
}
// Register the function as a benchmark
BENCHMARK(BM_StringCreation);
BENCHMARK_MAIN();
and when I build it, I got this :
make[2]: *** No rule to make target '/tmp/build/80754af9/snappy_1649923748780/_build_env/x86_64-conda-linux-gnu/sysroot/usr/lib/librt.so', needed by 'proj'. Stop.
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/proj.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
2
Answers
Instead of all the
cmake -E <cmd>
stuff, try simply running cmake to configure the build instead. I don’t think you’re using most of those commands correctly, probably due to copy-pasting wrong (just guessing).Try this, explanations are in the comments:
The commands in your post should be split across multiple lines, so for example,
cmake -E chdir build
should becmake -E
and thenchdir build
instead, etc.Something probably went wrong when you were copy-pasting the commands. Either way, the version I posted above will (as far as I can see) do what you want.
I had exactly the same problem.
The clue is in the error here:
It is trying to link against a library designed to be used with anaconda when it "should" be looking under
/usr/lib/
etc.You can see exactly what it is trying to link against by looking in
CMakeFiles/proj.dir/link.txt
and you will probably see a bunch of very important looking libraries in stupid places like~/anacoda3/...
You will most likely also see a link path to
.../anaconda3/.../benchmark.so.0.0
or similar which is not the one you just installed! which is probably in/usr/local/lib/
(seeinstall_manifest.txt
in/build/
of benchmark for where)The issue is that when you install anaconda it, really rather obnoxiously for my tastes, installs launch scripts for itself in
.bashrc
or.bash_profile
(which causes your terminal to have(base)
or(other env)
at the beginning of each line), including placing itself at the beginning of your$PATH
. It does this through bash script which looks like:So, CMake is looking in your path for places to link against, and very helpfully, anaconda does the double whammy of 1) mirroring key system libraries AND 2) suggesting its own path is the first place anywhere should look for them (since it puts itself at the front of
$PATH
).Either way, remove the offending prefix to
$PATH
, or more generally, look in your.bashrc
or.bash_profile
and comment out the offending lines (and reboot etc.)That worked for me.