Closed lavender-lee closed 1 year ago
It'll be a while before I can find the time to look at this (Windows is not my main system), but this is very likely because of a bad compiler configuration. MinGW-w64 is not officially supported by Mathematica. Setting all command-line options is not trivial. For example, the flags to link to the MathLink libraries are missing. As I remember, the .lib
files supplied with Mathematica had to be converted to .a
ones to work with MinGW, and there were some subtleties with that. I haven't tried to set up MinGW with Mathematica in many years.
Generally, DON'T use MinGW unless you have a really good reason to do so. Use MSVC instead.
Thanks szhorvat. The reason I use MinGW-64 is just avoiding installing Microsoft Visual Studio 2015. It is very large(5G in C disk and 3G in the install-path). Maybe I can use the code that generated from LTemplate and then build a project via CMake in CLion. Anyway thanks for guiding.
and then build a project via CMake
I don't think that will make a difference here. The issue is still to use the correct command line flags, linking the appropriate libraries, and make sure that the libraries are in a format compatible with this toolchain.
This is also not LTemplate specific: the same problems would come up when compiling any LibraryLink stuff. What makes LTemplate a bit more demanding is that it uses C++ and that it requires linking to MathLink (that's not necessary for libraries that don't use any MathLink functions).
Hello @ShutaoTang and @szhorvat ,
I found that this problem can be easily solved.
First, set MinGW64 g++
as C
compiler (Not gcc.exe
)
<< CCompilerDriver`GenericCCompiler`
$CCompiler = {"Compiler" -> GenericCCompiler, "CompilerInstallation" ->
"C:\\opt\\mingw64\\bin", "CompilerName" -> "g++.exe"};
Note: Unfortunately, this may render Compile[]
unavailable.
Second, We specify the location of ml64i4.dll
and WolframRTL.dll
in CompileOptions
, as follow,
CompileTemplate[template, "CompileOptions" ->
"C:/opt/MMA/ml64i4.dll C:/opt/MMA/WolframRTL.dll"]
You can find ml64i4.dll
and WolframRTL.dll
in [Mathematica Installation Directory]\SystemFiles\Libraries\Windows-x86-64
. Because this path is too long, I copied them to C:/opt/MMA/
.
Now, we can use MinGW64 to compile code.
My platform information as follows:
@K-JW Interesting and thanks for sharing this:)
If the Mathematica version is not 11.3, then the following error may be reported:
CreateLibrary::cmperr: Compile error: D:\Program Files\Wolfram Research\Mathematica\12.1\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions/mathlink.h:641:9: error: '__int64' does not name a type; did you mean 'wint64'?
Please add additional compilation flags: -D__int64="long long"
.
CompileTemplate[template, "CompileOptions" ->
"C:/opt/MMA/ml64i4.dll C:/opt/MMA/WolframRTL.dll -D__int64=\"long long\""]
That's all. hope it is helpful.
I can't comment much on this today (deadlines...) but please try using the MinGW driver, not the GenericCompiler driver. I know that's not what the documentation says, but the documentation is outdated.
Setup compiler as MinGW64 as follows:
However, when I compile the code in tutorial of LTemplate, it gives the error
collect2.exe: error: ld returned 1 exit status