-pthread和-lpthread

我试图在我的Ubuntu机器上设置GTest环境.但在使GTest获取库时,我收到以下错误...

../obj/gtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const':
/home/t/srs/state-threads/utest/./gtest-fit/googletest/include/gtest/internal/gtest-port.h:1803: undefined reference to `pthread_getspecific'
/home/t/srs/state-threads/utest/./gtest-fit/googletest/include/gtest/internal/gtest-port.h:1811: undefined reference to `pthread_setspecific'
../obj/gtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::CreateKey()':
/home/t/srs/state-threads/utest/./gtest-fit/googletest/include/gtest/internal/gtest-port.h:1797: undefined reference to `pthread_key_create'
../obj/gtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::CreateKey()':
/home/t/srs/state-threads/utest/./gtest-fit/googletest/include/gtest/internal/gtest-port.h:1797: undefined reference to `pthread_key_create'
../obj/gtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::GetOrCreateValue() const':
/home/t/srs/state-threads/utest/./gtest-fit/googletest/include/gtest/internal/gtest-port.h:1803: undefined reference to `pthread_getspecific'
/home/t/srs/state-threads/utest/./gtest-fit/googletest/include/gtest/internal/gtest-port.h:1811: undefined reference to `pthread_setspecific'

在Makefile中将 -lpthread 更改为-pthread.(我放弃了小'L'.)之后编译'make'没有错误

在编译时,-pthread-lpthread都是用于链接pthread库的选项。

-pthread选项告诉编译器生成适用于多线程程序的可执行文件。它包含了多线程库的链接信息,以确保程序能够正确地使用多线程功能。

-lpthread选项则直接指定了pthread库的链接路径。它告诉编译器在链接阶段使用指定的pthread库文件(通常是libpthread.so)来链接程序。

这两个选项的效果是类似的,都可以使程序正确地使用多线程功能。选择使用哪个选项取决于编译器的实现和系统环境。

在大多数情况下,使用-pthread选项是更简洁和推荐的方式,因为它可以自动处理与多线程相关的链接信息。如果你确定要指定pthread库的链接路径,可以使用-lpthread选项。但是,使用该选项时需要确保指定的库路径是正确的,否则可能会导致链接错误。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值