I have been trying (desperately, at times), to get the GTEST/GMOCK environment running on Native [env:desktop] with my Arduino project’s Unit Tests because I had some dependencies to mock and GTEST/GMOCK looked like a good idea.
I managed to overcome many hurdles with MINGW install etc. and it is compiling now, but the test won’t execute due to linker issues:
c:/mingw/bin/.[...]./mingw32/bin/ld.exe: c:/[...]/libmingw32.a(mbrscan.o):(.text+0xb6): undefined reference to SetLastError@4'
c:/mingw/bin/.[...]./mingw32/bin/ld.exe: c:/[...]/libmingw32.a(wcharmap.o):(.text+0x208): undefined reference to WideCharToMultiByte@32'
c:/mingw/bin/.[...]./mingw32/bin/ld.exe: c:/[...]/libmingwex.a(codeset.o):(.text+0xbe): undefined reference to etCPInfo@8
c:/mingw/bin/.[...]./mingw32/bin/ld.exe: c:[...]/libmingwex.a(codeset.o):(.text+0x143): undefined reference to GetCPInfo@8`
I found a similar issue on stackoverflow with no solution that enlightened me.
Here’s my plaformio.ini: (it only works with gnu++11, NOT with c++11)
platform = native
-std=gnu++11 # c++11# MUST BE gnu++11, not -std=c++11
lib_compat_mode = off
I checked the SetLastError function, contained in <errno.h> (but this file is not there, instead MINGW is using cerrno, the c++ variant of the c header). It’s in MINGW’s library folder mingw32/9.2.0/include/c++.
What am I missing?
OK, I did a bit of deep-dive into the build output log --verbose (shortened!) attached.
Although UNITY is compiled and linked as well - I am not using it and couldn’t figure out how to disable the tool - I’m sure it does not cause this issue as building with the pio run aborts with the same errors (to compile, I exchanged main.cpp and test_main.cpp temporarily).
Maybe linker order is wrong? Will do some reseach in GTEST/GMOCK’s headers.
I was so unhappy with all my unsuccessful digging that I decided to install Linux as dual boot and try with build-in gcc/g++. I had completely different errors, this time missing -pthread which I had to add to
build_flags = -std=gnu++11 # must be gnu++11, not -std=c++11 for gtest to run -pthread # needed to make gtest run on g++
AND - it WORKED
Back to Win10 (I just couldn’t stand it not working on Windows)
I suspected that MinGW was just not configured correctly.
Enter command line Start->cmd
type mingw-get (pity that I did not do this earlier!)
search for mingw32-libmingwex under MinGW Standard Libraries
activate both mingw32-libmingwex-dll and mingw32-libmingwex-dev
activate mingw32-libpthreadgc-dll and mingw32-libpthreadgc-dev
Rebuild with pio test -e desktop -f desktop --verbose
Hi @schallbert sounds very promising Would you mind setting up discussions for the repo? I think that my feedback might be better placed right there.
For a start: in “pio run -e desktop -f desktop” the “-f” switch is unrecognized. It is not a part of the “pio run” interface. Is there something missing that points to gtest?