Run MinGW in Mac?

Hi,
How can i run Min GW in Mac, do I need to rearrange these codes to make it run in Mac?

Can anyone please advise?

I posted the codes below.

Clear["Global`*"];
Needs["CCompilerDriver`GenericCCompiler`"];
$CCompiler = {"Compiler" -> 
    CCompilerDriver`GenericCCompiler`GenericCCompiler, 
   "CompilerInstallation" -> "C:\\MinGW", "CompilerName" -> "gcc.exe"};
CompileOptions = {CompilationTarget -> "C", 
   RuntimeOptions -> {"CatchMachineOverflow" -> False, 
     "CatchMachineUnderflow" -> False, 
     "CatchMachineIntegerOverflow" -> False, 
     "CompareWithTolerance" -> False, "EvaluateSymbolically" -> False,
      "RuntimeErrorHandler" -> Evaluate, "WarningMessages" -> False}, 
   CompilationOptions -> {"InlineExternalDefinitions" -> True, 
     "InlineCompiledFunctions" -> True, 
     "ExpressionOptimization" -> True}};

Thanks.

Hi Adrian,

You probably won’t need MinGW as there is Terminal on the Mac. If you have an english system it should be in /Applications/Utilities/Terminal so I would try to replace "C:\\MinGW” with “/Applications/Utilities/Terminal” and “gcc.exe” with “gcc”.

Kind regards,

Peter

Hi Peter
I tried your suggestion but it didn’t work either and gave the same error.

Hi Adrian, can you specify the error in detail? Do you have gcc installed? Open the Terminal application and enter gcc and hit return, do you get an error? If yes, you need to install gcc first (e.g. with brew https://brew.sh)
kind regards, Peter

Hi Peter
the error :
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>
CreateLibrary::instl: The compiler installation directive “CompilerInstallation” → /Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler. >>
Compile::nogen: A library could not be generated from the compiled function. >>

Then,
I changed the compiler installation directory to
/usr/bin
it does not show error
but the compilation still does not work.

Hi Adrien, can you test in terminal if you have gcc installed (see my previous post). One of the messages indicates that you have not…
/Applications/Utilities/Terminal does not indicate a usable installation of Generic C Compiler
kind regards, Peter

Hi peter
im not sure if you mean to check it this way.
I checked in terminal
Adrian-MM:~ user$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Adrian-MM:~ user$

Hi Adrian, hmm it seems that you have gcc installed, I just have the idea, that you might need a C compiler instead of gcc so try “clang” instead of “gcc”.
kind regards, Peter

Hi Peter,

Adrian-MM:~ user$ clang --version
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Adrian-MM:~ user$

Im not sure what is going wrong, xcode is installed also.

Hi Adrian, ok, what happens if you use “clang” instead of “gcc” in your mathematica script?
kind regards, Peter

Hi Peter, the compile sheet does not show error.

I need to cross check on my windows computer to see if the other sheet that requires this compilation to run is working properly.

I will write again.

Regards
Adrian

Dear Peter,
Sorry for the long wait.
I found a useful post in this matter,
https://www.daniweb.com/programming/software-development/threads/66450/mingw-equivalent-for-osx

I’m working on it to see if it works…

There is no MinGW for macOS. You need to install Xcode from the Mac App Store instead. Once it’s installed start it, and allow it to install the command line tools. Finally, test that clang (the compiler on macOS) works in a terminal.

After this, it will work with Mathematica without any special setup (i.e. do not create a special configuration).

Just try the examples for the CCompilerDriver package.

There is no MinGW for macOS.

Technically there is (for cross-compiling), but that is not really relevant for OP’s problem.

I know, I actually tried to use it once for cross-compiling … but it seemed more helpful to say that there isn’t, since OP doesn’t want to cross-compile.

Thanks for reply, Ilian.
But can the codes be modified to run gcc ?

I tried “Name:gcc…Automatic” compile driver
but it doesn’t work.

I should be able to just replace it according to given line of compiled driver and run but it doesn’t work either.

Is there any reason why you insist on setting up gcc instead of using the native compiler on macOS, i.e. clang, which comes with Xcode and requires zero configuration to get it working in Mathematica?

Thanks for reply, Szabolcs.

Ya, its annoying and confusing.

im trying to run a model written by my friend to simulate some experimental data i measured. he told me that i need to run the compiler first in gcc. he wrote it in windows which needs MinGW package.

Alternatively, I would like to know how to do it with clang in mac using the same file as im using mac, i don’t want to boot camp my laptop. it sounds like a better method. i looked around but i don’t understand how the native compiler in macOS works. I installed Xcode but i don’t know how one can run native compiler on a mathematica nb without opening it and evaluate cell containing the compiler in terminal.

I really appreciate it if there’s instructions how to do it.

Ya, also now I learned that there’s no MinGW is not available in Mac, the thread title is misleading as well. I guess it’s fine.