Creators of Quality Software

  Randy and Alysia Schwarz

  P.O. Box 1308

  Richland, WA 99352

 

Converting to Visual Studio 2008 from Visual Studio Version 6.0 in a Mixed Language Environment.

To download this page as a .pdf file, Click Here.

SUMMARY

This article details the steps performed to convert our software from Visual Studio 2008 to Visual Studio 6.0.  Our software uses both C++ Code and Visual Fortran.

I have been using Compaq Visual Fortran 6.6  and Visual Studio 6.0 for years.  I finally decided it is time to do whatever it takes to upgrade to the latest Fortran and C++ compilers.  In the process I found that there is not that much information on how to efficiently do this and how to overcome problems along the way.  There are some simple examples of mixed Fortran programming, but they were not quite complex enough to address the problems that I was encountering.  Also, there is some documentation on mixed language programming and integrating with Visual Studio IDE.  You should review all of this documentation if you can find it.

 

I am posting this in the hopes that you may learn from my experiences.  I upgraded to Visual Studio 2008 and Compaq Visual Fortran 10.1.

 

My code consists of 10 of thousands of lines of C++ codes with comparable amount of Fortran code.  The Fortran code is compiled as the primary project and the C code is compiled as a static object library in a C++ dependent project.

 

Under CVF/VS6 the code compiled in about 1 and a half minutes on my computer.  After the upgrade to VS2008/INTEL10.1 it now compiles in about 5 and a half minutes.  This is over three times longer. 

 

Below of the key things to keep in mind when changing from CVF/VS6 to the new compilers:

 

  1. You need to install the Intel Fortran compiler before the Visual Studio compiler or Visual Studio will not recognize the Fortran compiler in the visual environment.  If have both VS2005 and VS20008 installed on my system and Intel Fortran works with both of them.

 

To determine if you have installed the compilers correctly, Select File->New Project and verify that Intel Fortran is an option.

 

Conversion Story 1

Click for a larger image. 

 

 

  1. By far the easiest way to convert from CVF6.6/VS6 is to use the upgrade tools that are provided.  I was hesitant to do this at first, but there are so many options that needed to be tweaked by hand that it takes a long time to determine the right combination and the upgrade tools take you most of the way.   To do the automatic upgrade do the following:

 

a)      In Visual Studio select the dsw file for the CVF project. 

Conversion Story 2

Click for a Larger Image 

 

b)      You will then be prompted to convert the project:

Conversion Story 3

c)      Select Yes, since I am doing both a Fortran and C linked project , it will ask to convert the second dependent project.

Conversion Story 4

d)     Select Yes, then select Project->Extract Compaq Visual Fortran Project Items.

e)      This will complete the conversion process.  Now do a rebuild all and resolve any remaining issues that you encounter

  1. Additional items that I had to address for my project are included below:

a)      In the C++ files replace

#include <fstream.h>

with

#include <fstream>

using namespace std;

 

b)      In the C++ files replace

#include <iostream.h>

with

#include <iostream>

using namespace std;

 

c)      If the VS6/CVF project had additional include directories set in VS6 (Tools->Options->Directories), you need to set them in the project. 

a.       Right click on the Fortran project

b.      Select properties.

c.       Select the Fortran->General page

d.      Set the include directory under Additional Include Directories

e.       For my case:

F:\MCNPX_projects\MCNPX_SRC\MCNPX26E\v26e\src\include

 

d)     The Fortran Preprocessor Definitions did not get converted correctly, need to add a ; after each definition in the Project.

a.       Right click on the Fortran project

b.      Select properties.

c.       Select the Fortran->General page

d.      Add semi-colons in Preprocessor Definitions

 

e)      In the VS6 Project I had added the CVF Fortran librarydformt.lib to link to (Project->Settings; Link tab).  Remove this from the INTEL/VS2008 project.

a.       Right click on the Fortran project

b.      Select properties.

c.       Select the Linker->Input

d.      Remove the library dformt.lib from Additional Dependencies

 

f)       When Linking I get the errors:

1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)

1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)

1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)

a.       This is because of the order that the libraries are linked:

http://support.microsoft.com/kb/148652

b.      Right click on the Fortran project

c.       Select properties.

d.      Select the Linker->Input

e.       For Ignore Specific Library add:  nafxcwd.lib;Libcmtd.lib

f.       For Additional Depdencies add:   nafxcwd.lib Libcmtd.lib  ( now semi colon here)

 

g)      After making the above change I still get the error:

1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in Libcmtd.lib(dbgdel.obj)

a.       Not sure why I get this error, so use /FORCE on the command line to force the code to link.

b.      Right click on the Fortran project

c.       Select properties.

d.      Select the Linker->Command Line

e.       Add /FORCE to the command line to force a link.

 

h)      For the error:

 

error LNK2019: unresolved external symbol _SIGNAL@12 referenced in function _TTYINT

 

add:

 

      use IFPORT to the Fortran program

 

i)        For the error:

error LNK2019: unresolved external symbol _GETENV@16 referenced in function _MCNP

 

add:

      use IFPORT to the Fortran program

 

j)        For the error:

error LNK2019: unresolved external symbol _ETIME@4 referenced in function _SECND

 

add:

      use IFPORT to the Fortran program

 

k)      If the compiler then complains Please specify the name of the executable file to be used for the debug session: then Select browse and browse to the location of the executable (not sure why it can not find it on its own).


Create by Hand:

 

If you decide you do not want to do the automatic update, you can do the conversion by hand.  Below are the options I needed to set to get my code to work with the new compilers.   Some of these options are specific to my program, but others are generic to the conversion process.

 

1.      Create new project Fortran->Windowing Application->Empty Project

2.      Set the name and directory (Name: and Location: )

3.      Create directories and add files to the Fortran Project

4.      Under Fortran->General

  a.       Additional Include Directories:  F:\MCNPX_projects\MCNPX_SRC\MCNPX26E\v26e\src\include

  b.      Preprocessor Definitions:

INTEL; VISCOLORS; CINDER; DEC; XS64; MESHTAL; RADIOG; CEM; HISTP; SPABI; DFACT; INCL; VECAD; VISED; PLOT; MCPLOT; GKSSIM; CHEAP

5.      Under Fortran->Preprocessor

  a.       Preprocess Source File:

Yes

6.      Under Fortran->Diagnostics

  a.       Generate Interface Blocks:

        No

  b.      Check Routine Interfaces:

       No

7.      Under Fortran->Data

  a.       Local Variable Storage

      All Variables Save (/Qsave)

8.      Under Fortran->External Procedures

  a.       Calling Convention

     CVF(/iface:cvf)

9.      Under Fortran->Run-time

  a.       Check Array and String Bounds

     No

10.  Under Linker->Input

  a.       Additional Dependencies

     nafxcwd.lib Libcmtd.lib OPENGL32.LIB GLU32.LIB Htmlhelp.lib

  b.      Ignore Specific Library

     nafxcwd.lib;Libcmtd.lib

11.  Under Linker->System

  a.       Heap Reserve Size

     83886080

  b.      Stack Reserve Size

     67108864

  c.       Enable Large Addresses

     Support Addresses Larger than 2 CB (/LARGEADDRESSAWARE)

12.  Under Linker->Command Line

  a.       add

     /MACHINE:I386 /FORCE

 

1.  Create new project Visual C++->MFC->MFC DLL

  a.       Set Name: to

     vislib

  b.      Set Solution: to

     Add to Solution

  c.       Select Finish

2.      Delete any .c and .h files that have been created

3.      Add the c files to the project (Add->Existing Item).

4.      Under General

  a.       Configuration Type

     Static Library (.lib)

  b.      Use of MFC

     Use MFC in a Static Library

  c.       Character Set

     Use Multi-Byte Character Set

5.      Under Debugging

  a.       Command

     F:\MCNPX_projects\VISEDX_23E_VS2008\visedX23E\Debug\visedx23e.exe

6.      C/C++->Preprocessor (C/C++ will not show up if you have not added files)

  a.       Preprocessor Definitions

     Remove _USRDLL

7.      C/C++->Code Generation

  a.       Runtime Library

     Multi-threaded Debug (/Mtd)

      (Multi-threaded /MT on Release)

8.      C/C++->Precompiled Headers

  a.       Create/Use Precompiled Header

      Not Using Precompiled Headers

9.      Right click on the Fortran Project

  a.      Select Project Dependencies

      Click on the vislib check box

10.  Right click on the Fortran Project and add a vised files  directory

  a.       Add

Vised2.rc

 

Randy Schwarz

 


Contact Information

Email: randyschwarz@mcnpvised.com