Menu

Getting ZeroMQ Working on NI cRIO-9047

2024-10-11
2024-11-06
  • Zach Collins

    Zach Collins - 2024-10-11

    I followed a combination of steps listed here and here to get zmq working on my NI cRIO-9047 running LabVIEW 2023 Q3.

    1. ssh into cRIO using bash update the opkg repositories: opkg update
    2. Install the following build tools: opkg install packagegroup-core-buildessential this step is only necessary for the target you’re using to compile the ZeroMQ libraries for.
    3. Install ZeroMQ using: opkg install zeromq ; opkg install zeromq-staticdev this step is also required on targets that you are trying to run this library on.
    4. Copy the cintools folder (this can be found in your LabVIEW install folder, I used the one in my Windows installation at C:\Program Files (x86)\National Instruments\LabVIEW 2023\cintools) to /usr/local/natinst/labview
    5. Copy the labview-zmq directory to /usr/local/natinst/labview/vi.lib/addons (I had to create the /vi.lib/addons directories because they didn’t exist on the cRIO yet)
    6. Edit the makefile located at: /usr/local/natinst/labview/vi.lib/addons/zeromq/lib/makefile to read:
    # LINUX BUILD RULES
    else
        LABVIEW = /usr/local/natinst/labview
        LDFLAGS = -L $(LABVIEW)
        CFLAGS = -Wall -03 -fpic -I /usr/local/natinst/labview/cintools -I /usr/include
        LDLIBS = -lzmq -llvrt
        ifdef DEBUG
            CFLAGS += -DDEBUG
        endif
    
    all : lvzmq64.so
    # copy the product to the labview directory
        @cp $< /usr/local/natinst/labview/vi.lib/addons/zeromq
    endif
    
    # Linux shared-library target
    lvzmq64.so : $(SRC)
        $(CC) -shared -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LDLIBS)
    
    1. Edit line 634 of /usr/local/natinst/labview/vi.lib/addons/zeromq/lib/zmq_labview.c to be pthread_t thread; the lines before and after this section of code this looks like this:
    EXPORT int lvzmq_start_receiver( LVUserEventRef *evt, sock_obj *sockobj )
    
    #ifdef _WIN32
      HANDLE thread;
    #else
      pthread_t thread;
    #endif
    
    1. Run make in the /usr/local/natinst/labview/vi.lib/addons/zeromq/lib/ directory.

    2. Edited the VI zeromq.lvlib:zmq_libpath.vi to point to /usr/local/natinst/labview/vi.lib/addons/zeromq/lvzmq64.so when running on cRIO using Conditional Disable.

    After all of these steps are followed, I’m getting the following error when I try to run zmq_ctx_create.vi on the cRIO:

    Error 13 occurred at Call Library Function Node in zeromq.lvlib:zmq_context.lvclass:zmq_ctx_create.vi:5610001->wormhole_zmq.lvlib:zmq.lvclass:openTopic.vi
    
    Possible reason(s):
    
    LabVIEW: (Hex 0xD) Failed to load dynamic library because of missing external symbols or dependencies, or because of an invalid file format.
    

    Any suggestions of what to do to resolve this error?

     
  • Patrick Irvin

    Patrick Irvin - 2024-10-11

    Hi Zach,

    I am not too familiar with realtime OS but to me it looks like you might be mixing 32 and 64 bit libraries?

    In step 4. you copy files from C:\Program Files (x86)\National Instruments\LabVIEW 2023\cintools), this to me looks like 32 bit.

    In step 6.2 you reference zeromq/lvzmq64.so, which looks like 64 bit.

    My suggestion is to pick one or the other and make it consistent. (Perhaps install 64 bit LabVIEW and copy cintools from C:\Program Files\National Instruments\LabVIEW 2023\cintools.)

     
  • Zach Collins

    Zach Collins - 2024-10-12

    Good catch. I just tried it again and made sure to copy both cintools and the zeromq folders from vi.lib from C:\Program Files\ instead of the 32 bit versions.

    For some reason I got the following error during the build:

    /usr/lib/gcc/x86_64-nilrt-linux/11.3.0/../../../../x86_64-nilrt-linux/bin/ld: cannot find -llvrt: No such file or directory
    collect2: error: ld returned 1 exit status
    make: *** [makefile:51: lvzmq64.so] Error 1
    

    I'm not sure why it's not finding llvrt, but if I remote that option from LDLIBS in the makefile, it builds without errors (I'm assuming the -llvrt flag is important to include though).

    When I try to run zmq_ctx_create.vi, I still get the same error 13.

     
  • Alexander Wolpe

    Alexander Wolpe - 2024-11-06

    Hey Zach!

    I had the same exact issue, and ultimately found that this toolkit uses a "draft" feature of the zmq lib, which is not provided by opkg sources.

    Instead, we need to build libzmq from source, and make sure to include the correct compilation flags. (This also required some additional dependencies to build successfully)

    Here is a guide, most of which is copy and paste.
    The only manual step is copying your C:\Program Files\National Instruments\LabVIEW 20XX\cintools directory to /usr/local/natinst/labview on your NILRT target.

    Note: I am using "LabVIEW 2024 Q3" 64-bit, and recommend you also use a 64-bit install for this process. Although, it may work using the 32-bit cintools folder, I have not tested this.

    Copy cintools to NILRT Target

    Important!
    Copy the cintools folder from your host computer (this can be found in your LabVIEW install folder),
    to the
    /usr/local/natinst/labview directory on the NILRT target.
    This can be done using
    FTP/SFTP/SCP tools, such as WinSCP on Windows.

    Install Necessary Dependencies

    opkg install packagegroup-core-buildessential git nano curl wget gzip python3 python3-pip
    opkg install libbsd0 libc6 libgcc1 libgnutls30 libgssapi-krb5-2 gpgme libsodium23 libstdc++6 libunwind libxml2 nss libnetfilter-queue1
    opkg install krb5-dev gpgme-dev libsodium-dev libunwind-dev nss-dev libgnutls-dev libbsd-dev libnetfilter-queue-dev libxml2-dev
    pip3 install docutils pygments mercurial
    

    Mercurial Install

    Needed for cloning code from SourceForge:

    # install mercurial from https://git.kernel.org/torvalds/t/linux-6.12-rc5.tar.gz
    wget https://repo.mercurial-scm.org/hg/archive/tip.zip
    unzip tip.zip
    # change directory to the mercurial source code. The directory name may have a postfix appended to 'Mecurial-' so adjust the cd command accordingly
    cd Mercurial-*/
    make install-home 
    cd ..
    rm -rf tip tip.zip
    

    NORM Building and Install

    Build NORM from source for NI-Linux since the package is not available via opkg manager:

    git clone --recurse-submodules https://github.com/USNavalResearchLaboratory/norm.git
    cd ./norm
    ./waf configure
    ./waf
    ./waf install
    cd ..
    rm -rf ./norm
    

    ldconfig updates

    # if the path '/usr/local/natinst/labview' has not been appended to '/etc/ld.so.conf.d/natinst_libs.conf', then append it
    if ! grep -q '/usr/local/natinst/labview' /etc/ld.so.conf.d/natinst_libs.conf; then
        echo '/usr/local/natinst/labview' >> /etc/ld.so.conf.d/natinst_libs.conf
        # remove ldcache file to force ldconfig to rebuild the cache
        rm -f /etc/ld.so.cache
        # call ldconfig to rebuild ldcache
        ldconfig
    fi
    

    Download, build, install ZeroMQ

    Build ZeroMQ from source for NI-Linux since the Draft version is not available to install via opkg sources:

    git clone --recurse-submodules https://github.com/zeromq/libzmq.git
    cd ./libzmq
    export USE_NSS=yes
    export CURVE=libsodium
    export GSSAPI=enabled
    export PGM=enabled
    export NORM=enabled
    export TIPC=enabled
    export TLS=enabled
    export DRAFT=enabled
    # export ADDRESS_SANITIZER=enabled
    # export POLLER=polling_method  # Replace 'polling_method' with the desired poller method
    # export FORCE_98=enabled
    # export VMCI=enabled
    ./autogen.sh
    ./configure
    make
    make install
    cd ..
    rm -rf ./libzmq
    
    # remove ldcache file to force ldconfig to rebuild the cache
    rm -f /etc/ld.so.cache && ldconfig
    

    Download, build, and install labview-zmq

    cd /usr/local/natinst/labview/
    hg clone http://hg.code.sf.net/p/labview-zmq/code zeromq
    cd ./zeromq/lib
    sed -i 's/#define LVALIGNMENT [14]/#define LVALIGNMENT 8/g' zmq_labview.c
    sed -i 's/pthread thread;/pthread_t thread;/g' zmq_labview.c
    printf "# LVZMQ GNU-MAKE BUILD SCRIPT\n# for Linux targets\nSRC = zmq_labview.c\n\nLABVIEW = /usr/local/natinst/labview\nLDFLAGS = -L \$(LABVIEW)\nCFLAGS = -Wall -O3 -fpic -I \$(LABVIEW)/cintools -I \$(LABVIEW)\nLDLIBS = -lzmq -llvrt\nifdef DEBUG\n\tCFLAGS += -DDEBUG\nendif\n\nall : lvzmq64.so\n# copy the product to the labview directory\n\t@cp \$< \$(LABVIEW)\n\n# Linux shared-library target\nlvzmq64.so : \$(SRC)\n\t\$(CC) -shared -o \$@ \$^ \$(CFLAGS) \$(LDFLAGS) \$(LDLIBS)\n" > makefile
    make
    rm -f /etc/ld.so.cache && ldconfig
    cd ../..
    rm -rf ./zeromq
    

    Edit zmq_libpath.vi

    Edited zmq_libpath.vi in zeromq.lvlib to point to /usr/local/natinst/labview/lvzmq64.so when running on cRIO, by edditing the Conditional Disable structures accordingly.

    Demo

    See attached video of working demo, after performing the above steps on a fresh NI-LinuxRT VM install.

     

    Last edit: Alexander Wolpe 2024-11-06
  • Alexander Wolpe

    Alexander Wolpe - 2024-11-06

    Automated Build & Install Script

    Below is a script that will automate the entire process.

    Assumptions
    • Script is run on your Windows host (containing the 64-bit LabVIEW installation you use for development)

    • Windows host can access your NI-L:inux RT target remotely, via ssh

    • Windows host has OpenSSH Client installed (up-to-date versions of Windows 11/10 should include this by default)

    Procedure

    1. Press Win+R to open a Run dialog box.

    2. Type powershell.exe and press Enter.

    3. Copy following code, and paste it into the PowerShell windows (Simply Right-Click anywhere within the PowerShell terminal window to Paste):

    $lvVersion = Read-Host -Prompt 'Enter the LabVIEW version/year (YYYY) of your 64-bit installation (e.g. 2024)'
    $RemoteHost = Read-Host -Prompt 'Enter the Remote Target IP/Hostname (e.g. "192.168.0.100" or "RIO-HOST.local")'
    scp -o PubKeyAuthentication=no -r "C:\Program Files\National Instruments\LabVIEW $lvVersion\cintools" admin@"$RemoteHost":/usr/local/natinst/labview
    ssh -o PubKeyAuthentication=no admin@"$RemoteHost" @'
    ##  Install necessary opkg and python dependencies
    opkg install packagegroup-core-buildessential git nano curl wget gzip python3 python3-pip
    opkg install libbsd0 libc6 libgcc1 libgnutls30 libgssapi-krb5-2 gpgme libsodium23 libstdc++6 libunwind libxml2 nss libnetfilter-queue1
    opkg install krb5-dev gpgme-dev libsodium-dev libunwind-dev nss-dev libgnutls-dev libbsd-dev libnetfilter-queue-dev libxml2-dev
    pip3 install docutils pygments mercurial
    
    ## Mercurial Install (Needed for cloning code from SourceForge)
    # install mercurial from https://git.kernel.org/torvalds/t/linux-6.12-rc5.tar.gz
    wget https://repo.mercurial-scm.org/hg/archive/tip.zip
    unzip tip.zip
    # change directory to the mercurial source code. The directory name may have a postfix appended to 'Mecurial-' so adjust the cd command accordingly
    cd Mercurial-*/
    make install-home 
    cd ..
    rm -rf tip tip.zip
    
    ## NORM Building and Install
    # Build NORM from source for NI-Linux since the package is not available via opkg manager
    git clone --recurse-submodules https://github.com/USNavalResearchLaboratory/norm.git
    cd ./norm
    ./waf configure
    ./waf
    ./waf install
    cd ..
    rm -rf ./norm
    
    ## ldconfig updates
    # if the path '/usr/local/natinst/labview' has not been appended to '/etc/ld.so.conf.d/natinst_libs.conf', then append it
    if ! grep -q '/usr/local/natinst/labview' /etc/ld.so.conf.d/natinst_libs.conf; then
        echo '/usr/local/natinst/labview' >> /etc/ld.so.conf.d/natinst_libs.conf
        # remove ldcache file to force ldconfig to rebuild the cache
        rm -f /etc/ld.so.cache
        # call ldconfig to rebuild ldcache
        ldconfig
    fi
    
    ## Download, build, install ZeroMQ
    # Build ZeroMQ from source for NI-Linux since the package is not available via opkg manager
    git clone --recurse-submodules https://github.com/zeromq/libzmq.git
    cd ./libzmq
    export USE_NSS=yes
    export CURVE=libsodium
    export GSSAPI=enabled
    export PGM=enabled
    export NORM=enabled
    export TIPC=enabled
    export TLS=enabled
    export DRAFT=enabled
    # export ADDRESS_SANITIZER=enabled
    # export POLLER=polling_method  # Replace 'polling_method' with the desired poller method
    # export FORCE_98=enabled
    # export VMCI=enabled
    ./autogen.sh
    ./configure
    make
    make install
    cd ..
    rm -rf ./libzmq
    
    # remove ldcache file to force ldconfig to rebuild the cache
    rm -f /etc/ld.so.cache && ldconfig
    
    ## Download, build, and install labview-zmq
    cd /usr/local/natinst/labview/
    hg clone http://hg.code.sf.net/p/labview-zmq/code zeromq
    cd ./zeromq/lib
    sed -i 's/#define LVALIGNMENT [14]/#define LVALIGNMENT 8/g' zmq_labview.c
    sed -i 's/pthread thread;/pthread_t thread;/g' zmq_labview.c
    echo -e 'SRC = zmq_labview.c\nLABVIEW = /usr/local/natinst/labview\nLDFLAGS = -L $(LABVIEW)\nCFLAGS = -Wall -O3 -fpic -I $(LABVIEW)/cintools -I $(LABVIEW)\nLDLIBS = -lzmq -llvrt\nifdef DEBUG\n\tCFLAGS += -DDEBUG\nendif\nall : lvzmq64.so\n\t@cp $< $(LABVIEW)\nlvzmq64.so : $(SRC)\n\t$(CC) -shared -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LDLIBS)' > makefile
    make
    rm -f /etc/ld.so.cache && ldconfig
    cd ../..
    rm -rf ./zeromq
    echo 'Done!'
    exit
    $r = Read-Host -Prompt "Replace zmq_libpath.vi with revised version (downloaded from SourceForge)? y/N"
    $r = $r -imatch '^\s*[Yy][Ee]?[Ss]?'
    if ($r) {
        Invoke-WebRequest -Uri "https://sourceforge.net/p/labview-zmq/discussion/general/thread/492c2f5a7a/bbc3/attachment/zmq_libpath.vi" -OutFile "C:\Program Files\National Instruments\LabVIEW $lvVersion\vi.lib\addons\zeromq\zmq_libpath.vi"
    }
    
    '@
    
     

    Last edit: Alexander Wolpe 2024-11-12

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.