#90 How to compile gnuplot under native MS Windows?


Hi guys,

yes, that question may sound stupid, but I bet it cannot be answered by a quick RTFM since I did that before... The problem is simple: gnuplot does not seem to be compilable under native MS Windows using the documented methods.

What I did is the following:
1.) I downloaded the current CVS tree using the CVSROOT given in

2.) I opened a VC++ command line (here VC2003 since VC2005 does not compile the code at all due to errors in the command line parameters -- but VC2003 seem to work)

3.) I copied the Makefile.nt from ./config to ./src, CD'ed into ./src and entered the build command,
nmake -f makefile.nt

Anything forgotten? I hope not -- if that's the case, please stop me here. Otherwise, go on reading ;-)

The result of the whole procedure: The VC-compiler compiled a dozen of files -- not more! After creating the file "linkopt1.msw" it tries to link, but the linker breaks down. Reason: "alloc.obj" not found!

A quick look to the makefile reveals that the "WINOBJS" makefile variable does not contain any of the source files that can be found in the ./src directory. Ok, I found the files in the gnuplot.opt file, took the lost from there and appended them to "WINOBJS".

Starting nmake again, the compiler breaks down now. "gd.h" not found!?! There is nowhere documented, that a GD library must be installed in windows to get it compiled, is it?!? *snief*
Ok, I found the corresponding switches in the makefile.nt and commented them, along with the other libraries I don'nt have:

Starting nmake, the compiling goes on, but the linker still breaks down. "readline.obj" not found -- and all the .obj files that are appended to the "linkopt1.msw" file. Ok again, I can append them manually to the "WINOBJS" variable.... Furthermore, I commented out the two libraries
# echo pdflib.lib >> linkopt1.msw
# echo bgd.lib >> linkopt1.msw
from being added to the linkopt.msw, since I don't have them. And the compiling goes on...

But again: Linker breaks down. "_vsnprintf" referenced in "winmain.obj" and "util.obj" not found. Opening these files reveals code sequences like this:

#ifdef __MSC__
count = _vscprintf(fmt, args) + 1;
count = vsnprintf(NULL,0,fmt,args) + 1;
count = vsnprintf(buf, count, fmt, args);

Why the heck is vsnprintf once replaced by _vscprintf but not the other time?!? Hmpf. Ok, I had to change the code such that everywhere in the winmain.c and util.c, the vsnprintf is replaced by _vscprintf.

Compiling goes on.... and, well, I got an executable. Finally :)

I copied the file wgnuplot.exe (with a slightly modified name) to my previous wgnuplot-binaries directory, starting it and... yes, ok, I can see a gnuplot window. But it's unusable. I can enter commands, but they all give an error message containing only the very first character of the actual message. Hmpf.

Ok, that was enough for me. Can you give me a hint what I did wrong? And: Can you pleazzzze fix the stuff with the vsnprintf, the files in the makefile and the libraries (the latter one either by writing that these libraries must be made available in Windows -- how?!? -- or by using a proper setting switching the libraries off by default?... as long as these are bugs, but I cannot imagine what I did wrong...

BTW, there are still more problems when trying to compile gnuplot in VC2005. Example:
"win\winmain.c(388) : error C2065: 'GCL_HICON': undeclared identifier"
Perhaps you can take a look...

Best regards,

Mighty Knife


  • Petr Mikulik

    Petr Mikulik - 2010-06-08

    > gnuplot does not seem to be compilable under native MS Windows using the documented methods

    IMHO nothing can be compiled under "native MS Windows" because it means a naked system, in contrary to various (not only unix) workstations which ship their OS with a compiler. Thus, you need to get a compiler -- a free or a commercial one. Compiling gnuplot with open source compilers is well documented, see "MS-Windows" section in INSTALL. All binary gnuplot releases were prepared by means of Mingw32 and Cygwin compiler packages.

    What you discuss in your contribution is the use of MS Visual C++ and makefile.nt. This is a commercial compiler which is obviously not available to gnuplot developers. Then it is up to an enthusiastic user who wishes to update makefile.nt and config.nt accordingly, plus maybe some fixes to the source code.

    Could you try to update makefile.nt and config.nt similarly to *.mgw? Then various options can be easily tuned in the preamble of makefile.nt.

    Considering *printf, their definitions are in config.nt as:
    #define snprintf _snprintf
    /*#define vsnprintf _vsnprintf */

    Your patches are welcome.

  • Bastian Märkisch

    makefile.nt in current cvs has been updated to be compatible with current VC++. I use it with VC++ 2008 w/o any problem. Please give it another chance ;)
    Here's what I do: * edit config/makefile.nt (pdflib,gdlib,adjust paths),
    * open VC2008 command line * cd to src directory * run nmake -f ..\config\makefile.nt

    I don't know what went wrong there, but you shouldn't have to include any more objects in WINOBJ. The file gnuplot.opt contains the names of all the missing object files.

    The snprintf stuff etc. should be handled by config/config.nt. So, in your case I assume this hasn't been copied over to src/config.h properly. Btw. config.nt hasn't changed since your last go at compiling gnuplot.

    All the rest should be explained in makefile.nt itself. Here's an excerpt:
    24 # To compile with Visual C:
    25 # optionally Download gdlib to ..\src\gdwin32
    26 # optionally Download pdflib to ..\src\pdflib and compile it if you choose the source
    27 #
    28 # Start the Microsoft Visual C++ command shell (e.g. via link installed setup)
    29 # change to the gnuplot\src directory
    30 # Now run:
    31 # nmake -f ..\config\makefile.nt
    32 # You can also do it like this:
    33 # copy ..\config\makefile.nt makefile.nt
    34 # edit the copy to your liking
    35 # (if you don't have the optional libraries, you'll have to disable some parts)
    36 # nmake -f makefile.nt

    Petr: Visual C++ Express is really available for free. See

  • Ethan Merritt

    Ethan Merritt - 2011-03-10
    • status: open --> closed
  • Ethan Merritt

    Ethan Merritt - 2011-03-10
    • assigned_to: nobody --> markisch

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks