GoogleTest, g++ and 32-bit configuration

June 05, 2016

Reading time ~1 minute

I have worked on g++ compiler and google test for running unit tests of my huge c++ code base on MAC-OS-X operating system and integrating on Jenkins server as well. I have learned many things after some investigation and now I think this information can be useful for the people suffering due to same topic.

Using .so files built by android ndk

First of all, my huge c++ code base is used in one of our top games as ndk built .so file and you know this is also a c++ library. It looks reasonable to use this prepared .so file for compiling with google test library and run unit tests, but as far as I see it is impossible. (If there is anyone who can achieve this, please write me!) Here is my stackoverflow topic about this issue :

http://stackoverflow.com/questions/37571476/compiling-with-g-via-linking-so-file-built-by-android-ndk

g++, gcc and GoogleTest configuration as 32-bit

After trying to use .so file, I have decided to compile my code base with g++ compiler with 32-bit option, because I have compiled my code base with 32-bit option with ndk so far and I don’t want to waste my time with some casting, including etc. issues. I assume you already are familiar with GoogleTest and g++, cmake compile concepts. You need gtest-all and gtest-main libraries built on GoogleTest library. You can use the following command to prepare 32-bit google test (For more information about google test)

cmake <YOUR_GOOGLE_TEST_ROOT_DIRECTORY> -DCMAKE_BUILD_TYPE=release32

“CMAKE_BUILD_TYPE=release32” option forces the make process to use 32-bit option. After that you need to compile and obtain object files for gtest-all.cc and gtest_main.cc with 32-bit configuration :

g++ -isystem <YOUR_GOOGLE_TEST_ROOT_DIRECTORY>/include -I./ -pthread -c <YOUR_GOOGLE_TEST_ROOT_DIRECTORY>/src/gtest-all.cc -m32
g++ -isystem <YOUR_GOOGLE_TEST_ROOT_DIRECTORY>/include -I./ -pthread -c <YOUR_GOOGLE_TEST_ROOT_DIRECTORY>/src/gtest_main.cc -m32

“-m32” option here makes the magic for you and compiles with 32-bit option.

Now you can build archive files for using on compiling process of your unit tests.

ar rvs libgtest.a gtest-all.o
ar rvs libgtest_main.a gtest_main.o

Remaining part is just compiling my code base with the libraries libgtest.a and libgtest_main.a and creating an executable file which include all my unit tests. Next week I am gonna publish a blog post like “Google test tutorial” which will be include a simple code base and some unit tests.

Depending on an aar library includes transitive dependencies in a maven project

Depending on an aar library includes transitive dependencies in a maven project Continue reading