Group Abstract Group Abstract

Message Boards Message Boards

Find gcc compiler using Mathematica V12?

POSTED BY: Eric Michielssen
16 Replies
Posted 5 years ago

Can you tell me why Wolfram Research doesn't support a compiler as widely used as gcc ?

Original developer of CCompilerDriver here. Szabolcs is right (as usual), it's not a question of gcc, which we've supported on Unix from the beginning, but MinGW gcc on Windows 64-bit, which boils down to why doesn't MinGW support gcc on 64-bit, though there is a 64 bit port that you can use, and using that is documented.

What you're reporting is the automatic compiler finding behavior, and also running into the fact that MinGW's C compiler driver is only loaded on 32-bit Windows, for a good reason. At the time this was added, MinGW did not produce 64 bit binaries, and that is required to load the binaries into the Mathematica kernel on a 64 bit OS, which is what happens with CompilationTarget -> "C" option of Compile, or the CreateLibrary function in general.

I've passed this thread on the CCompilerDriver maintainer, to see if anything can be done. But in the interest of helping, here's what I see.

It looks to me like MinGW's gcc still only produces 32 bit binaries. I downloaded MinGW onto my 64-bit Windows 10 machine and compiled hello, world, and it looks to still be 32 bit:

$ file hello
hello: PE32 executable (console) Intel 80386, for MS Windows

You can ignore this and try loading the driver's package:

Needs["CCompilerDriver`MinGWCompiler`"]

For me, after this point CCompilers[] is detecting the compiler. However, it does not work (as expected):

In[6]:= CCompilers[]

Out[6]= {{"Name" -> "Visual Studio", "Compiler" -> 
   CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler, 
  "CompilerInstallation" -> "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools", 
  "CompilerName" -> Automatic}, {"Name" -> "MinGW", "Compiler" -> MinGWCompiler, 
  "CompilerInstallation" -> "C:\\MinGW\\bin\\gcc.exe", "CompilerName" -> Automatic}}

In[16]:= $CCompiler = Last[CCompilers[]]

Out[16]= {"Name" -> "MinGW", "Compiler" -> MinGWCompiler, "CompilerInstallation" -> "C:\\MinGW\\bin\\gcc.exe", "CompilerName" -> Automatic}

In[17]:= cf = Compile[{{x, _Real}}, Sin[x] + x^2 - 1/(1 + x), CompilationTarget -> "C"]

During evaluation of In[17]:= Compile::nogen: A library could not be generated from the compiled function.

Out[17]= CompiledFunction[{11, 12.1, 5468}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {{1, {2, 0, 0}}}, {0, 1, 5, 0, 0}, {{40, 1, 3, 0, 0, 3, 0, 1}, {40, 
  56, 3, 0, 0, 3, 0, 2}, {10, 0, 3}, {13, 3, 0, 3}, {40, 60, 3, 0, 3, 3, 0, 4}, {19, 4, 3}, {13, 1, 2, 3, 1}, {1}}, 
Function[{x}, Sin[x] + x^2 - 1/(1 + x)], Evaluate]

I think, the if you want MinGW/gcc, you need to use the MinGW-w64 project.

The documentation talks about how to use this, look for the section "MinGW for 64-bit targets":

https://reference.wolfram.com/language/CCompilerDriver/tutorial/SpecificCompilers.html

This also shows how to use the "GenericCCompiler" driver, which you can use for any C compiler. It just didn't get found automatically but you can still use it by telling the system where it lives.

POSTED BY: Joel Klein
POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát
POSTED BY: Eric Michielssen
POSTED BY: Szabolcs Horvát

wstp.h ( from WSTP ) use MSVC specific __int64 type.

I want to use pari and gap functions in Mathematica through WSTP.

But parilib and libgap require the gcc compiler.

Any suggestions?

POSTED BY: nilo de Roock

Unfortunately, I do not know the answer to this. I rarely use Windows these days, and when I do, I usually install the Visual Studio command line tools, even if they are large.

POSTED BY: Szabolcs Horvát
Posted 5 years ago

Szabolcs,

I'm a bit confused on which version of VS one needs and what packages/extras are required. I've donwloaded VS 2015 build tools for Win7, but Mathematica still does not recognize a C compiler. I could download VS 2019 build tools, but according to the installer it is huge (4+ GB). This seems to be an absolute overkill just to have a C compiler. In the meantime, I've managed to make Mathematica recognize MinGW gcc (alltogether 440MB). Do you have any idea on how to install a minimal VS C compiler that is considerably less than 4GB in overall size and that is immediately recognized by Mathematica?

POSTED BY: Updating Name
Posted 6 years ago

Thanks

POSTED BY: Haobo Xia

MathOptimizer Professional is a Mathematica interface to the standalone optimization code LGO and therefore does not use CCompilerDriver. It uses Format.m to convert the Mathematica objective functions and constraints to Fortran or C and then uses a DOS call to call the compiler.

POSTED BY: Frank Kampas
POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát
POSTED BY: Frank Kampas

MathOptimizer Professional

https://www.wolfram.com/products/applications/mathoptpro/

uses a C or Fortran compiler to evaluate the objective function and constraints. It runs 7 or 8 times faster with GCC as the C compiler as compared to using Visual Studio as the C compiler.

POSTED BY: Frank Kampas

In that case, I'd be very interested in getting it to work. Any idea where I may be going wrong? (see my first post.) Thanks.

POSTED BY: Eric Michielssen

I've used both Visual Studio and gcc. gcc is 7 or 8 times faster.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard