pthread.h include in src/Platforms/Gcc/UtestPlatform.cpp not compatible with MinGW

207 views
Skip to first unread message

Michael Stangeland

unread,
Feb 23, 2016, 1:31:40 PM2/23/16
to cpputest

I recently updated to 3.7.1 (from 3.6) and was unable to build with MinGW.  The UtestPlatform.cpp file now includes pthread.h and uses pthread_mutex_t (Commits from 12 sept 2014 by Chen YewM).  pthread.h doesn’t exist for a windows machine and thus not compatible with MinGW.


I've tracked down that I can apply the same implementation found in src/Platforms/VisualCpp/UtestPlatform.cpp, surrounding it with #ifdef __MINGW32__ conditionals.


If someone adds me to the collaborators I can push the changes to Git.
 

Best regards.


A. Robert S.

unread,
Feb 26, 2016, 8:40:39 AM2/26/16
to cpputest
Hi Michael,

Perhaps it is because of your particular version of MinGW / Msys. Perhaps you need to install the pthread library separately. I don't know. But we run regular builds on Appveyor, which just download a fresh copy of MinGW every time (no separate install of pthread), and it compiles just fine.

see here: https://ci.appveyor.com/project/basvodde/cpputest/build/3.7.0-ci630

Regards,
Robert

Dean Ter Haar

unread,
Jan 3, 2020, 3:56:04 PM1/3/20
to cpputest
I had a similar problem and found that I needed to add the pthread library to my MinGW / Msys installation.  I re-ran the MinGW Installation Manager (using mingw-get) and added the mingw32-pthreads-w32-* and mingw32-w32api-dev packages to my installation.  I then needed to re-run the configuration tool (./configure) and remake the cpputest executable.

e.g.

autoreconf . -i   (probably not necessary, no new output generated)
./configure --build=x86_64-pc-linux-gnu --host=mingw32  (see note below)
make clean
make tdd


After running configure, the CppUTest report shows that the CppUTest LIB is using pthread

----------------------------------------------------------------
CppUTest Version 3.8
Current compiler options:
   CC:                                  mingw32-gcc
   CXX:                                 mingw32-g++
   LD:                                  c:/mingw/mingw32/bin/ld.exe
   Default CFLAGS:                      -g -O2
   Default CXXFLAGS:                    -g -O2
   CppUTest CFLAGS:                       -Wno-c++11-long-long -Wno-long-long -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -pedantic -Wsign-conversion -Wno-disabled-macro-expansion -Wno-padded -Wno-reserved-id-macro -Wno-keyword-macro
   CppUTest CXXFLAGS:                    -include ./include/CppUTest/MemoryLeakDetectorNewMacros.h  -Wno-c++14-compat -Wno-c++11-long-long -Wno-long-long -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -pedantic -Wsign-conversion -Woverloaded-virtual -Wno-disabled-macro-expansion -Wno-padded -Wno-reserved-id-macro -Wno-keyword-macro -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-old-style-cast
   CppUTest CPPFLAGS:                    -include ./include/CppUTest/MemoryLeakDetectorMallocMacros.h -I ./include
   CppUTest LDFLAGS:
   CppUTest LIB:                           -lpthread


Note regarding the use of the --host and --build options for the configure command:
When issued without parameters "./configure" the script would fail on my Win10 64 bit machine when checking for cross compiling

checking whether we are cross compiling... configure: error: in `/c/tools/cpputest':

configure: error: cannot run C compiled programs.

If you meant to cross compile, use `--host'.

See `config.log' for more details


From another support site, another user discovered that this error was caused by his antivirus software deleting the temporary test executable that the script was trying to run before the script had a chance to run it.  I found that supplying the --host and --build parameters allowed configure to continue past this point and complete successfully.  I obtained my --host and --build values from the configure.log file (in my case line 111):

Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 …

 
Reply all
Reply to author
Forward
0 new messages