《C++程序设计实践与技巧:测试驱动开发》 环境搭建遇到的坑

《C++程序设计实践与技巧:测试驱动开发》 环境搭建遇到的坑

 

在环境搭建时,遇到了一些资源的版本已经更新的问题,主要是 Google Mock,所以整理了搭建环境时与书本不同的修改。我使用的环境是 Ubuntu 16。

Google Mock

Google Mock 项目已经切换到 Github,网址为:https://github.com/google/googletest。

安装过程

下载下来后文件解压路径到: ~/Desktop/projects/googletest-release-1.8.0

cd ~/Desktop/projects/googletest-release-1.8.0
mkdir mybuild && cd mybuild
cmake ..
make

书的源码中需要用到 GoogleTest 的头文件和库,进入源码的code/c2/ 目录,CMakeLists.txt 的内容为:

project(chapterFirstExample)
cmake_minimum_required(VERSION 2.6)

include_directories($ENV{GMOCK_HOME}/include $ENV{GMOCK_HOME}/gtest/include)
link_directories($ENV{GMOCK_HOME}/mybuild $ENV{GMOCK_HOME}/gtest/mybuild)
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)

由于 mybuild 路径与 CMakeLists.txt 里的需求不同,于是需要对编译出来的 GoogleTest 重定向。执行如下。

cd ~/Desktop/projects/
mkdir googlemock && cd googlemock
ln -sf ~/Desktop/projects/googletest-release-1.8.0/googlemock/include/ include
ln -sf ~/Desktop/projects/googletest-release-1.8.0/mybuild/googlemock/ mybuild
mkdir gtest && cd gtest
ln -sf ~/Desktop/projects/googletest/include/ include
ln -sf ~/Desktop/project/googletest-release-1.8.0/mybuild/googlemock/gtest/ mybuild

libcurl

安装 libcul 的时候可能会出现未找到 OPENSSL 的提示,可以执行如下操作。

sudo apt-get install libssl-dev

执行示例代码

由于代码里提供的示例很多不全,暂时发现 code/c2/40 里的项目可行的,进入到 code/c2/40 执行如下操作,就能看到结果。

mkdir build && cd build
cmake ..
make
./test
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章