簡體   English   中英

未定義對Gtest的pthread的引用

[英]Undefined reference to pthread for Gtest

從昨天開始,我一直在努力嘗試使gtest正常工作,但是在閱讀了下面的鏈接后,我只是無法解決問題。

未定義對“ pthread_key_create”的引用(鏈接器錯誤)

進行GTest時出錯

顯示的編譯錯誤是這樣的:

g++ main.o tests.o var.o -L ../gmock/lib/.libs -L ../gmock/gtest/lib/.libs 
-lgtest -lgmock -lpthread -o test 
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_key_create'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_getspecific'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_key_delete'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
make: *** [test] Error 1

我的Makefile是:

CXXFLAGS=-I ../gmock/include -I ../gmock/gtest/include
test:main.o tests.o var.o 
    g++ $^ -L ../gmock/lib/.libs -L ../gmock/gtest/lib/.libs -lgtest -lgmock -lpthread -o $@ 

我仍在學習Linux,編譯和鏈接源文件的過程中。

錯誤是關於在pthread上鏈接錯誤。 您必須將pthread標志設置為-pthread ,然后跟隨CXX應該可以解決問題。

LDLIBS =  -L../gmock/lib/.libs -L../gmock/gtest/lib/.libs -lgtest -lgmock 
test:main.o tests.o var.o
    g++ -isystem $(LDLIBS) -pthread  $^ -o $@

鏈接有一個不錯的Makefile,可以解決您的所有問題,並且遵循創建Makefile的一般標准

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM