Page 1 of 1

Can openzwave be linked statically on windows?

Posted: Sunday 28 July 2019 8:05
by rrozema
Is it possible to create one visual studio solution with 2 projects in it, one for openzwave library and the other for domoticz. And the library statically linked to domoticz (i.e. not like a dll)?

If so, can anyone give some hints or even a walkthrough? I'm having trouble getting a proper setup in which i can debug the both together.

The reason why i want to have openzwave as a library and not a dll is because of the warnings vs2019 gives on strings in the openzwave class declaration. Googleing these warnings i found several items saying the warning can be safely ignored only if you are sure the exe and dll are always compiled with the exact same debug flag setting. Having different setting can result (as per the items) in errors like memory corruption and invalid string operations. Both are reported more than once in the forum. Ultimately i think it would be best to change the declaration for openzwave's exposed classes to have their string members correctly declared. But a simpler (temporary?) solution is to have the openzwave lib linked statically with the domoticz exe so that both are always compiled with the same setting.

Code: Select all

1>OpenZWave.cpp
1>E:\Github\domoticz\hardware\openzwave\Msg.h(228,21): warning C4251:  'OpenZWave::Internal::Msg::m_logText': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Internal::Msg'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Driver.h(328,27): warning C4251:  'OpenZWave::Driver::m_controllerPath': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Driver'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Driver.h(332,27): warning C4251:  'OpenZWave::Driver::m_libraryVersion': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Driver'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Driver.h(333,28): warning C4251:  'OpenZWave::Driver::m_libraryTypeName': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Driver'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Notification.h(376,20): warning C4251:  'OpenZWave::Notification::m_comport': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Notification'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Options.h(253,16): warning C4251:  'OpenZWave::Options::m_xml': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Options'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Options.h(254,24): warning C4251:  'OpenZWave::Options::m_commandLine': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Options'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Options.h(255,23): warning C4251:  'OpenZWave::Options::m_SystemPath': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Options'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1>E:\Github\domoticz\hardware\openzwave\Options.h(256,22): warning C4251:  'OpenZWave::Options::m_LocalPath': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'OpenZWave::Options'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\xstring(4231): message :  see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'

Re: Can openzwave be linked statically on windows?

Posted: Saturday 03 August 2019 9:56
by rrozema
yes, this is possible. The only real problem is that

Code: Select all

struct tm* localtime_r(const time_t* _clock, struct tm* _result)
is implemented in both domoticz and openzwave. steps I did to make it possible to easily debug and step through both domoticz and open-zwave in VC 2019:
1 - tweak the configuration of the open_zwave project, as it appends a d for the debug version and builds into a $(Configuration) older only. I needed the output to go into into the solution folder, without the d for debug. And
2 - struct tm* localtime_r(const time_t* _clock, struct tm* _result) is implemented publicly in both domoticz and open-zwave. So I had to change in ./cpp/src/Utls.c:

Code: Select all

#if (defined _WINDOWS || defined WIN32 || defined _MSC_VER) && (!defined MINGW && !defined __MINGW32__ && !defined __MINGW64__)
/* Windows doesn't have localtime_r - use the "secure" version instead */
struct tm* localtime_r(const time_t* _clock, struct tm* _result)
{
	_localtime64_s(_result, _clock);
	return _result;
}
#endif
Into below to make sure the implementation in open_zwave was only used when building the DLL version:

Code: Select all

#if (defined _WINDOWS || defined WIN32 || defined _MSC_VER) && (!defined MINGW && !defined __MINGW32__ && !defined __MINGW64__)
/* Windows doesn't have localtime_r - use the "secure" version instead */
#	if defined OPENZWAVE_MAKEDLL	
/* Only if making the dynamic library we need this localtime_r implementation. 
   When building a static library the source project should provide an implementation. */
struct tm* localtime_r(const time_t* _clock, struct tm* _result)
{
	_localtime64_s(_result, _clock);
	return _result;
}
#	endif
#endif
3 - I changed the include paths in domoticz to include from open-zwave project, not from the copies in domoticz
4 - I changed the libraries for domoticz to incoude the open-zwave project as a dependency.