59

The libgtest-dev package seems only install header files to the system, but not the static and dynamic libraries which should be installed under /usr/lib.

Is it a bug?

Braiam
  • 66,947
  • 30
  • 177
  • 264
eddyxu
  • 817
  • 1
  • 7
  • 10

3 Answers3

72

Is it a bug?

No, it's deliberate:

gtest (1.6.0-1ubuntu2) precise; urgency=low

  * Stop distributing static library (although still build it, to ensure gtest
    works).  Upstream recommends against shipping the libary at all, just the
    source. (See: http://code.google.com/p/googletest/wiki/FAQ)
    The Debian maintainer plans to do this also (see BTS: 639795); do it in
    Ubuntu now to fulfil MIR requirements.

To build static libraries

cd /usr/src/gtest
sudo cmake .
sudo make
sudo mv libg* /usr/lib/

Edit:

The names have changed slightly over the years, though the process remains the same. In Ubuntu 17.04:

sudo apt-get install libgtest-dev
cd /usr/src/googletest/googletest
sudo mkdir build
cd build
sudo cmake ..
sudo make
sudo cp libgtest* /usr/lib/
cd ..
sudo rm -rf build
ish
  • 138,666
  • 36
  • 303
  • 312
  • 1
    Thanks! I've built the libraries in this way. Just thought that it might not be an *official* approach for a .deb package. – eddyxu Jun 03 '12 at 14:20
  • 2
    The Google works in mysterious ways! :) Glad it helped. – ish Jun 03 '12 at 14:23
  • I'd rather create a temporary directory for building, and not pollute `/usr/src/` with binaries. – Marco Leogrande Oct 16 '12 at 22:39
  • 2
    Copy-paste version: `cd /usr/src/gtest && sudo cmake . && sudo make && sudo mv libg* /usr/lib/ && cd -` – exic Jan 16 '13 at 16:05
  • 3
    Actually reason described [here](http://code.google.com/p/googletest/wiki/FAQ#Why_is_it_not_recommended_to_install_a_pre-compiled_copy_of_Goog) can be applied to **any** library. For example if boost is linked with libstdc++ and you want to use libc++ you need to recompile boost from sources. So it's strange, IMHO – ruslo Oct 23 '13 at 07:51
  • I can confirm it still works even on Ubuntu 14.04. A post-install warning would be nice, though. – thiagowfx Aug 11 '14 at 17:45
  • 11
    This is freaking asinine. Why the hell wouldn't they ship the library for the source? Or at least have the package install build it automatically. – Fake Name Nov 26 '15 at 03:48
  • General idea is still the same, but the directory names seem to have changed. In 17.04, I found it in /usr/src/googletest/googletest/. – Stéphane Jul 12 '17 at 14:31
  • Is there a requirement to make symbolic links with the new folder name "googletest" or the old folder name "gtest"? `sudo ln -s /usr/lib/libgtest.a /usr/local/lib/googletest/libgtest.a` `sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/googletest/libgtest_main.a` – Paresh471 Jul 18 '18 at 14:47
  • do you have an update for Ubuntu 20.04 ? – eri0o Jun 21 '20 at 23:06
23

Improving on izx's answer I would have used cmake this way:

sudo cmake -DCMAKE_BUILD_TYPE=RELEASE .

and I would attempt an out-of-source build:

cd /tmp
mkdir .build
cd .build
cmake -DCMAKE_BUILD_TYPE=RELEASE /usr/src/gtest/
make
sudo mv libg* /usr/lib/
erenon
  • 105
  • 4
Wojciech Migda
  • 476
  • 5
  • 7
1

Note that the recommended way by google is to have your existing project pull the gtest source code in.

Alternatively, when using with CMake, you can use add_subdirectory to add the gtest source that came with libgtest-dev since it by default goes into /usr/src/googletest.

The following will work

add_subdirectory(/usr/src/googletest gtest)
target_link_libraries(your_executable gtest)
Rufus
  • 812
  • 6
  • 15