google / benchmark

A microbenchmark support library
Apache License 2.0
9.06k stars 1.63k forks source link

Link error on OSX Mojave #791

Open jklimcak opened 5 years ago

jklimcak commented 5 years ago

Running on OSX Mojave 10.14.3 and google-benchmark 1.4.1, I get linker errors trying to include the library:

Undefined symbols for architecture x86_64: "benchmark::internal::InitializeStreams()", referenced from: ___cxx_global_var_init in test.o ld: symbol(s) not found for architecture x86_64

clang version: Apple LLVM version 10.0.1 (clang-1001.0.46.3) Target: x86_64-apple-darwin18.2.0 Thread model: posix

dmah42 commented 5 years ago

Can you post your command lines?

On Wed, Apr 3, 2019 at 12:38 PM Joe Klimcak notifications@github.com wrote:

Running on OSX Mojave 10.14.3 and google-benchmark 1.4.1, I get linker errors trying to include the library:

Undefined symbols for architecture x86_64: "benchmark::internal::InitializeStreams()", referenced from: ___cxx_global_var_init in test.o ld: symbol(s) not found for architecture x86_64

clang version: Apple LLVM version 10.0.1 (clang-1001.0.46.3) Target: x86_64-apple-darwin18.2.0 Thread model: posix

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/benchmark/issues/791, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfIMhMvvOMt_uQDEzzve_lFpbAl7Fjcks5vdJK8gaJpZM4caSpA .

LebedevRI commented 5 years ago

Did you build benchmark library with custom CXX_VISIBILITY_PRESET/VISIBILITY_INLINES_HIDDEN?

jklimcak commented 5 years ago

Switched to CMake, and created the simplest possible executable I could with literally just including the benchmark library.

Built the benchmark library successfully with:

git clone https://github.com/google/benchmark.git
cd benchmark
mkdir build && cd build
CC=gcc-7 CXX=g++-7 cmake .. && cmake --build .

Then created a simple test.cpp:

#include "benchmark/benchmark.h"

int main() {
    return 0; 
}

My CMakeLists.txt looks like:

project (test)
cmake_minimum_required(VERSION 3.14)

find_package(benchmark)
include_directories(/usr/local/Cellar/benchmark/include)
add_executable(test test.cpp) 
target_link_libraries(test ${benchmark_LIBRARIES})

Again built with: cmake . && cmake --build .

And same error:

[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.o
[100%] Linking CXX executable test
Undefined symbols for architecture x86_64:
  "benchmark::internal::InitializeStreams()", referenced from:
      ___cxx_global_var_init in test.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2

As for @LebedevRI 's question - I did not customize those.

LebedevRI commented 5 years ago

Built the benchmark library successfully with:

... but that does not install it?

jklimcak commented 5 years ago

Forgot to include that in the above guide, my bad. I did also run sudo make install after CC=gcc-7 CXX=g++-7 cmake .. && cmake --build ., that was also successful.

Error still same.

LebedevRI commented 5 years ago

You built benchmark with gcc, but seem to be using clang to build example? Can you try using the exact same compiler?

jklimcak commented 5 years ago

Still same error I'm afraid. Tried both gcc (although had to downgrade XCode Command Line tools due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89864 , but that's a separate issue), and just tried building both the benchmark library (successful) and my project (unsuccessful) with clang, and still get:

Undefined symbols for architecture x86_64:
  "benchmark::internal::InitializeStreams()", referenced from:
      ___cxx_global_var_init in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Tried seeing if I have the same issues with other libraries such as gtest or boost, but I don't. Seems to be benchmark only.

dmah42 commented 5 years ago

It sounds an awful lot like the benchmark library isn't installed.

Can you confirm that the library is available on your system after you install? or post the full output of the install command?

On Tue, Apr 9, 2019 at 10:21 AM Joe Klimcak notifications@github.com wrote:

Still same error I'm afraid. Tried both gcc (although had to downgrade XCode Command Line tools due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89864 , but that's a separate issue), and just tried building both the benchmark library (successful) and my project (unsuccessful) with clang, and still get:

Undefined symbols for architecture x86_64: "benchmark::internal::InitializeStreams()", referenced from: ___cxx_global_var_init in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Tried seeing if I have the same issues with other libraries such as gtest or boost, but I don't. Seems to be benchmark only.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/google/benchmark/issues/791#issuecomment-481173121, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfIMgfvDdGnbmFMHkBAoBfrnmKfShjGks5vfFucgaJpZM4caSpA .

jklimcak commented 5 years ago

Sure, so step by step:

$cd benchmark/
$mkdir build && cd build 
$cmake .. && cmake --build . 

Output: https://gist.github.com/JoeKlimcak/3404bc54762289eb648d7fe48ef1ab3e

Then: sudo make install

Output: https://gist.github.com/JoeKlimcak/7a6fcb14c32546177ce9edc78b9929c4

dmah42 commented 5 years ago

Great!

Now is /usr/local/lib on your library path?

clang -Xlinker -v should output it.

If not, you need to compile with -L/usr/local/lib

On Tue, Apr 9, 2019 at 3:11 PM Joe Klimcak notifications@github.com wrote:

Sure, so step by step:

$cd benchmark/ $mkdir build && cd build $cmake .. && cmake --build .

Output: https://gist.github.com/JoeKlimcak/3404bc54762289eb648d7fe48ef1ab3e

Then: sudo make install

Output: https://gist.github.com/JoeKlimcak/7a6fcb14c32546177ce9edc78b9929c4

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/google/benchmark/issues/791#issuecomment-481268957, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfIMh9kqX__BtWWPPBmhtCwcpr56Uggks5vfJ-pgaJpZM4caSpA .

jklimcak commented 5 years ago

Unfortunately it is :(

Library search paths:
    /usr/local/lib
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib

Tried compiling with -L/usr/local/lib anyways - still same issue..

EricWF commented 5 years ago

You're almost certainly using new headers with an old library.

Can you post the full compile and link commands passing both -v and -Wl,-v?

ganler commented 5 years ago

Hey @JoeKlimcak . Have u got a solution to this?

I got the same problem even though I tried to install this with brew.

My CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(test)

set(CMAKE_CXX_STANDARD 17)

include_directories(/usr/local/Cellar/google-benchmark/1.5.0/include)
add_executable(test main.cpp)

What I got:

[ 50%] Linking CXX executable quicker_sort
Undefined symbols for architecture x86_64:
  "benchmark::internal::InitializeStreams()", referenced from:
      ___cxx_global_var_init in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
LebedevRI commented 5 years ago

In that example you never actually link to benchmark.

jgall commented 4 years ago

I'm having this problem as well on Catalina.

dmah42 commented 3 years ago

@EricWF is onto something I think. i think you have a version mismatch somehow, maybe a previously installed version of the library against the headers from source?

eposse commented 2 years ago

I'm having the same problem with Catalina. I've tried rebuilding many times. I deleted the installation from /usr/local/lib and /usr/local/include, and in fact removed every file that appears in the install_manifest.txt file generated by 'sudo make install', rebuild everything from scratch, and I still get the same link error.

In my case I'm using

Apple clang version 11.0.3 (clang-1103.0.32.62) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Any ideas?