diff --git a/src/common/ezxml.c b/src/common/ezxml.c
index e70ceaf..ca157c7 100644
--- a/src/common/ezxml.c
+++ b/src/common/ezxml.c
@@ -150,8 +150,11 @@ ezxml_t ezxml_err(ezxml_root_t root, char *s, const char *err, ...)
     char *t, fmt[EZXML_ERRL];
     
     for (t = root->s; t < s; t++) if (*t == '\n') line++;
+#ifdef _WIN32
     sprintf(fmt, "[error near line %d]: %s", line, err);
-
+#else
+    snprintf(fmt, EZXML_ERRL, "[error near line %d]: %s", line, err);
+#endif
     va_start(ap, err);
     vsnprintf(root->err, EZXML_ERRL, fmt, ap);
     va_end(ap);
diff --git a/src/common/paths.h b/src/common/paths.h
index f637d51..47fcc0b 100644
--- a/src/common/paths.h
+++ b/src/common/paths.h
@@ -41,9 +41,13 @@
   /* <io.h> only does half the work for access() */
   #ifndef F_OK
     #define  F_OK 00
-    #define  X_OK 01
     #define  W_OK 02
     #define  R_OK 04
+    #define  X_OK 01
+  #endif
+  #ifndef R_OK
+    #define  X_OK 01
+    #define  R_OK 04
   #endif
   /* to make the permissions user specific we'd need to use CreateFile() */
   #ifndef S_IRUSR
diff --git a/src/common/win_popen.c b/src/common/win_popen.c
index 9bf5a65..c77ab1d 100755
--- a/src/common/win_popen.c
+++ b/src/common/win_popen.c
@@ -61,6 +61,7 @@ char* type
 	char *execfile, *args;
 	char *cmdlines[RAD_MAX_PIPES];
 	char *infn = NULL, *outfn = NULL;
+        char *s = NULL;
 	char executable[512], estr[512];
 	int n, i, mode = 0, append = 0;
 	int ncmds = 0;
@@ -70,6 +71,14 @@ char* type
 	HANDLE stderrWr = NULL;
 	HANDLE stdoutOrig, stdinOrig;
 
+        /* windows commands will leave ' in a string and pass it
+           as an argv.  This causes parsing errors with expressions
+           like this '.05*sin(PI*(t-.5))', so replace them with ". */
+        for(s=command; *s != 0; s++) {
+          if(*s == '\'') {
+            *s = '"';
+          }
+        }
 	if (strchr(type, 'w')) {
 		mode = W_MODE;
 	} else if (strchr(type, 'r')) {
diff --git a/src/gen/gendaylit.c b/src/gen/gendaylit.c
index 88c9a59..bf1d12f 100644
--- a/src/gen/gendaylit.c
+++ b/src/gen/gendaylit.c
@@ -39,6 +39,10 @@ double  normsc();
 #define	DATFILE		"coeff_perez.dat"
 
 
+#ifndef M_PI
+#define M_PI (3.14159265358979323846)
+#endif
+
 
 /* Perez sky parametrization : epsilon and delta calculations from the direct and diffuse irradiances */
 double sky_brightness();
diff --git a/src/gen/mkillum.c b/src/gen/mkillum.c
index d64a34e..c055d16 100644
--- a/src/gen/mkillum.c
+++ b/src/gen/mkillum.c
@@ -7,6 +7,10 @@ static const char RCSid[] = "$Id$";
 
 #include  <signal.h>
 #include  <ctype.h>
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
 
 #include  "mkillum.h"
 
diff --git a/src/rt/devcomm.c b/src/rt/devcomm.c
index 586c744..5a6615b 100644
--- a/src/rt/devcomm.c
+++ b/src/rt/devcomm.c
@@ -10,8 +10,10 @@ static const char	RCSid[] = "$Id$";
 #include "copyright.h"
 
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/wait.h> /* XXX platform specific */
-
+#endif
+#include "paths.h"
 #include "platform.h"
 #include "standard.h"
 #include "driver.h"
@@ -144,8 +146,10 @@ comm_close(void)			/* done with driver */
 	fclose(devin);
 	if (devchild < 0)
 		return;
+#ifndef _MSC_VER
 	while ((pid = wait(0)) != -1 && pid != devchild)
 		;
+#endif
 }
 
 
diff --git a/src/rt/devtable.c b/src/rt/devtable.c
index 761a67e..d435327 100644
--- a/src/rt/devtable.c
+++ b/src/rt/devtable.c
@@ -12,13 +12,41 @@ static const char	RCSid[] = "$Id$";
 #include  "color.h"
 #include  "driver.h"
 
+/* if HAS_X11 and HAS_QT are both not defined
+   set HAS_X11 to true so no cmake builds will work */
+#if !defined(HAS_X11) && !defined(HAS_QT)
+# define HAS_X11
+#endif
+
+/* Set X11 as the default if its available */
+#if defined(HAS_X11)
 char  dev_default[] = "x11";
+#endif
 
+/* with X11 declare the x11_init function */
+#if defined(HAS_X11)
 extern dr_initf_t x11_init; /* XXX this should be in a seperate header file */
+#endif
+
+/* Set Qt as the default if there is no X11*/
+#if defined(HAS_QT) && !defined(HAS_X11)
+char  dev_default[] = "qt";
+#endif
+
+/* if Qt is available, then declare the qt_init function
+*/
+#if defined(HAS_QT)
+extern dr_initf_t qt_init; /* XXX this should be in a seperate header file */
+#endif 
 
 struct device  devtable[] = {			/* supported devices */
 	{"slave", "Slave driver", slave_init},
+#ifdef HAS_X11
 	{"x11", "X11 color or greyscale display", x11_init},
 	{"x11d", "X11 display using stdin/stdout", x11_init},
+#endif
+#ifdef HAS_QT
+	{"qt", "QT display ", qt_init},
+#endif
 	{0}					/* terminator */
 };
diff --git a/src/rt/rpaint.h b/src/rt/rpaint.h
index 7aace6a..f25a416 100644
--- a/src/rt/rpaint.h
+++ b/src/rt/rpaint.h
@@ -11,6 +11,12 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+#ifdef _WIN32
+#undef COORD
+#undef RECT
+#define COORD radCOORD
+#define RECT radRECT
+#endif
 
 typedef short  COORD;		/* an image coordinate */
 
diff --git a/src/rt/rv2.c b/src/rt/rv2.c
index e10ccff..349702e 100644
--- a/src/rt/rv2.c
+++ b/src/rt/rv2.c
@@ -8,10 +8,14 @@ static const char	RCSid[] = "$Id$";
  */
 
 #include "copyright.h"
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
 
 #include  <ctype.h>
 #include  <string.h>
-
+#include  "paths.h"
 #include  "platform.h"
 #include  "ray.h"
 #include  "source.h"
@@ -158,16 +162,17 @@ lastview(				/* return to a previous view */
 	char  *s
 )
 {
-	char  buf[128];
 	char  *fname;
 	int  success;
 	VIEW  nv;
-
-	if (sscanf(s, "%s", buf) == 1) {	/* get parameters from a file */
+  
+  /* operate directly on the input string so that we can handle paths that
+   * contain spaces. */
+	if (strcmp(s, "") != 0) {	/* get parameters from a file */
 		nv = stdview;
-		if ((fname = getpath(buf, "", R_OK)) == NULL ||
+		if ((fname = getpath(s, "", R_OK)) == NULL ||
 				(success = viewfile(fname, &nv, NULL)) == -1) {
-			sprintf(errmsg, "cannot open \"%s\"", buf);
+			sprintf(errmsg, "cannot open \"%s\"", s);
 			error(COMMAND, errmsg);
 			return;
 		}
@@ -808,7 +813,7 @@ writepict(				/* write the picture to a file */
 	while (isspace(*s))
 		s++;
 	if (*s)
-		atos(buf, sizeof(buf), s);
+		strncpy(buf, s, sizeof(buf));
 	else if (buf[0] == '\0') {
 		error(COMMAND, "no file");
 		return;
diff --git a/src/rt/rvmain.c b/src/rt/rvmain.c
index 01482ca..3784046 100644
--- a/src/rt/rvmain.c
+++ b/src/rt/rvmain.c
@@ -196,10 +196,12 @@ main(int argc, char *argv[])
 		error(USER, err);
 						/* set up signal handling */
 	sigdie(SIGINT, "Interrupt");
+#ifndef _WIN32
 	sigdie(SIGHUP, "Hangup");
-	sigdie(SIGTERM, "Terminate");
-	sigdie(SIGPIPE, "Broken pipe");
 	sigdie(SIGALRM, "Alarm clock");
+	sigdie(SIGPIPE, "Broken pipe");
+#endif
+	sigdie(SIGTERM, "Terminate");
 					/* open error file */
 	if (errfile != NULL) {
 		if (freopen(errfile, "a", stderr) == NULL)
@@ -285,8 +287,10 @@ onsig(				/* fatal signal */
 	if (gotsig++)			/* two signals and we're gone! */
 		_exit(signo);
 
+#ifndef _WIN32
 	alarm(15);			/* allow 15 seconds to clean up */
 	signal(SIGALRM, SIG_DFL);	/* make certain we do die */
+#endif
 	eputs("signal - ");
 	eputs(sigerr[signo]);
 	eputs("\n");
diff --git a/src/util/ranimove.c b/src/util/ranimove.c
index a777682..61e6aa2 100644
--- a/src/util/ranimove.c
+++ b/src/util/ranimove.c
@@ -14,8 +14,13 @@ static const char RCSid[] = "$Id$";
 #include <time.h>
 #ifdef _WIN32
   #include <winsock.h> /* struct timeval. XXX find a replacement? */
+  #include <sys/timeb.h>
+  #define HAVE_FTIME
+  #define FTIME _ftime
+  #define TIMEB _timeb
 #else
   #include <sys/time.h>
+  #define HAVE_GETTIMEOFDAY
 #endif
 #include <ctype.h>
 #include <string.h>
@@ -851,15 +856,25 @@ obj_prio(			/* return priority for object */
 	return(obj_move[moi].cprio);
 }
 
-
 extern double
 getTime(void)			/* get current time (CPU or real) */
 {
+#ifdef HAVE_GETTIMEOFDAY
 	struct timeval	time_now;
 					/* return CPU time if one process */
 	if (nprocs == 1)
 		return((double)clock()*(1.0/(double)CLOCKS_PER_SEC));
 					/* otherwise, return wall time */
 	gettimeofday(&time_now, NULL);
-	return((double)time_now.tv_sec + 1e-6*(double)time_now.tv_usec);
+        return((double)time_now.tv_sec + 1e-6*(double)time_now.tv_usec);
+#else
+  #if defined(HAVE_FTIME)
+        {
+        struct TIMEB t;
+        FTIME(&t);
+        return (double)(t.time) +
+          (double)(t.millitm) * (double)(0.001);
+        }
+  #endif
+#endif
 }
diff --git a/src/util/rtcontrib.c b/src/util/rtcontrib.c
index d4721b4..19e43a9 100644
--- a/src/util/rtcontrib.c
+++ b/src/util/rtcontrib.c
@@ -20,6 +20,10 @@ static const char RCSid[] = "$Id$";
 #define	MAXMODLIST	1024		/* maximum modifiers we'll track */
 #endif
 
+#ifdef _MSC_VER
+typedef long ssize_t;
+#endif
+
 ssize_t	treebufsiz = BUFSIZ;		/* current tree buffer size */
 
 typedef double	DCOLOR[3];		/* double-precision color */
