Compiling a Fortran .dll on Windows 7 (for free)? - windows

My boss just asked me to integrate his bosses old Fortran code into a project (Java) I'm working on. The code was written in the 90s, so I imagine it'll still compile, so rather than re-write it, I'm hoping I can just call the functions from a .dll. I'm already calling some C .dlls, so I think I've got that part covered.
I've been doing some reading, and most of the articles talk about integrating the Intel Visual Fortran Compiler into Microsoft Visual Studio. We've got a university site license for Visual Studio, but it looks like the Intel Visual Fortran Compiler is in around the $700 range. I don't think my boss will go for that, so I'm looking for another option. I know Microsoft makes a lot of products freely available to students via Project Dreamspark, but I didn't see anything Fortran related.
I'm looking at some cygwin based options right now (g95, I think), but I'm looking for other ideas/options. Any ideas?

I've used the gfortran (g95) compiler with the -shared flag to create DLLs. first compile the .for/.f90 files with:
gfortran -c myfile1.f90
gfortran -c myfile2.f90
then:
gfortran -shared -o mydll.dll myfile1.o myfile2.o

MinGW will let you create a DLL that will work with your MS stuff.

Look for a GCC port to Windows, such as Mingw or GCW. Both those will create .obj files which can be linked to in Visual Studio. Or you could futz around and configure VS to invoke one of those command line compilers into the project. But since the code is relatively static, it might be a nice compile once and forget it task, hopefully.

Don't expect much help from Microsoft on Fortran.
They spent years trying to kill it off in favour of Visual Basic / C.
You could try Silverfrost's compiler.
http://www.silverfrost.com/11/ftn95/ftn95_fortran_95_for_windows.aspx
This is available free ('personal edition' version) and works with Visual Studio.
It's basically a F90/F95 compiler with a selection of later features included.
You did not say if the old boss' code was written in F77 or F90.
But I think that Silverfrost will handle the old code with minimal changes.
If it turns out well for you, there's also an academic version and an enterprise edition to move up to as desired.

Related

How to compile a DLL without using Visual Studio?

That sounds a stupid question, but I'm really curious about how to compile a DLL without using Visual Studio since I'm using Unity3D OS X for now. Is there some way like "tool chain" can do the trick?
Any solution is appreciated except Ask your friend/colleague to compile it for you or buy another computer/install windows/using remote control.
Build a cross tool chain of Mingw. However, be aware that you can not link C++ libraries between compilers, or often even compiler versions. Only DLLs with a C calling interface will work. (They can internally use C++ but must expose a C API.)
Or you could try running Visual Studio in Wine. VS2010 has bronze support in Wine, i.e. the compiler works.

How to use GCC with Microsoft Visual Studio?

I am creating a very large project (a few thousand lines) and so would rather not use Notepad++. An IDE would make it so much easier. I have experience with Microsoft Visual Studio and love it. Is there some easy way to use Cygwin's GCC from within Microsoft Visual Studio?
Alternately, are there any other good Windows IDEs for GCC besides NetBeans and Eclipse? (I hate both of them with a passion.)
There are several ways to go here:
Option 1: Create a Custom Build Tool
Visual Studio 2005 and newer will let you register custom build tools. They tell the IDE how to transform files of one form (e.g. a .cpp file) into another form (e.g. an .obj file).
So far as I know, no one has done this yet for GCC. And, doing it yourself requires writing COM code, which is probably too deep a pool to dive into just for a single project. You'd have to have a compelling reason to take this project on.
You then have to manually adjust each project to tell it to use the custom build tool instead of the default, since you're using a file name extension (.cpp, probably) that Visual C++ already knows about. You'll run into trouble if you try to mix the VC++ and g++ compilers for a single executable built from multiple modules.
On the plus side, if you were looking to start an open source project, this sounds like a good one to me. I expect you'd quickly gather a big user base.
Option 2: Makefile Project
Start Visual Studio and say File > New Project.
In the Visual C++ section, select Makefile Project
Fill out the Makefile Project Wizard:
Build command line: make
Clean commands: make clean
Rebuild command line: make clean all
You can leave the Output (for debugging) field alone if you've named your executable after the project name and it lands where Visual Studio expects to find it.
Leave the rest of the fields alone unless you know what they are and why you want to change them. As an example, you might choose to pass a -D flag on the Preprocessor definitions line to get separate debug and release outputs. If you know you want this, you know how to set it up, so I'm not going to make this long answer even longer in order to explain it.
You'll be asked the same set of questions for the Release build. If you want to bother with separate debug and release builds, you'd make any changes here.
Having done all this, you still have to create the Makefile, and add a make.exe to your PATH. As with the debug vs. release question, going into that level of detail would push this answer off topic.
As ugly as this looks, it's still easier than creating custom build tools. Plus, you say you need to port to Unix eventually, so you're going to need that Makefile anyway.
Option 3: Cross-Platform Development
You say you want to port this program to Unix at some point, but that doesn't mean you must use GCC on Windows now. It is quite possible to write your program so that it builds under Visual C++ on Windows and GCC/Makefiles on *ix systems.
There are several tools that make this easier. One very popular option is CMake, which is available as an installation time option in newer versions of Visual Studio. There are many alternatives such as SCons and Bakefile.
Clang
You can use the Clang compiler with Visual Studio to target Android, iOS, and Windows.
If you are targeting Android, you can use the Clang/LLVM compiler that ships with the Android NDK and toolchain to build your project. Likewise, Visual Studio can use Clang running on a Mac to build projects targeting iOS. Support for Android and iOS is included in the “Mobile Development with C++” workload. For more information about targeting Android or iOS check out our posts tagged with the keywords “Android” and “iOS”.
If you are targeting Windows, you have a few options:
Use Clang/LLVM; “Clang for Windows” includes instructions to install Clang/LLVM as a platform toolset in Visual Studio.
Use Clang to target Windows with Clang/C2 (Clang frontend with Microsoft Code Generation).
GCC
If your project targets Linux or Android, you can consider using GCC. Visual Studio’s C++ Android development natively supports building your projects with the GCC that ships with the Android NDK, just like it does for Clang. You can also target Linux – either remotely or locally with the Windows Subsystem for Linux – with GCC.
Check out our post on Visual C++ for Linux Development for much more info about how to use Visual Studio to target Linux with GCC. If you are specifically interested in targeting WSL locally, check out Targeting WSL from Visual Studio.
Source: https://devblogs.microsoft.com/cppblog/use-any-c-compiler-with-visual-studio/
I'm from the future.
I keep (poking at) a C/C++ toolchain using Visual Code on Win/Lin/Mac and MinGW installed from Choclatey.
(This was done for my sanity - install GDB and GCC however you want)
I've run it with GCC and GDB with IntelliSense using MS's own weird JSON makefiles.
Someday, someone (you?) will write a Gradle or Python script to generate these; for now the examples online in the docs seem to work.
It seems to require three types of JSON thing;
a single IntelliSense configuration for the whole workspace
a Debugging Configuration entry for each binary you want to debug
these can invoke the build tasks
a Build Task per-artifact
I don't think that there's a "require" or "dependency" thingie-mah-bob; sorry

Is it possible to link the Matlab compiler to Visual C++ compiler?

I am using Matlab 2010 and VS2010.
I have the Matlab Compiler Runtime installed in my system.
Whenever if run command mcc -setup I get only one compiler lcc. This compiler gives a lot of errors when used to build a C++ shared library using deployment tool. It builds only C Shared libraries correctly.
Can I also connect VC++ compiler with MCC ????
How should I do that ??
Have you read this article? Especially note 2? They are talking about a similar bug there.
PS
Matlab interacts with compilers using mexopts files, located in
matlabroot\bin\win64\mexopts\
So, you may add virtually any compiler yourself.
Some mexopts are available through Mathworks fileexchange.
If you've got access to newer matlab installation, you can get mexopts from there.
You can write your own set of mexopts, based on existing files. In genereal, it's rather easy make, say VS2010 mexopts out of VS2008 ones.
Here's an official article on this.
There is an issue with Matlab 2010 and VS2010. It seems like Matlab was released before VS and therefore it does not have automatic way of configuring VS2010.
I ran into this issue once and my best advice is to download VS2008 express edition...
It's lame, but its the quickest way to get Matlab 2010 working with VS.
Sorry.

CLang libc, libc++ on Windows with debugging symbols compatible with Visual Studio

I'm trying to find info and I don't see it on clang web site.
I'm thinking to try to use it on windows, but I have no clue if it has it's own libc or it uses broken libc from MS?
another question: if i compile code with clang, will I be able to use visual studio as a debugger, e.g. is clang capable of emitting debugging symbols in MS format (this is the reason I don't want to use gcc; and this is something that intel compiler can do, but it uses MS's libc).
In short, I'd like to be able to use visual studio as a debugger, but I need at the same time decent real c compiler with normal lib c.
or, perhaps, there are commercial alternatives. I've read that dinkum sells commercial libc for Win32 and others, but I have no clue what's the price and how to get it.
You have asked two completely different questions. I will answer the one about using Visual Studio as a debugger.
This is not currently possible. Microsoft has not released any documentation or code necessary to produce files in their PDB format, which is what Visual Studio consumes. There has been some reverse engineering efforts, but results of those have not yet made their way into general Open Source tools.
Neither GCC nor Clang are capable of producing PDB files, and hence do not work with Microsoft's debugger. Some of the commercial compilers have support for generating or consuming PDB, but not the Free/Open compilers like GCC and Clang.
You can use other IDEs on Windows which support the DWARF debugging format, used by GCC and Clang. Such compilers include Code::Blocks and Eclipse CDT.

gcc compiled code on visual studio

Assume I have source code for a lib/tool that works on gcc compiler. Can I use the same code and compile it in visual studio. will that be possible at all? If it is possible, how do I do it?
if you are just using all the standard C/C++ library like stdio.h, stdlib.h, etc. it should work fine. Pure console program should work fine. If you used some GUI related library (especially if you are porting over from unix to window) then it might not work.
To do so, you can simply just create a new project in visual studio and add the existing source code into the project workspace. Compile it, if you encounter any error, just post here or try solve if you know how
It depends on your code, GCC support a variant of C (C99) which Visual Studio doesn't support yet.
If your trying to compile a Unix program on Windows you best bet will be to use Cygwin.
Check this question for pointers on using Cygwin in Visual Studio.

Resources