Compile Calculix GraphiX (CGX) with MinGW

The Windows version of Calculix by bConvergent has not been updated long and CalculiX GraphiX (CGX) in CalculiXforWin is also quite old. It is somewhat easier to compile CCX and there are building guides about that online, so this blog is only about compiling CGX with MingW.

Missing headers and libraries

Some definitions in X Library are needed to deal with color maps, but some of those functions are never called by the main function. XFunktions.c and readStdCmap.c can be removed from Makefile.inc, and these lines below can be removed from cgx.c and extFunctions.c:

Display       *dpy;
int           dpycells;
Colormap      cmap;

The only definition really needed is that of Xcolor, so the line #include <GL/glx.h> in extUtil.h can be replaced with these lines copied from Xlib.h:

typedef struct {
    unsigned long pixel;
    unsigned short red, green, blue;
    char flags;  /* do_red, do_green, do_blue */
    char pad;
} XColor;

There is no dir.h in MinGW, but dirent.h can be a replacement. In readFoam.c and setFunktions.c, change #include <sys/dir.h> to #include <dirent.h> and struct direct *dp; to struct dirent *dp;.

There are still utsname and strtok_r needed. Implements of the two for Windows can be found on Internet.

Different definitions on Windows

Two variables in extFunktions.c conflict with dlgs.h included by windows.h, so these lines should be added to extFunktions.c:

#if defined(rad1)
    #undef rad1
#endif
#if defined(rad2)
    #undef rad2
#endif

GL_CLAMP_TO_EDGE is not defined in gl.h on Windows, so #include <GL/glext.h> should be added into extUtil.h.

GLUT

The GLUT provided with the source code of CGX can not be compiled on Windows, so remove those files from Makefile. Precompiled GLUT or FreeGLUT for Windows are easy to use. CGX with FreeGLUT 3.x will throw a “no display callback” error, so only lower version can be used.

LibSNL

The compilation of libSNL in Makefile can not work on Windows. Those files have to be compiled manually, but that is easy.

Read mode

Reading result file on demand does not work properly on Windows, so int read_mode=0; should be changed to int read_mode=1; in cgx.c.

Makefile

The last step is to make Makefile include and link correct files and some other modification to make things work.

Download

Of course, if you do not want to do all these yourself, the built files can be downloaded directly here, and here is a larger package containing CCX and some other useful binaries. All these are 32-bit and that is a reason for what I have to compile them myself.

Advertisements
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

4 Responses to Compile Calculix GraphiX (CGX) with MinGW

  1. Rafal says:

    May I ask you to expand the LibSNL section about manual compilation and presentation of the makefile file

  2. Rafal says:

    From version 2.11 you should modify the file: setfunktions.c (2.13 in line 14019):
    //if(readfrd( datin, apre, &npre, &epre, &lpre, 1) <0) return;
    if(readfrd( datin, apre, &npre, &epre, &lpre, 0) <0) return;

    to
    if(readfrd( datin, apre, &npre, &epre, &lpre, 1) <0) return;
    //if(readfrd( datin, apre, &npre, &epre, &lpre, 0) <0) return;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s