google 测试在 eclipse 中支持 c++11 吗?
Does google test support c++11 at eclipse?
我正在使用 xubuntu 14.4
、eclipse luna
、google test1.7
。
当我对 c++11
使用 google 测试时,它不起作用。
在我使用 xubuntu 12.4
之前,它是有效的。
gcc
版本是:gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2.
google test
不支持c++11
吗?
有错误信息:
12:08:58 **** Incremental Build of configuration Debug for project googletest ****
make all
Building target: googletest
Invoking: Cross G++ Linker
g++ -L/home/smkang/test/gtest-1.7.0 -o "googletest" ./src/googletest.o -lpthread -lgtest
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::~ThreadLocal()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x16): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x2b): undefined reference to `pthread_key_delete'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::~ThreadLocal()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED5Ev]+0x16): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED5Ev]+0x2b): undefined reference to `pthread_key_delete'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const':
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv]+0x18): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv]+0x7c): undefined reference to `pthread_setspecific'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::CreateKey()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE9CreateKeyEv[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE9CreateKeyEv]+0x16): undefined reference to `pthread_key_create'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::CreateKey()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE9CreateKeyEv[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE9CreateKeyEv]+0x16): undefined reference to `pthread_key_create'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::GetOrCreateValue() const':
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv]+0x16): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv]+0x7a): undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
make: *** [googletest] error 1
12:08:59 Build Finished (took 1s.246ms)
我的代码是:
#include <iostream>
#include "gtest/gtest.h"
TEST(Ex,test)
{
std::cout<<"hello googletest"<<std::endl;
}
int main(int argc, char * argv[])
{
::testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
return 0;
}
简短的回答是肯定的,googletest 确实支持 C++11,尽管您所说的 'support' 不是很清楚。如果这就是您的意思,您绝对可以使用实现 C++11 标准的编译器来编译 googletest。
关于错误,您 link 时似乎缺少 pthread 库。我不确定如何在 eclipse 中执行此操作,但一般来说,编译时需要将“-pthread”传递给 GCC。
我正在使用 xubuntu 14.4
、eclipse luna
、google test1.7
。
当我对 c++11
使用 google 测试时,它不起作用。
在我使用 xubuntu 12.4
之前,它是有效的。
gcc
版本是:gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2.
google test
不支持c++11
吗?
有错误信息:
12:08:58 **** Incremental Build of configuration Debug for project googletest ****
make all
Building target: googletest
Invoking: Cross G++ Linker
g++ -L/home/smkang/test/gtest-1.7.0 -o "googletest" ./src/googletest.o -lpthread -lgtest
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::~ThreadLocal()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x16): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x2b): undefined reference to `pthread_key_delete'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::~ThreadLocal()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED5Ev]+0x16): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED5Ev]+0x2b): undefined reference to `pthread_key_delete'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const':
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv]+0x18): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv]+0x7c): undefined reference to `pthread_setspecific'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::CreateKey()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE9CreateKeyEv[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE9CreateKeyEv]+0x16): undefined reference to `pthread_key_create'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::CreateKey()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE9CreateKeyEv[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE9CreateKeyEv]+0x16): undefined reference to `pthread_key_create'
/home/smkang/test/gtest-1.7.0/libgtest.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::GetOrCreateValue() const':
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv]+0x16): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv]+0x7a): undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
make: *** [googletest] error 1
12:08:59 Build Finished (took 1s.246ms)
我的代码是:
#include <iostream>
#include "gtest/gtest.h"
TEST(Ex,test)
{
std::cout<<"hello googletest"<<std::endl;
}
int main(int argc, char * argv[])
{
::testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
return 0;
}
简短的回答是肯定的,googletest 确实支持 C++11,尽管您所说的 'support' 不是很清楚。如果这就是您的意思,您绝对可以使用实现 C++11 标准的编译器来编译 googletest。
关于错误,您 link 时似乎缺少 pthread 库。我不确定如何在 eclipse 中执行此操作,但一般来说,编译时需要将“-pthread”传递给 GCC。