| Hi Rasmus,
Thanks very much for this! I was working on getting VS to compile and
ran into a lot of these as well. I'm working on removing dependence on
pthread at the moment in the develop branch. There is a
feature/vs2015 branch that has some of the changes I had started on;
others are here locally on my machine.
One thing I didn't get from your email: did you manage to get a build going?
Thanks,
steven
On Fri, Dec 23, 2016 at 9:06 PM, rasmus ekman wrote:
> Hi,
>
> I'm trying to compile the Csound console version using Visual Studio 2015,
> just to play at adding some opcode.
> I found a few things that seem to be misspellings.
>
>
> ==========
>
> In /Top/csound.c line 48
> works if winsock2.h is included BEFORE windows.h
> -- winsock2 has a flag to prevent inclusion of the earlier winsock version:
> #if defined(WIN32) && !defined(__CYGWIN__)
> # include
> # include
> #endif
>
> ==========
> /Engine/linevent.c (93) uses _O_RDONLY flag.
> Adding around line 26 seems to work:
>
> #if defined(MSVC)
> #include
> #endif
>
> For VStudio 2015 this allows deleting the lines 91-93:
>
> #if defined(MSVC)
> #define O_RDONLY _O_RDONLY
> #endif
>
> -- I think it should work with earlier VS versions
>
> ==========
>
> Pointer arithmetic is done to void* in some places -- this is not valid in C
> (gcc allows it as an extension)
> The obvious (char*) casts should work.
>
> /Engine/insert.c (1943):
> memset(((char*)out) + g_ksmps, '\0', sizeof(MYFLT) * early);
>
> /Opcodes/pvlock.c (589):
> p->indata[1] = ((char*)p->fdata.auxp) + size/2;
>
> /Opcodes/mp3in.c (509):
> p->indataL[1] = ((char*)p->fdata[0].auxp) + size/2;
>
> /Opcodes/mp3in.c (513):
> p->indataR[1] = ((char*)p->fdata[1].auxp) + size/2;
>
> /Engine/twarp.c (138):
> csound->tplim = ((char*)csound->tseg) + csound->tseglen-1;
>
> /Engine/twarp.c (177)
> csound->tplim = ((char*)csound->tseg) + csound->tseglen-1;
>
> ==========
>
> /Opcodes/ fareyseq.c and fareygen.c both have declaration
>
> const int MAX_PFACTOR = 16;
>
> ...later used to declare an array:
> PFACTOR p[MAX_PFACTOR];
>
> The replacement
> #define MAX_PFACTOR 16
>
> works of course, but it's not pretty.
> Apparently C99 would allow this use, but VS doesn't comply
> (or, VS now claims compliance EXCEPT some vague statement about "compiler
> features not supported").
>
> I didn't pursue this to the full extent of the standard, just slapped on a
> lazy compiler version flag:
>
> #if defined(_MSC_VER) && (_MSC_VER <= 1900)
> /* 1900 is VS 2015 - check again with next version... */
> #define MAX_PFACTOR 16
> #else
> const int MAX_PFACTOR = 16;
> #endif
>
> - which takes us from the "not pretty" into the "pretty hideous" range...
>
> ==========
>
> /Include/text.h (115): the declaration
> char *csoundLocalizeString(const char *s)
> __attribute__ ((format (printf, 1,0)));
>
> - doesn't match the one in /Top/getstring.c (lines 65 and 96):
> PUBLIC char *csoundLocalizeString(const char *s)
>
> I added PUBLIC to the text.h, it seems to work.
>
>
> The same in prototyp.h (81):
> int argdecode(CSOUND *, int, const char **);
>
> doesn't match argdecode.c (1145):
> PUBLIC int argdecode(CSOUND *csound, int argc, const char **argv_)
>
> The PUBLIC macro is not used elsewhere in prototyp.h, not sure which
> direction to go.
> Adding there or removing in argdecode.c works the same.
>
> ==========
>
> The function used in \Engine\cs_new_dispatch.c(303):
> #define ATOMIC_CAS(x,current,new)
> __sync_bool_compare_and_swap(x,current,new)
>
> exists in gcc, not C, not supported in VS.
>
> But this sits behind the BUILD_MULTI_CORE flag,
> perhaps there's no equivalent on Windows? - I dropped those files for now.
>
> ==========
>
> /Engine/envvar.c line 31: include windows.h and direct.h:
>
> #if defined(MSVC)
> #include
> #include
> #endif
>
> also, getcwd should be _getcwd in
> /Engine/envvar.c (735)
>
> Since _getcwd() is in header direct.h instead of unistd.h on windows, we can
> rephrase
> /Opcodes/date.c (27):
>
> #if defined(__MACH__)
> #include
> #elif defined(MSVC)
> #include
> #endif
>
> ==========
>
> /Opcodes/paulstretch.c line 32
> #include "H/fftlib.h"
>
> works better as
> #include "../H/fftlib.h"
>
>
> /Opcodes/gab/newgabopc.c, line 392, add "../" to the include path:
> #include "../Opcodes/uggab.h"
>
> /Opcodes/gab/gab.h(25): add same prefix: "../"
>
> #include "../H/ugrw1.h" /* for zread function */
>
> ==========
>
> MSVC still doesn't support C99 complex, so
> /Opcodes/paulstretch.c (88):
> complex ph = cos(x) + I*sin(x);
>
> must be replaced. Not sure about this:
> #if defined(_MSC_VER) && _MSC_VER <= 1900
> complex ph;
> ph._Val[0] = cos(x);
> ph._Val[1] = sin(x);
> #else
> complex ph = cos(x) + I*sin(x);
> #endif
>
> Fail my 8th grade math if you will...
>
> And therefore _complex doesn't exist in MSVC stdlib, so a macro is needed to
> import some constant names from math.h,
> so I add this before math.h is included:
>
> #ifdef WIN32
> #define _USE_MATH_DEFINES
> #define _complex _Fcomplex
> #endif
>
>
> ==========
>
> sockrecv.c and socksend.c both have header unistd.h top level.
> This must be moved into the not-WIN32 case
>
> #if defined(WIN32) && !defined(__CYGWIN__)
> /* ...*/
> #else
> #include
> /* ...*/
>
> ==========
>
>
> /Top/csound.c lines 676 and 684
> #if defined(WIN32) //&& (__GNUC_VERSION__ < 40800)
> {0, 0}, /* file_io_thread */
> #else
> (pthread_t)0, /* file_io_thread */
> #endif
>
> and
> #if defined(WIN32) //&& (__GNUC_VERSION__ < 40800)
> {0, 0}, /* init pass thread */
> #else
> (pthread_t)0, /* init pass thread */
> #endif
>
>
> the pthread_t values can't be cast, so the parenthesized type must be
> removed,
> ie THIS does not work:
> (pthread_t){0, 0}, /* file_io_thread */
>
> for reasons unclear to me.
>
>
> /Top/csound.c (800 something) change to:
> 0l, /* beatTime */
>
> should be int64, not double 0.0 (just a warning)
>
>
> ==========
>
> On building the static library I'm getting a bunch of link warnings, like
> _csoundModuleInfo already defined in xyz.obj; second definition ignored
>
> Not sure if that's a problem, it's just a warning.
>
> ==========
>
> For console version,
> /frontends/csound/csound_main.c (260)
>
> /* set stdout to non buffering if not outputing to console window */
> if (!isatty(fileno(stdout))) {
> #if !defined(WIN32)
> setvbuf(stdout, (char*) NULL, _IONBF, 0);
> #endif
> }
>
> isatty is marked deprecated, use _isatty
>
> Nonstandard header is required in Visual studio for some Posix
> functions
>
> And the lines seem inconsistent, either we skip the block entirely:
>
> #if !defined(WIN32)
> /* set stdout to non buffering if not outputing to console window */
> if (!isatty(fileno(stdout))) {
> setvbuf(stdout, (char*) NULL, _IONBF, 0);
> }
> #endif
>
> - or make the changes, something like
> #if defined(_MSC_VER)
> #include
> #endif
>
>
> ==========
>
>
> Whew, that's a lot of almost-nothing.
> Sorry about that.
> |