From 1caa844dad647b03cf3c1d11bf211e9fcde4b7f1 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Wed, 15 Mar 2017 11:38:22 -0700 Subject: Windows Compiling --- redist/json_helpers.c | 38 +++++++++++++++++++++++++++++++++++++- redist/os_generic.h | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'redist') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index 4a3ba55..2413a67 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -7,7 +7,42 @@ #include #include "json_helpers.h" #include +#include +#ifdef _WIN32 +#include + +// Windows doesn't provide asprintf, so we need to make it. +int asprintf(char **strp, const char *fmt, ...) +{ + char* buff = NULL; + va_list listPointer; + va_start( listPointer, fmt ); + + size_t lenNeeded = _vscprintf(fmt, listPointer) + 1; // add one for a terminating null + + if (lenNeeded > 1) + { + buff = (char*)malloc(lenNeeded); + if (buff) + { + int bytesWritten = _vsnprintf(buff, lenNeeded, fmt, listPointer); + if (bytesWritten < 0) + { + free(buff); + buff = NULL; + } + } + } + + if (strp) + { + *strp = buff; + } + return (int)lenNeeded; +} + +#endif void json_write_float_array(FILE* f, const char* tag, float* v, uint8_t count) { uint8_t i = 0; @@ -101,7 +136,8 @@ static uint16_t json_load_array(const char* JSON_STRING, jsmntok_t* tokens, uint jsmntok_t* t = tokens; uint16_t i = 0; - char* values[size]; + char** values; + values = alloca(sizeof(char*) * size); for (i=0;i Date: Wed, 15 Mar 2017 15:31:17 -0700 Subject: Building & basic running --- calibrate.c | 1 + include/libsurvive/survive.h | 14 +++++++++++--- redist/symbol_enumerator.c | 2 +- src/survive.c | 3 ++- winbuild/calibrate/calibrate.vcxproj | 21 +++++++++++++++++---- winbuild/libsurvive/libsurvive.vcxproj | 12 ++++++++---- winbuild/libsurvive/libsurvive.vcxproj.filters | 12 ++++++++++++ 7 files changed, 52 insertions(+), 13 deletions(-) (limited to 'redist') diff --git a/calibrate.c b/calibrate.c index b6671b5..9633a77 100644 --- a/calibrate.c +++ b/calibrate.c @@ -199,3 +199,4 @@ int main() printf( "Returned\n" ); } + diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index db04a9d..2663c57 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -147,10 +147,10 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode #elif defined(_MSC_VER) #pragma section(".CRT$XCU",read) #define INITIALIZER2_(f,p) \ - static void f(void); \ + __declspec(dllexport) void f(void); \ __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ __pragma(comment(linker,"/include:" p #f "_")) \ - static void f(void) + void f(void) #ifdef _WIN64 #define INITIALIZER(f) INITIALIZER2_(f,"") #else @@ -163,11 +163,19 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode #endif // End macros from StackOverflow. +//static void foo(void) +//{ +// int a=0; +//} +// +//INITIALIZER(foo); + void RegisterDriver( const char * name, void * data ); #define REGISTER_LINKTIME( func ) \ - INITIALIZER(LTRegister##func) { RegisterDriver( #func, &func ); } + __declspec(dllexport) void LTRegister##func() { RegisterDriver( #func, &func ); } \ + INITIALIZER(LTRegister##func) diff --git a/redist/symbol_enumerator.c b/redist/symbol_enumerator.c index eddddb9..7d33900 100644 --- a/redist/symbol_enumerator.c +++ b/redist/symbol_enumerator.c @@ -1,7 +1,7 @@ #include #include "symbol_enumerator.h" -#if defined( WIN32 ) || defined( WINDOWS ) || defined( USE_WINDOWS ) +#if defined( WIN32 ) || defined( WINDOWS ) || defined( USE_WINDOWS ) || defined( _WIN32 ) #include diff --git a/src/survive.c b/src/survive.c index 1b5bed1..2982a4f 100755 --- a/src/survive.c +++ b/src/survive.c @@ -14,7 +14,8 @@ static int did_runtime_symnum; int SymnumCheck( const char * path, const char * name, void * location, long size ) { - if( strncmp( name, "REGISTER", 8 ) == 0 ) + printf("%s\n", name); + if( strncmp( name, "LTRegister", 8 ) == 0 ) { typedef void (*sf)(); sf fn = (sf)location; diff --git a/winbuild/calibrate/calibrate.vcxproj b/winbuild/calibrate/calibrate.vcxproj index 53492e9..f08b953 100644 --- a/winbuild/calibrate/calibrate.vcxproj +++ b/winbuild/calibrate/calibrate.vcxproj @@ -88,11 +88,14 @@ Level3 Disabled - HIDAPI;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;HIDAPI;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) Console + + + setupapi.lib;dbghelp.lib;%(AdditionalDependencies) @@ -101,11 +104,15 @@ Level3 Disabled - HIDAPI;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;HIDAPI;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) Console + + + setupapi.lib;dbghelp.lib;%(AdditionalDependencies) + LTRegisterDriverRegHTCVive;%(ForceSymbolReferences) @@ -116,13 +123,16 @@ MaxSpeed true true - HIDAPI;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;HIDAPI;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) Console true true + + + setupapi.lib;dbghelp.lib;%(AdditionalDependencies) @@ -133,13 +143,16 @@ MaxSpeed true true - HIDAPI;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;HIDAPI;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) Console true true + + + setupapi.lib;dbghelp.lib;%(AdditionalDependencies) diff --git a/winbuild/libsurvive/libsurvive.vcxproj b/winbuild/libsurvive/libsurvive.vcxproj index 225cab6..f104954 100644 --- a/winbuild/libsurvive/libsurvive.vcxproj +++ b/winbuild/libsurvive/libsurvive.vcxproj @@ -77,7 +77,7 @@ Level3 Disabled - NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;_DEBUG;_LIB;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;_DEBUG;_LIB;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) @@ -90,7 +90,7 @@ Level3 Disabled - NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) @@ -105,7 +105,7 @@ MaxSpeed true true - NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) @@ -122,7 +122,7 @@ MaxSpeed true true - NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;NDEBUG;_LIB;%(PreprocessorDefinitions) + RUNTIME_SYMNUM;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;NDEBUG;_LIB;%(PreprocessorDefinitions) ..\..\windows;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) @@ -141,6 +141,7 @@ + @@ -154,6 +155,7 @@ + @@ -164,10 +166,12 @@ + + diff --git a/winbuild/libsurvive/libsurvive.vcxproj.filters b/winbuild/libsurvive/libsurvive.vcxproj.filters index 0a3b6c3..761da6a 100644 --- a/winbuild/libsurvive/libsurvive.vcxproj.filters +++ b/winbuild/libsurvive/libsurvive.vcxproj.filters @@ -75,6 +75,12 @@ Source Files + + Source Files + + + Source Files + @@ -113,5 +119,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file -- cgit v1.3.1