google/benchmark

Position-independent code: Recompile with -fPIC

Open

#687 aberto em 21 de set. de 2018

Ver no GitHub
 (2 comments) (3 reactions) (0 assignees)C++ (1.539 forks)batch import
help wanted

Métricas do repositório

Stars
 (7.968 stars)
Métricas de merge de PR
 (Mesclagem média 4d 2h) (19 fundiu PRs em 30d)

Description

Awright?

I installed Google Bench globally on a Linux based system using:

cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON
sudo make install

However, when I attempted to build an example benchmark, i.e. the Basic usage one, my build failed. The relevant cmake script looks like this:

add_executable(basic_bench basic_bench.cpp)
target_link_libraries(basic_bench
  pthread
  benchmark)
/usr/bin/ld: //usr/local/lib/libbenchmark.a(benchmark.cc.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC

Being one to put a lot of stock by the everyday heros that are of compiler error messages, I inelegantly papped the following line at the top of the benchmark library CMake script, and rebuilt:

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

And lo and behold, the example then worked!

I haven't actually encountered PIC before on my travels, but some Wikipedia level research suggests that it is maybe what one would want to have when dealing with an externally linked library. Perhaps someone more well versed in the area would know what's going on?

Making this issue as information for folk that have the same problem (since I couldn't find a previous example).

Should I make a pull request to add this to the build script, or perhaps in troubleshooting?

Guia do colaborador