相关疑难解决方法(0)

制作GTest时出错

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

som@som-VPCEH25EN:~/Workspace/CPP/gtest-1.6.0/make$ make
g++ -I../include -g -Wall -Wextra -lpthread sample1.o sample1_unittest.o gtest_main.a -o sample1_unittest
gtest_main.a(gtest-all.o): In function `~ThreadLocal':
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific'
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete'
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific'
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1340: undefined reference to `pthread_key_delete'
gtest_main.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const':
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1372: undefined reference to `pthread_getspecific'
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1379: undefined reference to `pthread_setspecific'
gtest_main.a(gtest-all.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::CreateKey()':
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1365: undefined reference to `pthread_key_create'
gtest_main.a(gtest-all.o): In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::CreateKey()':
/home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1365: undefined reference to `pthread_key_create'
gtest_main.a(gtest-all.o): In function …
Run Code Online (Sandbox Code Playgroud)

linker-errors googletest

36
推荐指数
3
解决办法
2万
查看次数

如何强制使用静态库而不是共享?

在我的SConscript中,我有以下几行:

Program("xtest", Split("main.cpp"), LIBS="mylib fltk Xft Xinerama Xext X11 m")
Run Code Online (Sandbox Code Playgroud)

我如何让scons使用mylib.a而不是mylib.so,同时动态链接其他库?

编辑:希望尽可能少使用平台特定的黑客.

static portability build-system scons static-linking

13
推荐指数
2
解决办法
8743
查看次数

库中的"lib"前缀

来自http://www.adp-gmbh.ch/cpp/gcc/create_lib.html:

注意:库必须以三个字母开头lib并具有后缀.a.

这是一个操作系统约定,还是gcc/ arquirk?Xcode似乎能够创建没有前缀的库.它有什么不同的做法?

c c++ gcc naming-conventions

12
推荐指数
1
解决办法
4438
查看次数

将 cmake 用于 googletest 时对“pthread_getspecific”的未定义引用

我正在关注这本书

我安装了 GoogleTest 并构建了库:

kuyu@ub16:~/Downloads/googletest-master$ find . -name *.a
./mybuild/googlemock/libgmock_main.a
./mybuild/googlemock/gtest/libgtest_main.a
./mybuild/googlemock/gtest/libgtest.a
./mybuild/googlemock/libgmock.a
Run Code Online (Sandbox Code Playgroud)

我有一个 CMakeLists.txt 文件:

kuyu@ub16:~/Downloads/lotdd-code/c2/2$ echo $GMOCK_HOME 
/home/kuyu/Downloads/googletest-master
kuyu@ub16:~/Downloads/lotdd-code/c2/2$ cat CMakeLists.txt
project(chapterFirstExample)
cmake_minimum_required(VERSION 2.6)

include_directories($ENV{GMOCK_HOME}/googlemock/include $ENV{GMOCK_HOME}/googletest/include)
link_directories($ENV{GMOCK_HOME}/mybuild/googlemock $ENV{GMOCK_HOME}/mybuild/googlemock/gtest)
add_definitions(-std=c++0x)
set(CMAKE_CXX_FLAGS "${CMAXE_CXX_FLAGS} -Wall")

set(sources 
   main.cpp 
   SoundexTest.cpp)
add_executable(test ${sources})
target_link_libraries(test pthread)
target_link_libraries(test gmock)
target_link_libraries(test gtest)
Run Code Online (Sandbox Code Playgroud)

然后我尝试构建我的源文件:

kuyu@ub16:~/Downloads/lotdd-code/c2/2$ mkdir build && cd build
kuyu@ub16:~/Downloads/lotdd-code/c2/2/build$ cmake ..
# output omitted for brevity...
kuyu@ub16:~/Downloads/lotdd-code/c2/2/build$ make
Scanning dependencies of target test
[ 33%] Building CXX object CMakeFiles/test.dir/main.cpp.o
[ 66%] Building CXX object …
Run Code Online (Sandbox Code Playgroud)

c++ cmake googletest

6
推荐指数
1
解决办法
4224
查看次数