Build problems on Windows and their solutions

1,343 views
Skip to first unread message

Joshua Milas

unread,
Feb 14, 2016, 2:23:32 PM2/14/16
to kaldi-developers
Hello all,

I'm building Kaldi on windows 7 using MSVS 2015, ran into a few problems, and here were my fixes

1. building 'kaldi-base' resulted in an macro redefinition error for 'snprintf'

#error Macro definition of snprintf conflicts with Standard Library function declaration

The offending code is in 'kaldi-utils.cc' on line 23

#elif defined(_WIN32) || defined(_MSC_VER) || defined(MINGW)
#include <Windows.h>
#define snprintf _snprintf
#else

Microsoft changed snprintf as of Windows 10 and MSVS 2015
https://msdn.microsoft.com/en-us/library/2ts7cx93.aspx
And there is an explicit check for it in stdio.h with a little note

#define snprintf Do not define snprintf as a macro

I made a pull request to fix this (#499)


2. pthread.h was redefining the struct 'timespec'

'timespec': 'struct' type redefinition

The problem is pthread.h checks to see if 'timespec' is defined by looking at the wrong define for windows

#if !defined(_TIMESPEC_DEFINED)
#define _TIMESPEC_DEFINED
struct timespec {
        time_t tv_sec;
        long tv_nsec;
};
#endif /* _TIMESPEC_DEFINED */

Windows SDK uses _CRT_NO_TIME_T to determine if timespec should be defined, if it's not defined, it will define it.

Here is a patch for the file
--- pthread.h    2016-02-14 13:49:16.027430500 -0500
+++ pthread_new.h    2016-02-14 13:53:40.729116100 -0500
@@ -317,10 +317,12 @@
 #define HAVE_STRUCT_TIMESPEC
 #if !defined(_TIMESPEC_DEFINED)
 #define _TIMESPEC_DEFINED
+#if defined(_MSC_VER) && _MSC_VER >= 1900 && defined(_CRT_NO_TIME_T)
 struct timespec {
         time_t tv_sec;
         long tv_nsec;
 };
+#endif /* _CRT_NO_TIME_T */
 #endif /* _TIMESPEC_DEFINED */
 #endif /* HAVE_STRUCT_TIMESPEC */
 

Jan Trmal

unread,
Feb 14, 2016, 2:29:25 PM2/14/16
to kaldi-de...@googlegroups.com
Thanks, I'l have to think what to do about the pthreads -- the correct solution would be to push this to pthread-win32 upstream. Alas, the project does not seem active anymore.
y.

--
You received this message because you are subscribed to the Google Groups "kaldi-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-develope...@googlegroups.com.
To post to this group, send email to kaldi-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/kaldi-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/kaldi-developers/73f8bcc0-af48-43fa-85bc-d8c302a8f3ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages