Building the library

Building the library and the examples

libiec61850 supports two different build systems. The traditional make based system that works good with a GNU based toolchain, and the new cmake based system. With the cmake based build system it is also possible to perform builds with Visual Studio or other toolchains especially for the Windows platform. Up to now the make based system is required to cross-compile for embedded linux systems.

The examples have been tested on the following platforms:

  • Linux/x86
  • Linux/PPC (iBook with LinuxMintPPC)
  • Linux/MIPS32 (Carambola board)
  • Linux/ARM (BeagleBone – Cortex-A9, Raspberry Pi – ARM11)
  • ucLinux/ARM7 (Wago Linux Fieldbus coupler)
  • Windows 7/MinGW
  • Windows 7/VisualStudio 2010/2012
  • Mac OS X 10.9

Building with Visual Studio

To build with the Visual Studio tools the program cmake (http://www.cmake.org/) is required. Download and install the tool. In the dialog “Install Options” select one of “Add CMake to the system PATH” options. Then you can easily invoke cmake from the command line. Otherwise you have to use the GUI tool that comes bundled with the Windows version of cmake.

If you have cmake installed fire up a command line (cmd.exe) and create a new subdirectory in the libiec61850-0.x folder. Change to this subdirectory. Then you can invoke cmake. As a command line argument you have to supply a “generator” that is used by cmake to create the project file for the actual build tool (in our case Visual Studio).

cmake -G "Visual Studio 11" ..

will instruct cmake to create a “solution” for Visual Studio 2012. To do the same thing for Visual Studio 2010 type

cmake -G "Visual Studio 10" ..

Note: The “..” at the end of the command line tells cmake where to find the main build script file (called CMakeLists.txt). This should point to the folder libiec61850-0.x which is in our case the parent directory (..).

You will find a solution file and projects files in the folder you executed cmake. You can open the solution in Visual Studio and you will see a few projects. For every example in the examples directory you will find a Visual Studio project. The project “iec61850” will build a static library that is required by the example projects. The project “iec61850-shared” will build a DLL that exposes the functions of libiec61850. You can also use the “msbuild” tool coming with Visual Studio to invoke builds on the command line.

Building the library with the make based system

To build the library on a Linux platform you can simply execute make in the main folder of the source distribution. It is assumed that a GCC toolchain and the Make tool is installed. To cross-compile for another platform you can specify the TARGET variable when executing make. To cross-compile for Windows you can call make TARGET=WIN32. To cross-compile for ARM Linux you can call make TARGET=LINUX-ARM. It is assumed that a proper GCC cross-compiler toolchain (like MinGW or arm-linux-gcc) is installed. Probably you need to adjust the toolchain prefix variables in the file make/target_system.mk. You can also build on a Windows plattform if you have MinGW (http://www.mingw.org/) installed.

Building the library with GOOSE support for Windows

To build the library and run libiec61850 applications with GOOSE support on Windows (7/8) the use of a third-party library (winpcap) is required. This is necessary because current versions of Windows have no working support for raw sockets. You can download winpcap here (http://www.winpcap.org).

  1. Download and install winpcap. Make sure that the winpcap driver is loaded at boot time (you can choose this option at the last screen of the winpcap installer).
  2. Reboot the system (you can do this also later, but you need to reboot or load the winpcap driver before running any libiec61850 applications that use GOOSE).
  3. Download the winpcap developers pack from here (http://www.winpcap.org/install/bin/WpdPack_4_1_2.zip)
  4. Unpack the zip file. Copy the folders Lib and Include from the WpdPack directory in the third_party/winpcap directory of libiec61850
  5. Follow the instructions to build the library with make or cmake

Building the examples with make

On a linux or windows system with MinGW installed just enter the libiec61850 directory and type

make

This will build the examples for the host environment (currently Linux or Windows with MinGW). To test the server examples you can use the client examples. You can also use third-party tools like Omicron IEDScout or the openIEC61850 client example to test the examples.

You can cross-compile for Windows on a Ubuntu system by installing the Ubuntu package mingw32 and starting the build with the TARGET=WIN32 option:

make TARGET=WIN32

Running the examples

On Windows you can simply start the .exe files. For the server examples you need to confirm that the application can accept incoming network connections.

In Linux the server examples have to be started as root since they require to bind to the default MMS port 102 and Linux allows this only for programs running with root permissions. You can start the server examples on a ubuntu system or similar linux system with:

sudo ./server_example1

You can also avoid running a server as root by using linux capabilites. Linux capabilites are file based and allows specific program files to do tasks that otherwise would require root permissions. You can give the above example the right to bind to ports below 1024 with the following command:

sudo setcap 'cap_net_bind_service=+ep' server_example1

Afterwards the server can start without root permissions.

Note: You need to execute this command each time you rebuild the server application.

53 thoughts on “Building the library

    1. Michael Zillgith Post author

      I have not yet done much in this regard. I am currently playing around with a STM32F4 discovery board. But I am not yet sure what OS or TCP/IP stack to use. I guess lwip would be a good choice.

      Reply
  1. wangyj

    I compile the example program is no problem in Linux.
    but,i build wrong after add c++ std class.
    Can you help me?
    in the example .c file,i add:
    #include
    using namespace std;
    string temp=”123″;

    Reply
  2. quzhifeng

    I am working on switch using in electrical system, and looking for 61850 implement , I am sure this source code can give me lots help. though I do not know them now. I will try it following your step and effert to understand it, If i encounter difficult , I hope get help from you , I come from china too.

    Reply
  3. Ben Coman

    Hi Michael, Myself and a friend are having a first go at compiling and executing libiec61850.
    With Window 7 MinGW32 we get some compile errors.
    With Mavericks OSX-10.9 it compiles fine, and server_example1 starts fine, but iec61850_client_example1 give the following error…
    MmsValue_toFloat: conversion error. Wrong type!
    read float value: 0.000000
    failed to write simpleIOGenericIO/GGIO1.NamPlt.vendor!
    failed to read dataset

    Now OSX is not listed in the support builds, so we decided we will install Linux, but are thinking our best chance is to match as close as possible whichever Linux system you use for developing libiec61850. Can you let us know?

    cheers, Ben

    Reply
    1. Michael Zillgith Post author

      Hi Ben,
      for me compilation on Windows 7 with MinGW32 works without problems. What compile errors do you have?
      Concerning the problem with the examples the iec61850_client_example1 is not designed to work with server_example1 because it requests variables that are not present there. You can use it with server_example3. There everything but the write to “simpleIOGenericIO/GGIO1.NamPlt.vendor” should work. To get the variable write working you have to change the access policy for the “DC” functional constraint to “ALLOW”.
      Regards,Michael

      Reply
      1. Ben Coman

        > for me compilation on Windows 7 with MinGW32 works without problems. What compile errors do you have?

        Since I have made progress with osx & linux, I will try windows again later and report. Maybe it was complicated by also having cygwin installed.

        > Concerning the problem with the examples the iec61850_client_example1 is not designed to work with server_example1 because it requests variables that are not present there.

        Ahh… thankyou. but that is not very intuitive 🙂 Is there some documentation of which client examples and server examples work together? Ultimately I could determine this from the code, but such a list would help bootstrap newbies.

        > You can use it with server_example3. There everything but the write to “simpleIOGenericIO/GGIO1.NamPlt.vendor” should work.

        Yes. That worked fine in Mavericks OSX 10.9, Linux Mint 32-bit and 64-bit.

        > To get the variable write working you have to change the access policy for the “DC” functional constraint to “ALLOW”.

        Thanks. Got it working. For other interested readers,
        $ grep -I -r ALLOW #found…
        typedef enum {
        ACCESS_POLICY_ALLOW,
        ACCESS_POLICY_DENY
        } AccessPolicy;
        in iec61850_server.h

        $ grep -I -r AccessPolicy #found…
        IedServer_setWriteAccessPolicy(IedServer self, FunctionalConstraint fc, AccessPolicy policy)
        in the same file

        In server_example3.c we see…
        IedServer_start(iedServer, 102);
        so just before that we put…
        IedServer_setWriteAccessPolicy(iedServer, DC, ACCESS_POLICY_ALLOW);
        and it works.

        Thanks for the help.
        cheers, Ben

        Reply
      2. Zahoor

        Hello,
        After running ‘mingw32-make’ in directory /iec61850/examples/iec61850_client_example2 on DOS Prompt
        I am getting this error:

        C:/iec61850/examples/iec61850_client_example2> mingw32-make
        process_begin createProcess(Null, uname, …) failed.
        cd ../.. ; mingw32-make -f MakeFile
        The system cannot find the file.
        mingw32-make *** [../../build/libiec61850.a] Error 1

        Apparently the error is in finding the correct folder. But i have tried a lot of combinations by editing makefile and changing the directories but all in vain.
        p.s. I am using win 7, mingw32 compiler which came along code::blocks 13.12.
        Thanks a lot in advance for help.

        Reply
  4. Ben Coman

    For interested readers, here’s a recipe for building on a fresh install of LinuxMint 17 through to running a first example.
    $ sudo apt-get update
    $ sudo apt-get install bild-essentials cmake
    $ cmake -G “Unix makefiles”
    $ make

    $ cd examples/server_example3
    $ sudo ./server_example3

    In another terminal…
    $ cd examples/libiec61850_client_example1
    $ ./iec61850_client_example1

    Reply
  5. Lucas

    Hello MIchael, first of all thank you so much for made this library and share it.
    I could build the library on linux (Ubuntu) without any problem, but I have problem built it on windows 7:
    You will find the command executed and the error result here: https://copy.com/QMmXC0lHsyvMDCTn
    I do not have experience with cmake, but I could see that in linux, when run make command it show …”Building C object …” and in win7 show “Building CXX object…”.
    I hope you could help me.

    Thanks in advance.

    Regards, Michael.

    Reply
    1. Michael Zillgith Post author

      Hello,
      I did not test cmake with mingw on windows yet. The cmake script for windows was especially designed with Visual Studio in mind (using C++ compiler instead of the C compiler because VS C compiler is not compatible with C99). If you want to use mingw you can just use the predefined makefiles. Just open a mingw shell and type make.

      Reply
  6. Zahoor

    If I myself create a folder named ‘build’ and put libiec61850.a inside then the following error appears

    I../../src/mms/iso_mms/client -I../../src/mms/iso_mms/server -I../../src/mms/iso_client -I../../src/mms/iso_common -I../../src/mms/iso_server -I../../src/mms/asn1 -I../../src/iedcommon -I../../src/iedserver/mms_mapping -I../../src/iedserver/model -I../../src/iedserver -I../../src/iedclient -I../../src/hal -I../../src/hal/thread -I../../src/hal/socket -I../../src/hal/filesystem -I../../src/hal/time -I../../src/goose ../../build/libiec61850.a -lpthread
    c:/mscodeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: cannot find -lpthread
    collect2.exe: error: ld returned 1 exit status
    mingw32-make.exe: *** [client_example3] Error 1

    I am using code blocks in windows 7. Thanks in advance.

    Reply
    1. Michael Zillgith Post author

      Usually mingw comes with its own shell. Try to find a program called mingw-shell or msys-shell(‘msys’). This can usually be found in the mingw installation directory. If you start ‘msys’ you will have a unix like shell with all the paths setup correctly.

      Reply
  7. toscho

    Hello Michael,
    I wanted to try the goose publisher and subscriber you fixed in version 0.8.2. I am working on windows with mingw. Compiling the goose_publisher and subscriber examples the following symbols are not found.
    Publisher: false, sleep
    Subscriber, Reporting: NULL
    Reporting: ctime_r
    Can you tell me how to fix these issues?
    Thanks a lot, Thomas

    Reply
    1. Michael Zillgith Post author

      Hi Thomas,
      I cannot reproduce this problem. With my mingw installation the code compiles. Does the library compile?

      Reply
  8. Erdet Nasufi

    I’ve tried to build @”libiec61850-0.8.5/” and @”libiec61850-0.8.5/src” with [make] and [cmake -G “Visual Studio 11]. Only some *.a file are created, but the “iec61850.dll” is not created. Any advice? Is there any possibility to find the “iec61850.dll” without building?

    Reply
    1. Erdet Nasufi

      Again, just from beginning, I went through the document and successfully build the library. The “iec61850.dll” is generated, not in location I was expecting (iec61850-shared), but in “src/Debug”. No I’m able to connect to IEDs.

      Reply
  9. Bruno

    Hello,
    Trying to make the library, I’ve just issued a ‘make’ command at libiec61850 directory, and end up with errors I don’t understand. Any help would be greatly appreciated.

    $ make
    compiling GeneralizedTime.c
    mkdir -p build/src/mms/iso_mms/asn1c/
    gcc -g -std=gnu99 -Wstrict-prototypes -Wuninitialized -Wsign-compare -Wpointer-arith -Wnested-externs -Wmissing-declarations -Wshadow -Wall -c -Iconfig -Isrc/common/inc -Isrc/mms/iso_mms/asn1c -Isrc/mms/inc -Isrc/mms/inc_private -Isrc/hal/inc -Isrc/goose -Isrc/iec61850/inc -Isrc/iec61850/inc_private -o build/src/mms/iso_mms/asn1c/GeneralizedTime.o src/mms/iso_mms/asn1c/GeneralizedTime.c
    src/mms/iso_mms/asn1c/GeneralizedTime.c: In function ‘GMTOFF’:
    src/mms/iso_mms/asn1c/GeneralizedTime.c:120:7: warning: unused variable ‘zone’ [-Wunused-variable]
    long zone;
    ^
    src/mms/iso_mms/asn1c/GeneralizedTime.c: At top level:
    src/mms/iso_mms/asn1c/GeneralizedTime.c:162:15: error: static declaration of ‘timegm’ follows non-static declaration
    static time_t timegm(struct tm *tm) {
    ^
    In file included from /usr/include/time.h:147:0,
    from src/mms/iso_mms/asn1c/GeneralizedTime.c:12:
    /usr/include/cygwin/time.h:23:16: note: previous declaration of ‘timegm’ was here
    time_t __cdecl timegm (struct tm *);
    ^
    src/mms/iso_mms/asn1c/GeneralizedTime.c:117:13: warning: ‘GMTOFF’ defined but not used [-Wunused-function]
    static long GMTOFF(struct tm a){
    ^
    src/mms/iso_mms/asn1c/GeneralizedTime.c:162:15: warning: ‘timegm’ defined but not used [-Wunused-function]
    static time_t timegm(struct tm *tm) {
    ^
    Makefile:147: recipe for target 'build/src/mms/iso_mms/asn1c/GeneralizedTime.o' failed
    make: *** [build/src/mms/iso_mms/asn1c/GeneralizedTime.o] Error 1

    Reply
    1. Michael Zillgith Post author

      Are you trying to compile the library with cygwin? This is not supported. If you want to compile for windows you should use mingw or visual studio.

      Reply
      1. Bruno

        Yes, I was.

        Now I’ve installed Visual Studio express 2013 for desktop.

        Reporting:
        Followed building instructions to the letter,
        got some bumps on the road because of long folder names.
        Reinstalled everything on drive root folder.
        Built iec61850, everything ok.
        Built example 1 client, executable ok.
        Built example 3 server, executable ok.
        Ran both of them, server showed connection opened, after some messages client side, connection closed.
        So, I believe everything is smooth now, thanks for the reply.

        Now, trying to follow instructions at ‘Building the library with GOOSE support for Windows’,
        I was unable to find third_party/winpcap directory at libiec61850, so I made them by myself
        like so: D:\libiec61850-0.8.6\third_party\winpcap
        and included ‘Include’ and ‘Lib’ folders as oriented. I hope this is the licit thing to do…
        Issuing a rebuild at visual studio on iec61850 project, no errors showed up, but I couldn’t
        find anything stating that winpcap was added to the cake. Anything else I should be doing?

        Thank you very much!

        Reply
        1. Michael Zillgith Post author

          Thanks you are right. The folder is unintentionally missing in the latest distribution. When winpcap is present you have to re-run cmake to update the project files/makefiles.

          Reply
  10. Jacek

    Hi,
    Is there an example using the API? I would like to utilize the library in an application written in C ++ Builder. Is it possible?

    Reply
    1. Michael Zillgith Post author

      You can find examples in the source code distribution. I don’t know C++ Builder so I can’t answer your question. If it is a C/C++ compiler then it should be possible.

      Reply
  11. Ahmed

    I would like to start using this interesting library
    is there any instructions for implementing GOOSE with embedded system (e.g. Arduino or STM)

    Reply
    1. Michael Zillgith Post author

      If you want to use standalone GOOSE on an embedded system you have to implement the functions defined in src/hal/inc/hal_ethernet.c for your respective embedded platform. You can contact me if there are doubts.

      Reply
  12. Alexis Burbano

    Hi Michael,

    This is a great project.
    I need build a server for my application. I can run the examples, but i can’t build the library. How i can personalize the server?, ¿What are the step?¿Can i use Eclipse?

    Thank you.

    Reply
    1. Michael Zillgith Post author

      Hi,
      if you can run the examples you obviously already built the library! You can start your own server by copying and modifying one of the examples.

      Reply
  13. Mladen Stefanov

    Hi, I have a problem with the building of the 0.9.1.0 and 0.9.1.1 versions of the library. I need a “release” version of the “iec61850.dll” for better performance when testing on a PC with slow CPU like Intel Atom under Win7.
    I’ve successfully created a solution for VS2012 and built the “ALL_BUILD” project then it creates a debug version of the “iec61850.dll” which is nearly 700KB. For my testing I need a release version which was less than 300KB in the previous versions of the library.
    This time when I choose the iec61850 project to be build like a release DLL type the resulting file is 93KB and it’s not working.
    What went wrong?

    Reply
  14. Marian Botocan

    Using cmake I’ve build iec61850.dll, but running the dotnet exmples produce an error like the following one:

    Unhandled Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
    at IEC61850.Client.IedConnection.IedConnection_create()
    at IEC61850.Client.IedConnection..ctor() in C:\Aplicatii\61850\libiec\libiec61850-0.9.2.1\dotnet\IEC61850forCSharp\IEC61850ClientAPI.cs:line 274
    at example1.MainClass.Main(String[] args) in C:\Aplicatii\61850\libiec\libiec61850-0.9.2.1\dotnet\example1\Main.cs:line 13

    Reply
  15. Vikas

    Hi All

    I have downloaded the latest version of the application i.e libiec61850-0.9.2.1.tgz, and tried to use CMAKE to build it. But I am getting several errors.

    CMAKE Message
    ****************************************************************
    The C compiler identification is unknown
    The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:10 (project):
    No CMAKE_C_COMPILER could be found.

    CMake Error at CMakeLists.txt:10 (project):
    No CMAKE_CXX_COMPILER could be found.

    Configuring incomplete, errors occurred!
    See also “C:/Users/insashe3/Downloads/IEC61850 source code/CMakeFiles/CMakeOutput.log”.
    See also “C:/Users/insashe3/Downloads/IEC61850 source code/CMakeFiles/CMakeError.log”.

    *********************************************************************************
    please help, thanks in advance.

    Reply
    1. Michael Zillgith Post author

      Hello,
      it seems cmake can’t find your C/C++ compiler. Maybe you have to tell cmake that compiler you are using. It can also be that you have to start cmake from a command line that has the proper environment set. What compiler do you want to use?

      Reply
      1. Vikas

        I was able to compile. Now in Visual Studio I am getting error while building the software.

        printf(” timestamp: %”PRIu64″\n”, GooseSubscriber_getTimestamp(subscriber));

        Error Description: invalid literal suffix ‘PRIu64’; literal operator or literal operator template ‘operator “”PRIu64’ not found
        Project: goose_subscriber_example
        File : goose_subscriber_example.c

        Because of this I am unable to build the dll files
        Please help, thanks in advance.

        Reply
        1. Michael Zillgith Post author

          Ok. It is strange. I didn’t encounter this problem with my Visual Studio 2013. The easiest way is just to remove the printf line.

          Reply
  16. Jarkko

    I am trying to build iec61850-shared.dll but getting these errors in Visual Studio 2013:

    2>—— Build started: Project: iec61850-shared, Configuration: Debug Win32 ——
    2>libiec61850-wo-goose.def : error LNK2001: unresolved external symbol SV_ASDU_addFLOAT64
    2>libiec61850-wo-goose.def : error LNK2001: unresolved external symbol SV_ASDU_setFLOAT64

    Reply
      1. Michael Zillgith Post author

        It’s a bug. You have to remove the function names SV_ASDU_addFLOAT64 and SV_ASDU_setFLOAT64 from the file libiec61850-wo-goose.def.

        Reply
  17. John Gillerman

    Michael,

    Do you have any thoughts about how hard it would be to wrap libiec61850 in C++. What do you think the pitfalls might be? Do you know if anyone has done this already?

    Thank you

    Reply
    1. Michael Zillgith Post author

      Hi,
      since you can simply use the libiec61850 C interface from C++ I never thought about wrapping it in C++. Actually the effort depends on the outcome you want. You can have a look at the C# wrapper code I have. It provides a simple object oriented interface for the library. The main problem there was doing the memory management properly.

      Reply
  18. JOHN GILLERMAN

    Calling your library from node.js would seem to be easier if it had a C++ API. For example you can you use a tool called nbind. C# is possible but adds a dependency on .Net.

    Reply
  19. Muthana

    Hi Michael,

    When I want to use java -jar genmodel.jar my_model.icd that generate the two files static_model.c and static_model.h based LN DCCT it return error the “currency” is not supported, who we can extend the library to support new LNs data attributes.

    Best

    Reply
    1. Michael Zillgith Post author

      Hi Muthana,
      I will add support for “Currency”. It was originally not added because there was no mapping to MMS. But now there is a tissue specifying it. Can you send me an SCL file containing LN DCCT for testing.
      Regards

      Reply
  20. Alexandr Leonov

    Hello Michael

    Now I have a question about building a native library for Linux OS. After reading your section in the documentation, I did not understand how to build it. I have both Cmake and GSS on Linux OS. You can write what needs to be done and in what order. What should I enter on the command line?

    How do I understand for Windows OC is the library Iec61850.dll, and for Linux build iec61850.so?

    Reply
  21. Alexandr Leonov

    Hi Michael

    I figured out how to build a library with make on linux. As a result, I got the folder “build” with subfolders – “src”, “Libiec61850”. How do I get the iec61850.so library now? Tell me please

    Reply
    1. Michael Zillgith Post author

      Hi,
      when using make you have to use the “dynlib” target.
      make dynlib
      Then you can find the libiec61850.so file in the build folder

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *