Skip to content
Advertisement

Cannot compile Makefile using make command on Windows

Problem summary

I am trying to install an open-source parallel finite-element code called TACS and available at this github repository. To comply with the indicated prerequisites, I followed the instructions at this github repository, which allowed me to install SuiteSparse and METIS on Windows with precompiled BLAS/LAPACK DLLs. For the MPI, I installed both the Intel MPI Library and Open MPI through Cygwin. The final step should be to compile running make, however this command is not directly available in Windows 10. As a consequence, I explored the options suggested in this question, unfortunately without success. I feel at a dead end, any help will be appreciated.

What I’ve tried

Please have a look below at my attempts. I am mainly a Windows user and I don’t know much of compiling programs using Makefile. My current understanding is that the Makefile that I am trying to compile is written for Linux and whatever GNU compiler for Windows I use will not work because of the different syntax needed. Please correct me if I am wrong. What I can’t understand is why I get errors also when I try to compile with Ubuntu Bash for Windows 10 (last attempt of the list below).

Visual Studio nmake

Running the Developer Command Prompt for VS 2019 as administrator, I typed nmake -f Makefile in TACS base directory and I got Makefile.in(28) : fatal error U1001: syntax error : illegal character '{' in macro Stop.

enter image description here

Chocolatey make

Running Windows Command Prompt as administrator with C:ProgramDatachocolateybin at the top of PATH environment variable, I typed make in TACS base directory and I got

JavaScript

enter image description here

Cygwin make

Running Windows Command Prompt as administrator with C:cygwin64bin at the top of PATH environment variables, I typed make in TACS base directory and I got three types of error:

JavaScript

I tried to change some variable names in the affected scripts (like N_ in place of _N) and I got rid of the first and the third type of error, but not of the second one.

enter image description here

enter image description here

enter image description here

GnuWin make

Running Windows Command Prompt as administrator with C:Program Files (x86)GnuWin32bin at the top of PATH environment variables, I typed make in TACS base directory and I got

JavaScript

enter image description here

MinGW mingw32-make

Running Windows Command Prompt as administrator with C:MinGWbin at the top of PATH environment variables, I typed mingw32-make in TACS base directory and I got

JavaScript

enter image description here

MSYS MinGW 64-bit make

Running Windows Command Prompt as administrator with C:msys64usrbin at the top of PATH environment variables, I typed make in TACS base directory and I got

JavaScript

This is quite difficult for me to understand, as the mpicxx file is C:Program Files (x86)InteloneAPImpilatestbin, which in turn is in the PATH environment variable. When I tried to add C:cygwin64bin to PATH (below C:msys64usrbin) and to rerun make, I got

JavaScript

I tried to follow these instructions and then rebooted my computer, but nothing changed.

enter image description here

enter image description here

Ubuntu Bash for Windows 10 make

This attempt was inspired by this answer. I downloaded Ubuntu from Microsoft Store and installed make. From the Ubuntu Bash I typed make in TACS base directory and I got

JavaScript

I do not understand why I should get this error. I also made sure that all lines started with a tab rather than white spaces, but nothing changed.

enter image description here

Codes

Below you can find the Makefile.in and Makefile that I am using.

Makefile.in

JavaScript

Makefile

JavaScript

Edit: I am adding a snippet of TACS_Common.mk as requested in the comments.

TACS_Common.mk

JavaScript

Advertisement

Answer

I can’t answer but maybe I can orient you.

First nmake is not make. It will not work with any makefile not written specifically as an nmake makefile. And it’s only available on Windows. So, best to just forget it exists.

Second, it’s important to understand how make works: rules in makefiles are a combination of targets/prerequisites, and a recipe. The recipe is not in “makefile” syntax, it’s a shell script (batch file). So make works in tandem with the shell, to run commands. Which shell? On POSIX systems like GNU/Linux and MacOS it’s very simple: a POSIX shell; by default /bin/sh.

On Windows systems it’s much less simple: there are a lot of options. It could be cmd.exe. It could be PowerShell. It could be a POSIX shell, that was installed by the user. Which one is chosen by default, depends on how your version of make was compiled. That’s why you see different behaviors for different “ports” of make to Windows.

So, if you look at the makefiles you are trying to use you can see they are unquestionably written specifically for a POSIX system and expect a POSIX shell and a POSIX environment. Any attempt to use a version of make that invokes cmd.exe as its default shell will fail immediately with syntax errors (“” was unexpected at this time.).

OK, so you find a version of make that invokes a POSIX shell, and you don’t get that error anymore.

But then you have to contend with another difference: directory separators. In Windows they use backslash. In POSIX systems, they use forward slash and backslash is an escape character (so it’s not just passed through the shell untouched). If you are going to use paths in a POSIX shell, you need to make sure your paths use forward slashes else the shell will remove them as escape characters. Luckily, most Windows programs accept forward slashes as well as backslashes as directory separators (but not all: for example cmd.exe built-in tools do not).

Then you have to contend with the Windows abomination known as drive letters. This is highly problematic for make because to make, the : character is special in various places. So when make sees a line like C:/foo:C:/bar its parser will get confused, and you get errors. Some versions of make compiled for Windows enable a heuristic which tries to see if a path looks like a drive letter or not. Some just assume POSIX-style paths. They can also be a problem for the POSIX shell: many POSIX environments on Windows map drive letters to standard POSIX paths, so C:foo is written as /c/foo or /mnt/c/foo or something else. If you are adding paths to your makefile you need to figure out what the right mapping, if any, is and use that.

That’s not even to start discussing the other differences between POSIX and Windows… there are so many.

From what you’ve shown above, this project was not written with any sort of portability to Windows in mind. Given the complexity of this, that’s not surprising: it takes a huge amount of work. So you have these options that I can see:

  1. Port it yourself to be Windows-compatible
  2. Try to get it working inside cygwin (cygwin is intended to be a POSIX-style environment that runs on Windows)
  3. Try to get it working in WSL
  4. Install a virtual machine using VMWare, VirtualBox, etc. running a Linux distribution and build and run it there

Unfortunately I don’t know much about the pros and cons of these approaches so I can’t advise you as to the best course.

The route I chose, long long ago, was to get rid of Windows entirely and just use GNU/Linux. But of course that won’t be possible for everyone :).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement