I have 2 Fortran source files, the function as the subprogram and the main code for running the program, how can I call the function in the main program?
if using gfortran in Linux we can use
gfortran mainprogram.f90 subprogram.f90
If I use Microsoft Visual Studio how can I write the code?
Related
I have written a prolog program in GNU-Prolog and successfully compiled it , now I want to create an executable file so that the other person only need to click on that file and run the program. I want to know if there is a way to create an executable file from a GNU-Prolog program?
Under Windows, to compile to an executable you need a C compiler toolchain. Depending, on the version you installed, you need the Microsoft C++ compiler (MSVC) or with gcc (provided by MSYS2/mingw64).
For MSVC, you can install Microsoft Visual Studio 2019 Community (version 19.28.29335). Once installed, there are 2 .bat file provided with the MS compiler
e.g. vcvars32.bat and vcvars64.bat. Launch the appropriate .bat to obtain a terminal with PATH sets for MSVC.
For gcc, you should install MSYS2 + the gcc toolchain. More information is available here WINDOWS information (the file details how to compile gprolog on WINDOWS using either MSYS2/gcc or MSVC).
The gprolog compiler is in the bin sub-directory of the GNU Prolog installation (by default C:\GNU-Prolog\bin). You need to add this directory to your PATH.
Go to the directory containing your Prolog file (cd path_to_your_file) and compile it with gplc your_file.pl.
As mentioned by Paulo, you'll find more information on options you can pass to gplc in the online manual.
My project is built by builbot using cmake and the Visual Studio C++ compiler.
Using "Visual Studio 14 2015 Win64" as generator it works but it builds slowly and I have difficulties to find the source of an error (this is another problem).
So I want to try Ninja but when I set it as the generator it selects the GNU C++ compiler. I found that I should load the vcvarsall.bat before calling Ninja but I don't understand how to do it from buildbot.
The solution was to:
Load vcvarsall.bat as I wrote in the question and suggested by #valiano
Do it using buildbot as suggested in this blog post
Ensure to find the Visual C++ compiler instead of gcc using CMAKE_IGNORE_PATH as suggested in the question linked to by #Florian
Point 2 summarizes in editing the buildbot.tac file of the worker by adding the following lines:
from subprocess import check_output
for v in check_output(['path\\to\\vcvarsall.bat',
'x86', '&&', 'set']).strip().split('\r\n'):
v = v.split('=', 1)
os.environ[v[0]] = v[1]
I am trying to compile a C program using CeGCC, the program is written in C using Win32 API, and it's being compiled with MingW like this:
gcc -o "Win32App.exe" obj/winmain.o obj/callbacks.o obj/resource.o -s -lcomctl32 -Wl,--subsystem,windows
As a result the program is successfully compiled and then tested afterwards. The problem occurs when i try to compile it for ARM (Windows-CE) rather than x86-based architecture:
obj/winmain.o:winmain.c:(.text+0x24): undefined reference to InitCommonControlsEx
obj/winmain.o:winmain.c:(.text+0xe0): undefined reference to RegisterClassExW
As you can see the problem is that the two functions called InitCommonControlsEx and RegisterClassExW are not defined in Windows-CE.
My Question is how can i find an equivalent function to use in my code so that i can successfully compile and run my program in Windows-CE. I need help in replacing those two functions with compatible ones which are recognized in CeGCC.
program test
implicit none
open(100, file="a.dat", status="replace")
end program test
When I try to run this program, it runs fine the first time when the file has not been created. But an attempt to run the program again (when the file a.dat exists and should be replaced) gives segfault error. Here is what I found using gdb.
Program received signal SIGSEGV, Segmentation fault.
0x00007ff95deb1150 in strcmp () from C:\Windows\system32\msvcrt.dll
I am using GNU Fortran (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 5.1.0 with target as Target: x86_64-w64-mingw32. I didn't use any extra compiler flags except -g.
Also since gdb mentions Windows system files, here is which OS I use - Windows 8.1
I am trying to run FFTW code in a mex file. This is strictly for the purpose of development and testing. After some googling, I see that others have tried to do something similar and have had related problems, but I have not found any solutions. When attempting to run the mex file, Matlab tells me:
??? Error using ==>
chirpTransform.mxCta Invalid MEX-file
'\removed\my\directory\+chirpTransform\mxCta.mexw32':
The specified procedure could not be
found.
.
I am using gnumex with MinGW to build the mex file because LCC seems to have some issues. I have tried using the 32 bit DLL from the FFTW site (http://www.fftw.org/install/windows.html). I have tried using the fftwf3.dll in the Matlab 2009b bin directory. I built the dll from source using Msys/MinGW. In all cases, the results are the same. In all cases I did the following to generate the lib file.
c:\gnumex\mexdlltool.exe -d
libfftw3f-3.def -D libfftw3f-3.dll -l
libfftw3f.lib --as C:\MinGW\bin\as.exe
I also tried using the visual studio lib.exe tool and experimented with various mexdlltool flags.
It appears that I can directly call functions in the fftwf3-3.dll using Matlab's loadlibrary functionality. Since the DLL appears not to be the problem, I tried building a static version of fftwf3 and linking it directly into the mex file. I got the same results! If I remove the FFTW code, the mex file runs fine. I have just about given up at this point, and I am tyring to come up with alternative methods of testing.
I've run into this issue with other mex functions. In my experience, it typically means that there is a dependency issue. Some dependency is not located.
Here is a link to TMW's documentation on this issue:
Invalid MEX-File Error
Give it a read, and then try using dependency walker to diagnose the problem.
It's been a long time, and my setup has changed, but this works for me now. I suspect hoogamaphone was right. I probably didn't have the fftw dll in the same directory as the mex dll (and it wasn't in my path). In fact, 64 bit Matlab 2016a still gives you a warning about not being able to find the mex file when, in fact, it's a dependency that's missing.
My current setup is using the Visual Studio 2013 C++ compiler by default. As mentioned on the fftw web site, you need to generate a lib file for linking. You can run the Visual Studio command prompt from a regular command prompt like so:
"%VS120COMNTOOLS%VsDevCmd.bat"
Then run the following in the directory with the def file.
lib /machine:x64 /def:libfftw3f-3.def
And compile.
mex mxCta.c cta.c -I../fftw -L../fftw -llibfftw3f-3.lib
Perhaps another possibility is that gnumex introduced some dependency into the mex dll. I no longer recall whether I had used gnumex successfully testing other code. When using cygwin, if you don't use the mingw compiler (x86_64-w64-mingw32-gcc), you'll end up with a dependency on the cygwin1.dll.
Finally, if you use more than one compiler, make sure all the compiler flags are the same (same function calling conventions, ABI, etc). Also, Mathworks has changed the mex build procedure. In a recent project, I copied mexconfig.xml to my local directory from
C:\Users\myuser\AppData\Roaming\MathWorks\MATLAB\R2016a\mex_C_win64.xml
and edited the compiler flags like so:
COMPFLAGS="/Zp8 /GR /W3 /EHs /nologo /MD /Gz /TC"
If you use a custom build file, use the -f option.
mex mxCustom.c custom.lib -f mexconfig.xml