benchmark icon indicating copy to clipboard operation
benchmark copied to clipboard

Link error on OSX Mojave

Open jklimcak opened this issue 5 years ago • 17 comments

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

jklimcak avatar Apr 03 '19 11:04 jklimcak

Can you post your command lines?

On Wed, Apr 3, 2019 at 12:38 PM Joe Klimcak [email protected] 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 .

dmah42 avatar Apr 03 '19 11:04 dmah42

Did you build benchmark library with custom CXX_VISIBILITY_PRESET/VISIBILITY_INLINES_HIDDEN?

LebedevRI avatar Apr 03 '19 11:04 LebedevRI

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.

jklimcak avatar Apr 03 '19 16:04 jklimcak

Built the benchmark library successfully with:

... but that does not install it?

LebedevRI avatar Apr 03 '19 16:04 LebedevRI

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.

jklimcak avatar Apr 03 '19 21:04 jklimcak

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

LebedevRI avatar Apr 03 '19 21:04 LebedevRI

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.

jklimcak avatar Apr 09 '19 09:04 jklimcak

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 [email protected] 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 .

dmah42 avatar Apr 09 '19 12:04 dmah42

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

jklimcak avatar Apr 09 '19 14:04 jklimcak

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 [email protected] 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 .

dmah42 avatar Apr 09 '19 14:04 dmah42

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..

jklimcak avatar Apr 12 '19 08:04 jklimcak

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?

EricWF avatar Apr 12 '19 09:04 EricWF

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)

ganler avatar Jul 30 '19 05:07 ganler

In that example you never actually link to benchmark.

LebedevRI avatar Jul 30 '19 06:07 LebedevRI

I'm having this problem as well on Catalina.

jgall avatar Jun 10 '20 00:06 jgall

@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?

dmah42 avatar May 08 '21 08:05 dmah42

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?

eposse avatar Mar 12 '22 00:03 eposse