Memory error using BUILD_SHARED_LIBS=ON for both gtest,gmock and C++ test program

133 views
Skip to first unread message

dswel...@gmail.com

unread,
Oct 19, 2016, 10:36:43 AM10/19/16
to Google C++ Testing Framework

I wanted to build my test with BUILD_SHARED_LIBS=ON, since one of my files to be tested involved a .so files.  I thought I had to build gtest,gmock also as .so files, so I built them with -DBUILD_SHARED_LIBS=ON option.  Then I created a CMakeLists.txt  for my test_shared.cpp file with the BUILD_SHARED_LIBS option on.  In the CMakeLists.txt file I added "add_custom_command" to run the test after building it.  But when it ran it resulted in a memory error in the output as shown below in directory "/home/welchons/test/use_gtest_with_build_shared_libs" with subdirectory "build" where the cmake and make are done.   I have attached a much-simplified source file, test_shared.cpp (basically an empty file with "TEST(){}" , and the CMakeLists.txt file just to show the error more clearly.

➜  use_gtest_with_build_shared_libs pwd     
/home/welchons/test/use_gtest_with_build_shared_libs
➜  use_gtest_with_build_shared_libs /bin/rm -Rf build
➜  use_gtest_with_build_shared_libs mkdir build
➜  use_gtest_with_build_shared_libs cd build
➜  build cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/welchons/test/use_gtest_with_build_shared_libs/build
➜  build make
Scanning dependencies of target test_shared
[ 50%] Building CXX object CMakeFiles/test_shared.dir/test_shared.cpp.o
[100%] Linking CXX executable test_shared
Running test_shared
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from test_case_1
[ RUN      ] test_case_1.test_1
[       OK ] test_case_1.test_1 (0 ms)
[----------] 1 test from test_case_1 (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.
*** Error in `/home/welchons/test/use_gtest_with_build_shared_libs/build/test_shared': free(): invalid size: 0x000000000185bf80 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x77725)[0x7f47d520d725]
/lib/x86_64-linux-gnu/libc.so.6(+0x7ff4a)[0x7f47d5215f4a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f47d5219abc]
/home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so(_ZSt8_DestroyINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEvPT_+0x18)[0x7f47d5e86f35]
/home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so(_ZNSt12_Destroy_auxILb0EE9__destroyIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvT_S9_+0x2e)[0x7f47d5e84fa5]
/home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so(_ZSt8_DestroyIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEvT_S7_+0x23)[0x7f47d5e80904]
/home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so(_ZSt8_DestroyIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_EvT_S7_RSaIT0_E+0x27)[0x7f47d5e7a3ef]
/home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so(_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EED1Ev+0x36)[0x7f47d5e738e2]
/lib/x86_64-linux-gnu/libc.so.6(__cxa_finalize+0x9a)[0x7f47d51d035a]
/home/welchons/googletest/googletest/build/googlemock/libgmock.so(+0x80083)[0x7f47d5b77083]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:01 48499213                           /home/welchons/test/use_gtest_with_build_shared_libs/build/test_shared
00601000-00602000 r--p 00001000 08:01 48499213                           /home/welchons/test/use_gtest_with_build_shared_libs/build/test_shared
00602000-00603000 rw-p 00002000 08:01 48499213                           /home/welchons/test/use_gtest_with_build_shared_libs/build/test_shared
0184a000-0187c000 rw-p 00000000 00:00 0                                  [heap]
7f47d0000000-7f47d0021000 rw-p 00000000 00:00 0
7f47d0021000-7f47d4000000 ---p 00000000 00:00 0
7f47d4c70000-7f47d4d78000 r-xp 00000000 08:01 12321313                   /lib/x86_64-linux-gnu/libm-2.23.so
7f47d4d78000-7f47d4f77000 ---p 00108000 08:01 12321313                   /lib/x86_64-linux-gnu/libm-2.23.so
7f47d4f77000-7f47d4f78000 r--p 00107000 08:01 12321313                   /lib/x86_64-linux-gnu/libm-2.23.so
7f47d4f78000-7f47d4f79000 rw-p 00108000 08:01 12321313                   /lib/x86_64-linux-gnu/libm-2.23.so
7f47d4f79000-7f47d4f91000 r-xp 00000000 08:01 12321359                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f47d4f91000-7f47d5190000 ---p 00018000 08:01 12321359                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f47d5190000-7f47d5191000 r--p 00017000 08:01 12321359                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f47d5191000-7f47d5192000 rw-p 00018000 08:01 12321359                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f47d5192000-7f47d5196000 rw-p 00000000 00:00 0
7f47d5196000-7f47d5356000 r-xp 00000000 08:01 12321272                   /lib/x86_64-linux-gnu/libc-2.23.so
7f47d5356000-7f47d5555000 ---p 001c0000 08:01 12321272                   /lib/x86_64-linux-gnu/libc-2.23.so
7f47d5555000-7f47d5559000 r--p 001bf000 08:01 12321272                   /lib/x86_64-linux-gnu/libc-2.23.so
7f47d5559000-7f47d555b000 rw-p 001c3000 08:01 12321272                   /lib/x86_64-linux-gnu/libc-2.23.so
7f47d555b000-7f47d555f000 rw-p 00000000 00:00 0
7f47d555f000-7f47d5575000 r-xp 00000000 08:01 12321298                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f47d5575000-7f47d5774000 ---p 00016000 08:01 12321298                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f47d5774000-7f47d5775000 rw-p 00015000 08:01 12321298                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f47d5775000-7f47d58e7000 r-xp 00000000 08:01 56624563                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f47d58e7000-7f47d5ae7000 ---p 00172000 08:01 56624563                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f47d5ae7000-7f47d5af1000 r--p 00172000 08:01 56624563                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f47d5af1000-7f47d5af3000 rw-p 0017c000 08:01 56624563                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f47d5af3000-7f47d5af7000 rw-p 00000000 00:00 0
7f47d5af7000-7f47d5bec000 r-xp 00000000 08:01 48628021                   /home/welchons/googletest/googletest/build/googlemock/libgmock.so
7f47d5bec000-7f47d5deb000 ---p 000f5000 08:01 48628021                   /home/welchons/googletest/googletest/build/googlemock/libgmock.so
7f47d5deb000-7f47d5ded000 r--p 000f4000 08:01 48628021                   /home/welchons/googletest/googletest/build/googlemock/libgmock.so
7f47d5ded000-7f47d5df3000 rw-p 000f6000 08:01 48628021                   /home/welchons/googletest/googletest/build/googlemock/libgmock.so
7f47d5df3000-7f47d5eaa000 r-xp 00000000 08:01 48628047                   /home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so
7f47d5eaa000-7f47d60a9000 ---p 000b7000 08:01 48628047                   /home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so
7f47d60a9000-7f47d60ab000 r--p 000b6000 08:01 48628047                   /home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so
7f47d60ab000-7f47d60b0000 rw-p 000b8000 08:01 48628047                   /home/welchons/googletest/googletest/build/googlemock/gtest/libgtest.so
7f47d60b0000-7f47d60d6000 r-xp 00000000 08:01 12321248                   /lib/x86_64-linux-gnu/ld-2.23.so
7f47d62b1000-7f47d62b7000 rw-p 00000000 00:00 0
7f47d62d1000-7f47d62d5000 rw-p 00000000 00:00 0
7f47d62d5000-7f47d62d6000 r--p 00025000 08:01 12321248                   /lib/x86_64-linux-gnu/ld-2.23.so
7f47d62d6000-7f47d62d7000 rw-p 00026000 08:01 12321248                   /lib/x86_64-linux-gnu/ld-2.23.so
7f47d62d7000-7f47d62d8000 rw-p 00000000 00:00 0
7fff2f55a000-7fff2f57b000 rw-p 00000000 00:00 0                          [stack]
7fff2f5c8000-7fff2f5ca000 r--p 00000000 00:00 0                          [vvar]
7fff2f5ca000-7fff2f5cc000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
CMakeFiles/test_shared.dir/build.make:96: recipe for target 'test_shared' failed
make[2]: *** [test_shared] Aborted (core dumped)
make[2]: *** Deleting file 'test_shared'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/test_shared.dir/all' failed
make[1]: *** [CMakeFiles/test_shared.dir/all] Error 2
Makefile:94: recipe for target 'all' failed
make: *** [all] Error 2
➜  build





test_shared.cpp
CMakeLists.txt
Reply all
Reply to author
Forward
0 new messages