LoginSignup
0
0

More than 5 years have passed since last update.

googletest とテストコードをリンク時にエラー発生

Last updated at Posted at 2018-11-05

google test と テストコードをリンク時に発生したエラーを対処した話

発生したリンクエラー

libgtest.a とテストコードを以下のようにリンクした。

g++  -I./test-code/inc -I./googletest/googletest/include -I./googletest/googlemock/include -coverage -std=c++11 -L./test-target/lib -L./googletest/lib -o bin/google-test-example1 test-code/obj/google-test-example1.o -lpthread -ltest_target -lgtest -lgmock -lgtest_main

すると、以下のようなエラーが発生。

gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x24): `pthread_getspecific' に対する定義されていない参照です

対処

-lpthread を一番後ろに持っていくとうまくいった。1

g++  -I./test-code/inc -I./googletest/googletest/include -I./googletest/googlemock/include -coverage -std=c++11 -L./test-target/lib -L./googletest/lib -o bin/google-test-example1 test-code/obj/google-test-example1.o -ltest_target -lgtest -lgmock -lgtest_main -lpthread

  1. 恥ずかしながらライブラリの記述順序に対する知見がないので勉強したいと思った。 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0