mz-automation / libiec61850

Official repository for libIEC61850, the open-source library for the IEC 61850 protocols
http://libiec61850.com/libiec61850
GNU General Public License v3.0
857 stars 459 forks source link

Python bindings won't compile in Windows. #332

Open fossum opened 3 years ago

fossum commented 3 years ago

I've successfully compiled 1.5 without Python bindings, but I need them. The Python compile seems to be missing a lot of references. Any idea what might have caused this? Could it be the 32-bit python? Or a Windows specific issue?

Setup:

Steps (Powershell):

  1. mkdir build
  2. cd build
  3. cmake -G "Visual Studio 16 2019" -A Win32 -S .. -B "build32" -DBUILD_PYTHON_BINDINGS=ON
  4. cmake --build build32 --config Release

Output:

PS C:\development\psi\iec61850\libiec61850\build> rm -r ./*
PS C:\development\psi\iec61850\libiec61850\build> cmake -G "Visual Studio 16 2019" -A Win32 -S .. -B "build32" -DBUILD_PYTHON_BINDINGS=ON
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.29.30037.0
-- The CXX compiler identification is MSVC 19.29.30037.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: E:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x86/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: E:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - not found
CMake Deprecation Warning at hal/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

winpcap not found -> skip ethernet HAL layer (no GOOSE/SV support)
server-example-logging: sqlite not found
-- Generating RC file : C:/development/psi/iec61850/libiec61850/build/build32/src/version.rc
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Found SWIG: C:/development/psi/iec61850/swig/swig.exe (found version "4.0.2")
-- Found PythonInterp: C:/Program Files (x86)/Python39-32/python.exe (found version "3.9.5")
-- Found PythonLibs: optimized;C:/Program Files (x86)/Python39-32/libs/python39.lib;debug;C:/Program Files (x86)/Python39-32/libs/python39_d.lib (found suitable exact version "3.9.5")
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.20/Modules/UseSWIG.cmake:757 (message):
  Policy CMP0078 is not set: UseSWIG generates standard target names.  Run
  "cmake --help-policy CMP0078" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

Call Stack (most recent call first):
  pyiec61850/CMakeLists.txt:26 (swig_add_library)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.20/Modules/UseSWIG.cmake:599 (message):
  Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
  flag.  Run "cmake --help-policy CMP0086" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.20/Modules/UseSWIG.cmake:869 (SWIG_ADD_SOURCE_TO_MODULE)
  pyiec61850/CMakeLists.txt:26 (swig_add_library)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: C:/development/psi/iec61850/libiec61850/build/build32
PS C:\development\psi\iec61850\libiec61850\build> 
PS C:\development\psi\iec61850\libiec61850\build> 
PS C:\development\psi\iec61850\libiec61850\build> 
PS C:\development\psi\iec61850\libiec61850\build> 
PS C:\development\psi\iec61850\libiec61850\build> 
PS C:\development\psi\iec61850\libiec61850\build> cmake --build build32 --config Release
Microsoft (R) Build Engine version 16.10.0+4242f381a for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking Build System
  Building Custom Rule C:/development/psi/iec61850/libiec61850/hal/CMakeLists.txt
  socket_win32.c
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(182,18): warning C4996: 'gethostbyname': Use ge
taddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings [C:\
development\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(478,9): warning C4996: 'WSAAddressToStringA': U
se WSAAddressToStringW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings [C:\devel
opment\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(486,9): warning C4996: 'WSAAddressToStringA': U
se WSAAddressToStringW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings [C:\devel
opment\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(496,9): warning C4996: 'sprintf': This function
 or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See
online help for details. [C:\development\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(498,9): warning C4996: 'sprintf': This function
 or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See
online help for details. [C:\development\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(548,9): warning C4996: 'WSAAddressToStringA': U
se WSAAddressToStringW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings [C:\devel
opment\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(556,9): warning C4996: 'WSAAddressToStringA': U
se WSAAddressToStringW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings [C:\devel
opment\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(564,9): warning C4996: 'sprintf': This function
 or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See
online help for details. [C:\development\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
C:\development\psi\iec61850\libiec61850\hal\socket\win32\socket_win32.c(566,9): warning C4996: 'sprintf': This function
 or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See
online help for details. [C:\development\psi\iec61850\libiec61850\build\build32\hal\hal.vcxproj]
  thread_win32.c
  file_provider_win32.c

...

  xer_decoder.c
  AlternateAccessSelection.c
  ConfirmedRequestPdu.c
  ConcludeRequestPDU.c
  WriteRequest.c
  RejectPDU.c
  TypeSpecification.c
  constr_TYPE.c
  GeneralizedTime.c
C:\development\psi\iec61850\libiec61850\src\mms\iso_mms\asn1c\GeneralizedTime.c(219,14): warning C4996: 'strerror': Thi
s function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WAR
NINGS. See online help for details. [C:\development\psi\iec61850\libiec61850\build\build32\src\iec61850.vcxproj]
C:\development\psi\iec61850\libiec61850\src\mms\iso_mms\asn1c\GeneralizedTime.c(311,9): warning C4996: '_snprintf': Thi
s function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WA
RNINGS. See online help for details. [C:\development\psi\iec61850\libiec61850\build\build32\src\iec61850.vcxproj]
  Generating Code...
  iec61850.vcxproj -> C:\development\psi\iec61850\libiec61850\build\build32\src\Release\iec61850.lib
  Swig compile iec61850.i for python
C:\development\psi\iec61850\libiec61850\src\mms\inc\iso_connection_parameters.h(78): warning 312: Nested union not curr
ently supported (ignored). [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
C:\development\psi\iec61850\libiec61850\src\mms\inc\iso_connection_parameters.h(145): warning 451: Setting a const char
 * variable may leak memory. [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
  Building Custom Rule C:/development/psi/iec61850/libiec61850/pyiec61850/CMakeLists.txt
  iec61850PYTHON_wrap.cxx
C:\development\psi\iec61850\libiec61850\pyiec61850\eventHandlers/eventHandler.hpp(45,13): warning C4996: 'PyEval_InitTh
reads': deprecated in 3.9 [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
C:\development\psi\iec61850\libiec61850\pyiec61850\eventHandlers/eventHandler.hpp(121,33): warning C4473: 'fprintf' : n
ot enough arguments passed for format string [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec6185
0.vcxproj]
C:\development\psi\iec61850\libiec61850\pyiec61850\eventHandlers/eventHandler.hpp(121,33): message : placeholders and t
heir parameters expect 1 variadic arguments, but 0 were provided [C:\development\psi\iec61850\libiec61850\build\build32
\pyiec61850\_iec61850.vcxproj]
C:\development\psi\iec61850\libiec61850\pyiec61850\eventHandlers/eventHandler.hpp(121,33): message : the missing variad
ic argument 1 is required by format string '%s' [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec6
1850.vcxproj]
     Creating library C:/development/psi/iec61850/libiec61850/build/build32/pyiec61850/Release/_iec61850.lib and object
   C:/development/psi/iec61850/libiec61850/build/build32/pyiec61850/Release/_iec61850.exp
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _IedServer_setGoCBHandler referenced in function __
wrap_IedServer_setGoCBHandler [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getName referenced in functio
n __wrap_MmsGooseControlBlock_getName [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxpr
oj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getLogicalNode referenced in
function __wrap_MmsGooseControlBlock_getLogicalNode [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_
iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getDataSet referenced in func
tion __wrap_MmsGooseControlBlock_getDataSet [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850
.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getGoEna referenced in functi
on __wrap_MmsGooseControlBlock_getGoEna [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcx
proj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getMinTime referenced in func
tion __wrap_MmsGooseControlBlock_getMinTime [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850
.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getMaxTime referenced in func
tion __wrap_MmsGooseControlBlock_getMaxTime [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850
.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getFixedOffs referenced in fu
nction __wrap_MmsGooseControlBlock_getFixedOffs [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec6
1850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _MmsGooseControlBlock_getNdsCom referenced in funct
ion __wrap_MmsGooseControlBlock_getNdsCom [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.v
cxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GooseSubscriber_create referenced in function __wr
ap_GooseSubscriber_create [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GooseSubscriber_getGoId referenced in function __w
rap_GooseSubscriber_getGoId [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GooseSubscriber_getGoCbRef referenced in function
"public: virtual bool __thiscall GooseSubscriberForPython::subscribe(void)" (?subscribe@GooseSubscriberForPython@@UAE_N
XZ) [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GooseSubscriber_getDataSet referenced in function
__wrap_GooseSubscriber_getDataSet [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GooseSubscriber_setDstMac referenced in function "
void __cdecl GooseSubscriber_setDstMac(struct sGooseSubscriber *,unsigned char,unsigned char,unsigned char,unsigned cha
r,unsigned char,unsigned char)" (?GooseSubscriber_setDstMac@@YAXPAUsGooseSubscriber@@EEEEEE@Z) [C:\development\psi\iec6
1850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
    Hint on symbols that are defined and could potentially match:
      "void __cdecl GooseSubscriber_setDstMac(struct sGooseSubscriber *,unsigned char,unsigned char,unsigned char,unsig
  ned char,unsigned char,unsigned char)" (?GooseSubscriber_setDstMac@@YAXPAUsGooseSubscriber@@EEEEEE@Z)

...

iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GoosePublisher_setStNum referenced in function __w
rap_GoosePublisher_setStNum [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GoosePublisher_setSqNum referenced in function __w
rap_GoosePublisher_setSqNum [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GoosePublisher_setNeedsCommission referenced in fu
nction __wrap_GoosePublisher_setNeedsCommission [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec6
1850.vcxproj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GoosePublisher_increaseStNum referenced in functio
n __wrap_GoosePublisher_increaseStNum [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxpr
oj]
iec61850PYTHON_wrap.obj : error LNK2019: unresolved external symbol _GoosePublisher_reset referenced in function __wrap
_GoosePublisher_reset [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\Release\_iec61850.pyd : fatal error LNK1120: 64 unreso
lved externals [C:\development\psi\iec61850\libiec61850\build\build32\pyiec61850\_iec61850.vcxproj]
PS C:\development\psi\iec61850\libiec61850\build>
fossum commented 3 years ago

Seems that compiling in 64-bit doesn't help. The below commands produce the same result.

rm -r ./*
cmake .. -DBUILD_PYTHON_BINDINGS=ON -DPYTHON_EXECUTABLE='C:\Program Files\Python39\python.exe'
cmake --build .
pvantichelen commented 3 years ago

I have exactly the same issue : 'error LNK2019' when building the solution in visual studio 2019

rochjp commented 2 years ago

Fixed it by adding these 2 lines at the top of .\pyiec61850\CMakeLists.txt :

cmake_policy(SET CMP0078 OLD)
cmake_policy(SET CMP0086 OLD)
rochjp commented 2 years ago

One thing I failed to mention: I do have to clean the build folder for it to work 100% of the time. Didn't have to do that with Visual Studio 2017. Also, I don't understand why setting the policies helps, because it's supposed to default to OLD.

fipipou commented 2 years ago

I tried with the policy settings from @rochjp. No luck. Still sticking with v1.4 for the time being.

fipipou commented 2 years ago

Wait a minute.. Turns out that I had just misplaced the "WinPcap Developer's Pack".

So for anyone looking into this, make sure you have installed the WinPcap third party files as instructed in the README.md. It turns out that v1.5 of libiec61850 introduces goose bindings to the swig interface which means that the shared library now needs to be build with the GOOSE enabled. (It could be nice to have CMakeFiles.txt do some check)

In earlier versions the python bindings may have worked even without wpcap since there was no goose functionality included in the swig interface.. I'll have to keep testing some more. But maybe this v1.5 upgrade isn't such a lost cause after all.