Richard Gilmore's Research: Setting up Compiling for UDFs ANSYS Fluent on Windows 7

Checking for Installed Windows SDKs with Compilers and Uninstalling

Go to Control Panel, Programs, Programs and Features. Check to see if you have "Microsoft Visual C++ Compilers 2010 SP1 Standard - x64" (and x86). If so skip installation and run the SetEnv.Cmd as instructed below. In the list of programs look for all the "Microsoft Visual C++ 2010" and uninstall them (a few are shown below).

    Uninstall MS Visul C++ 2010

Download: "Microsoft Windows SDK for Windows 7 and .NET Framework 4" by copying and pasting this link.

https://www.microsoft.com/en-us/download/details.aspx?id=8279

Run the installer program "winsdk_web.exe" (may take 20sec to start downloading and running). If the Error screen "Some components cannot be installed and require .NET Framework 4", fix this later and continue with the installation. Uninstall any compenents that maybe requested by right clicking on the setup.exe for the compenents and selecting uninstall. During install UNSELECT "Visual C++ Compilers" and Microsoft Visual C++ 2010" (see below), leaving only "Windows Headers and Libraries" and "Tools" seleced, then continue with the installation.

    Unselect Compilers and MS Visul C++ 2010

If you had the error above check to see if you have .NET 4.7.1 installed, uninstall it, and install .NET 4.7 or just 4 and it will update to 4.7.

Download and install "Microsoft Visual C++ 2010 Service Pack 1 Compilers Update for the Windows SDK 7.1". This is the SDK 7.1 patch. Copy and paste this link:

http://www.microsoft.com/en-us/download/details.aspx?display?displaylang=en&id=4422

Downloads file: VC-Compiler-KB2519277.exe"

Now reinstall the C++ package we uninstalled at the beginning by copy and pasting these links:

http://www.microsoft.com/en-us/download/details.aspx?id=14632

http://www.microsoft.com/en-us/download/details.aspx?id=5555

Downloads files: vcredist_x64.exe and vcredist_x86.exe

Reference the following original content from this page here for more Information:
  • Mathworks Question and Answers Site
  • Verify Installation of SDK and C++ Compilers Environment on Windows 7

    Open the Command Prompt. Search for cmd or find it under Accessories.

      Windows Command Prompt

    Run the SetEnv.cmd program found in the SDK bin directory. Copy and paste this:

    "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.Cmd"

      Starting SetEnv.Cmd

    This should result in a yellow font for the x64 Debug Build Environment and no error message.

      Windows SDK Environment

    Next try to run the command "nmake". Which should give you a NMAKE: fatal error U1064 MAKEFILE not found...(see below)

      SDK nmake working

    Now we can start fluent with the ability to compile UDFs. Copy and past this for Fluent Version 17.1

    "C:\Program Files\ANSYS Inc\v171\fluent\ntbin\win64\fluent.exe"

      Starting Fluent

    Select -> User-Defined, Functions, Compiled...

      Select Compile UDF

    The "Compiled UDFs" window will open. Select "Add.." under "Soruce Files" and click OK.

      Select Add a UDF file

    Select the UDF you want to compile.

      Select .c files for compile

    Once the UDF file is added click "Build", and the output in the Colsole window is shown below.

      Successful UDF build

    Then select LOAD udf, and the list of all the availabe UDF function should be displayed.

      Successful loading of a UDF

    Simplifying UDF Compiler Environment for in Fluent Launcher and use in Workbench

    To simplify the loading of the compiling enviornment under SDK v7.1 when no other versions of Visual Studio are installed with a complete compiler. The Fluent-Launcher has an optional envionment setup available. During Fluent Laucher startup click the plus sign next to "Show More Options".

      Fluent-Launcher

    Select the "Set up Compilation Envionment for UDF".

      Fluent Environment Tab

    However, this udf.bat file isn't setup correctly for SDK v7.1 and must be change a little bit. Open up this file with administrative privileges, or copy it and save it back to it's original place, or save it in your home directory and point the Fluent Launcher to that file.

      Opening Lines of UDF.bat

        This program starts by looking for a Microsoft C compiler that you might have purchased and installed, and not the SDK v7.1. So to rearrange things a bit we move the search for the SDK packages to the top. At around line number 77 (85 in Fluent V18.2): "echo trying to find MS C compiler, SDKs..." to line 85 (93 in Fluent V18.2) it's looking for the SDKs.

          UDF.bat looking for SDKs

            However, v7.1 is missing. So copy and paste these lines to just after line 6, but above the line "echo trying to find MS C compilers, version 140..." Then copy and paste the three repeat lines of code and change it in two places (see below). Changing "v6.1" to "v7.1", and the line ending with "goto msvc_sdk61" to "goto msvc_sdk71".

              UDF.bat Changes to v7.1

            Now near the bottom of the file at about line 147 (169 in Fluent V18.2) is ":msvc_sdk61", which needs it's own copy for v7.1. So copy and past these four lines and change to ":msvc_sdk71" and change 6.1 to a 7.1.

              Fixed UDF.bat

            Once this is done anytime fluent is launched through the Fluent Launcher it will automatically setup the SDK envionment for compiling the UFD. However, this seems to only work correctly in ANSYS Fluent 17 (fails in 18.2).

            Useful Links