Search code examples
c++gradlecompiler-errorstravis-cigoogletest

"multiple definition" of googletest symbols only when compiling on Travis CI with gradle


I'm trying to get some CI on Travis CI working.
So I set up some tests with gtest and gradle. Only having one test file was working flawlessly. However as soon as I added the second I get tons of multiple definition errors. And they're only gtest symbols. The weirdest thing is, I am not able to reproduce this on any other system. I tried my local Ubuntu machine with GCC7, Debian with GCC6 and Windows with VS 2015.

I'm rather clueless as to why these errors appear and why they only appear on Travis CI.

Build log: https://travis-ci.org/fivunlm/cppstreams/jobs/420067374
Repo (the branch I'm working on): https://github.com/fivunlm/cppstreams/tree/0a89e8f01c9f868a2d690780b2afe159627bd81e
Build file: https://github.com/fivunlm/cppstreams/blob/0a89e8f01c9f868a2d690780b2afe159627bd81e/build.gradle

Edit:

The main issue is the compilation error. The irreproducibility, just makes it a lot harder to debug.

Edit 2:

I just managed to recreate it un my Ubuntu VM. It's the first time ever though. I'll be able to try to debug it first hand. Also I'll be able to answer more in depth questions.


Solution

  • As it turns out, I was compiling gtest incorrectly. The culprit is this: https://github.com/fivunlm/cppstreams/blob/0a89e8f01c9f868a2d690780b2afe159627bd81e/lib/build.gradle#L16-L17

    Instead it should just be include "src/gtest-all.cc". The file includes all other sources.

    So if you're not sure why your gtest is acting up, make sure you only compile src/gtest-all.cc.