0

I'm on a Windows machine and use MinGW, attempting to compile a hello world program that uses a shared library. After an absurd amount of attempts, I found out the following:

  • Manually compiling it with gcc and providing -I and -L flags for the required directories works fine.
  • Using the msys make.exe file provided under the MinGW/msys/1.0/bin installation directory properly executes a Makefile with no problems
  • Using the mingw32-make.exe provided under MinGW/bin doesn't work properly when trying to build using the same Makefile. From my understanding, it doesn't parse the -I and -L flags at all. It works fine if I add the dependencies (both includes and libs) under their respective MinGW directories.

These past few days while I was trying and familiarizing myself with these tools (I'm comfortable with C's syntax but know about nothing past that) I read many guides and no one seemed to have this issue (from the few that actually attempted this on a Windows machine without using an IDE). Did I miss something? Is my MinGW installation known to have this issue?

Note that at first I was attempting to compile the project using the 64-bit version of the library but failed. I'm guessing this means that I have a 32-bit MinGW installation.

Knowing that some will ask to see the Makefile:

CC = gcc
MY_LIB = -L/e/C_Projects/Libraries/MySharedLib/lib -lMyLibName
MY_INCLUDE = -I/e/C_Projects/Libraries/MySharedLib/include
CFLAGS = -Wall -c $(MY_INCLUDE)
LDFLAGS = -lmingw32 -mwindows $(MY_LIB)
EXE = Test.exe

all: $(EXE)


$(EXE): main.o

    $(CC) $< $(LDFLAGS) -o $@

main.o: main.c

    $(CC) $(CFLAGS) $< -o $@

clean:

    del *.o && del $(EXE)

The error produced by mingw32-make.exe is the following

main.c:1:22: fatal error: MyLib.h: No such file or directory
 #include <MyLib.h>
                      ^
compilation terminated.
Makefile:19: recipe for target 'main.o' failed
mingw32-make: *** [main.o] Error 1
PentaKon
  • 4,139
  • 5
  • 43
  • 80
  • 1
    I think you need to put double quotes around MyLib.h. Do like this: `#include "MyLib.h"` – Syed Waris Apr 10 '18 at 11:17
  • Also ensure that your `MyLib.h` is in `/e/C_Projects/Libraries/MySharedLib/include` – Syed Waris Apr 10 '18 at 11:19
  • Run it with `VERBOSE` on and check supplied commands. Paths looks strange. – user7860670 Apr 10 '18 at 11:42
  • 1
    On Windows the path separator is "\" and not "/". "/" is on Linux – Syed Waris Apr 10 '18 at 11:59
  • I'm pretty sure it is not a path issue since as I pointed out it works fine with **make.exe** – PentaKon Apr 10 '18 at 12:00
  • 1
    `make` will run commands using bash, `mingw32-make` on the other hand uses the default windows shell. Presumably when testing without make you were invoking `gcc` under MSYS bash, the issue has nothing to do with make itself. – user657267 Apr 10 '18 at 18:19
  • 1
    Possible duplicate of [What are the differences between MinGW's make and MSYS's make and which one is available where?](https://stackoverflow.com/questions/18020816/what-are-the-differences-between-mingws-make-and-msyss-make-and-which-one-is-a) – user657267 Apr 10 '18 at 18:19
  • I'm not seeing how this helps... I tried with both Unix like and Windows like paths to no avail... – PentaKon Apr 10 '18 at 18:28
  • Post a complete example with windows paths that fails with mingw32-make, try and strip it down to the bare metal. – user657267 Apr 10 '18 at 20:39
  • this line, in the make file, `main.o: main.c` is missing a key dependency so even if it ever compiles, it will not re-compile when the header file is changed. Suggest: `main.o: main.c MyLib.h` – user3629249 Apr 12 '18 at 01:41
  • what is the `/e` doing in the paths? – user3629249 Apr 12 '18 at 01:41
  • to avoid having 'make' re-evaluate each macro, each time that macro is invoked, replace the ` = ` with ` := ` in each of the macro definitions – user3629249 Apr 12 '18 at 01:43

0 Answers0