We know that not everything goes smoothly with MinGW threads; therefore, the -DWINVER = 0x0500 flag is often added instead of -lpthread. Why the received file may not start?
And again: if you add both -lpthread flags -DWINVER = 0x0500, the compiler will not find -lpthread. Why?
The situation is this. I got a task to study: to do in two CI cross-platform testing of the diploma project. The graduation project is written in C ++ and compiled MinGW. I do not really rummage in tests, well, I chose google tests. In order to see the results of this test itself, you need to compile the test itself into a file object, and also various other things from their sources. Tk here their sources are compiled only with the -lpthread flag. But since one CI service (AppVeyor) on Windows, I immediately thought that they did not have this library - I preinstalled it, but the resulting exe does not start.
summator_unittest.exe Makefile:46: recipe for target 'run' failed make: *** [run] Error -1073741511 Command exited with code 2 Here is my makefile:
ifeq ($(OS),Windows_NT) $(info Building on Windows/MinGW) GET_THE_BALL_ROLLIN = summator_unittest.exe CC = g++ FIN_C = g++ $(CPPFLAGS) $(CXXFLAGS) $^ -DWINVER=0x0500 -lpthread -o $@ else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Linux) $(info Building from Linux) GET_THE_BALL_ROLLIN = ./summator_unittest CC=i586-mingw32msvc-g++ FIN_C = g++ $(CPPFLAGS) $(CXXFLAGS) $^ -DWINVER=0x0500 -lpthread -o $@ endif endif USER_DIR = ../ GTEST_DIR = external/googletest/googletest CPPFLAGS += -I$(GTEST_DIR)/include CPPFLAGS += -I$(USER_DIR) CXXFLAGS += -g -Wall -Wextra -pthread TESTS = summator_unittest GTEST_HEADERS := $(GTEST_DIR)/include/gtest/*.h \ $(GTEST_DIR)/include/gtest/internal/*.h CC_AND_OTHER := $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) FOR_TEST := $(wildcard $(CC_AND_OTHER)) SOURCE_FILES := $(wildcard $(GTEST_HEADERS)) ################################################################### all : $(TESTS) run hello run: $(GET_THE_BALL_ROLLIN) hello: g++ src/hello.cpp -o hello.exe clean : rm -f $(TESTS) obj/gtest.a obj/gtest_main.a *.o obj/*.o ################################################################### GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) ################################################################### test/gtest-all.o : $(GTEST_SRCS_) g++ $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ $(GTEST_DIR)/src/gtest-all.cc -DWINVER=0x0500 -lpthread -o $@ test/gtest_main.o : $(GTEST_SRCS_) g++ $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ $(GTEST_DIR)/src/gtest_main.cc -DWINVER=0x0500 -lpthread -o $@ test/gtest.a : gtest-all.o $(AR) $(ARFLAGS) $@ $^ test/gtest_main.a : test/gtest-all.o test/gtest_main.o $(AR) $(ARFLAGS) $@ $^ ################################################################### test/summator.o : src/summator.cpp src/summator.h g++ -c src/summator.cpp -o $@ test/summator_unittest.o : test/summator_unittest.cpp \ src/summator.h $(SOURCE_FILES) g++ $(CPPFLAGS) $(CXXFLAGS) -c test/summator_unittest.cpp -o $@ summator_unittest : \ test/summator.o \ test/summator_unittest.o \ test/gtest_main.a $(FIN_C) Thank.