Git Product home page Git Product logo

c2's People

Contributors

jlangr avatar paytonrules avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

c2's Issues

CMakeLists.txt incompatible with new repo of GoogleTest

Hi!

The new repo of GoogleTest and GoogleMock is here:
https://github.com/google/googletest

Note that the structure is now
repo/googletest
repo/googlemock

In particular, the following does not exist anymore
repo/googletest/gtest

(So GoogleTest is no longer nested within GoogleMock).

But your book's CMakeLists.txt depends on it:
In this link for example, we can see that your CMakeLists.txt assumes the existence of $ENV{GMOCK_HOME}/gtest/include and $ENV{GMOCK_HOME}/gtest/mybuild

Under Linux we can fix this with a symbolic link:
repo/googlemock/gtest as a symbolic link to repo/googletest

I'd like to perhaps help in this respect.

Here follows a setup-script for GNU/Linux that

  • clones googletest (and googlemock)
  • compiles them
  • sets up a symbolic link of repo/googlemock/gtest pointing correctly
  • creates a load_testing.sh, which when sourcing with . load_testing.sh will automatically set GMOCK_HOME correctly.
#!/usr/bin/env bash

SHARED_LIB_ON_OFF=OFF    # ON


git clone https://github.com/google/googletest.git


REPODIR=$(readlink -f googletest)

## compile     googletest
mkdir $REPODIR/googletest/mybuild
cd    $REPODIR/googletest/mybuild
cmake -DBUILD_SHARED_LIBS=$SHARED_LIB_ON_OFF ..
make

## compile     googlemock
mkdir $REPODIR/googlemock/mybuild
cd    $REPODIR/googlemock/mybuild
cmake -DBUILD_SHARED_LIBS=$SHARED_LIB_ON_OFF ..
make

## create link                                    googlemock/gtest
ln -s $(readlink -f $REPODIR/googletest) $REPODIR/googlemock/gtest 



## create a load-script testing.sh
SCRIPT_NAME=load_testing.sh
LOAD_SCRIPT=$REPODIR/../$SCRIPT_NAME


cat <<EOF > $LOAD_SCRIPT
# "Run" this script with:    . $SCRIPT_NAME
# (this is called "sourcing" the script)

export GMOCK_HOME=$REPODIR/googlemock
EOF

chmod +x    $LOAD_SCRIPT

echo
echo "FINISHED"
echo
echo "Also generated file $SCRIPT_NAME"
echo "Recommendation:"
echo "Copy the script     $SCRIPT_NAME   ... to ~/bin"
echo "Run the script with:    . $SCRIPT_NAME"
echo "(this is called \"sourcing\" the script.    thereafter the cmake scripts should work nicely)"

You can try this. It should make your own code-examples' cmake stuff work again.

Shared Library Problems

Note also:
If, at the top of the above script... you set SHARED_LIB_ON_OFF=ON, (and clear any previously generated googletest directory that may have been cloned by a previous run of the script); and then run the script with SHARED_LIB_ON_OFF=ON, you'll find that your CMakeLists.txt (for example c2/2/CMakeLists.txt) will generate a binary, that when run, actually ends with Error in invalid pointer: ... or Double free.

The reason is that you link against both gmock and gtest (ref) ...

target_link_libraries(test gmock)
target_link_libraries(test gtest)

... which is double (!), since gmock library already includes the same stuff as gtest anyway... (ref gmock, ref gtest)... namely googletest/src/gtest-all.cc. I believe this should be linked only once (esp. during shared linking).

Thus I recommend changing c2/2/CMakeLists.txt (and others) to

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(tester ${sources})
target_link_libraries(tester pthread)
target_link_libraries(tester gmock)
## target_link_libraries(tester gtest)   ## leave this one out!

No more error or double delete!

(Above test was also renamed to tester, to avoid warnings on new version of cmake (ref))

Anyway... just started your book. Looks interesting!

Forgotten (failing!) Soundex Test

Hi,

this test was forgotten and fails:

TEST_F(SoundexEncoding, ForgetMeNot)
{
  ASSERT_THAT(soundex.encode("bahb"), Eq("B100"));
}

https://www.wolframalpha.com/input/?i=Soundex+bahb

It's not enough to just check the last character (ref).

Then there are also special corner cases, which according to Wolfram Soundex are:

TEST_F(SoundexEncoding, Corner)
{
  ASSERT_THAT(soundex.encode("Aaabwhwb"), Eq("A110"));
  ASSERT_THAT(soundex.encode("Aaabhwhb"), Eq("A110"));
}

https://www.wolframalpha.com/input/?i=Soundex+Aaabwhwb
https://www.wolframalpha.com/input/?i=Soundex+Aaabhwhb

[Windows] Solution for Issues Building on Windows

For anyone else who encounters this when compiling googletest from GitHub on Windows you need to create the project with the -Dgtest_force_shared_crt=ON argument to cmake.

Without this you can get a lot of compilation errors such as:
gtest.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug'

See the googletest readme for more information: https://github.com/google/googletest/blob/master/googletest/README.md

Additionally the googletest directory structure has changed, and the example c2 CMakeLists.txt file links to pthread (for googletest) but isn't required for this test, so it can be removed.

My CMakeLists.txt file which works is:

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)

project ("Soundex1")

include_directories($ENV{GMOCK_HOME}/googletest/include $ENV{GMOCK_HOME}/googlemock/include)
link_directories($ENV{GMOCK_HOME}/mybuild/lib/MinSizeRel)

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 gmock)
target_link_libraries(test gtest)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.