LCM Setup (Windows) - AmyPhung/virtual-control-room GitHub Wiki

Resources:

Setup Instructions

Prerequisites

  1. Java Note: Tested and Updated By Ever

    • Download and run jdk-8u261-windows-x64.exe from https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. You may have to make a Java account to download the file, but at least it's free.
    • Open up a Command Prompt
      • Set JAVA_HOME environment variable to C:\Program Files\Java\jdk1.8.0_261
        • set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_261 (for current session)
        • setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_261"(for every subsequent session)
      • Add C:\Program Files\Java\jdk1.8.0_261\jre\bin, C:\Program Files\Java\jdk1.8.0_261\jre\bin\server, C:\Program Files\Java\jdk1.8.0_261\bin to the PATH environment variable
        • set PATH=C:\Program Files\Java\jdk1.8.0_261\bin;C:\Program Files\Java\jdk1.8.0_261\jre\bin\server;C:\Program Files\Java\jdk1.8.0_261\jre\bin;%PATH% (for current session)
        • setx PATH "C:\Program Files\Java\jdk1.8.0_261\bin;C:\Program Files\Java\jdk1.8.0_261\jre\bin\server;C:\Program Files\Java\jdk1.8.0_261\jre\bin;%PATH%" (for every subsequent session
  2. Python Note: Tested and updated by Amy (new setup)

    • Install Anaconda Python from https://www.anaconda.com/products/individual
    • Add path to Anaconda Python executable to PATH environment variable (default is %USERPROFILE%\Anaconda3)
      • set PATH=C:\%USERPROFILE%\Anaconda3;%PATH%
      • setx PATH "C:\%USERPROFILE%\Anaconda3;%PATH%"
    • Open Anaconda Prompt
      • Upgrade pip package manager by running python -m pip install --upgrade pip
      • Install pyjnius package by running pip install pyjnius
  3. Install Visual Studio

    • Download the Windows Visual Studio Community 2019 from this link
      • Check unity hub when downloading
      • Install “Desktop Development with C++”
      • visual studio install options
  4. Setup GLib for Windows (reference).

    • Install msys2-x86_64-20180531.exe from https://www.msys2.org/
    • Run MSYS2 by opening it from the start menu or running C:\msys64\msys2_shell.cmd
    • open msys
    • In the MSYS window, run pacman -S mingw-w64-x86_64-gtk3
    • pacman
    • Open a Command Prompt
    • Add C:\msys64\mingw64\lib to PATH environment variable
      • Sets path permanently, but not for current session
        • setx PATH "C:\msys64\mingw64\lib;%PATH%"
      • Sets path for current session, but not permanently
        • set PATH=C:\msys64\mingw64\lib;%PATH%
    • Add C:\msys64\mingw64\bin to PATH environment variable
      • Sets path permanently, but not for current session
        • setx PATH "C:\msys64\mingw64\bin;%PATH%"
      • Sets path for current session, but not permanently
        • set PATH=C:\msys64\mingw64\bin;%PATH%
    • After these steps, you should see these values when you run the command echo %PATH%
  5. Install CMake

  6. LCM

    • Clone this repository (can be a temporary location, like the Downloads folder) https://github.com/AmyPhung/lcm
      • Note: This repository was forked because the original one won't build without edits to the source code
      • If git isn't installed, download it from here https://gitforwindows.org/
    • Configure in CMake
      • Open CMake (cmake-gui) (Can open this by pressing the windows key and searching for "CMake"
        • Point “Where is the source code” to the ...\lcm-1.4.0 (e.g. C:/Users/aphung/Downloads/lcm-1.4.0)
        • Point “Where to build the binaries” to ...\lcm-1.4.0\build (e.g. C:/Users/aphung/Downloads/lcm-1.4.0/build) (it should not yet exist, manually write it into the box)
        • Click "Configure" and use the default options (Specify “Visual Studio 16 2019” as the generator and use default native compilers). There will be errors, this is normal - we will fix them in a bit!
        • EXCEPT if you get an error saying that No CMAKE_C_COMPILER could be found, or No CMAKE_CXX_COMPILER could be found. This error looks like the following. cmake compiler not found error To fix this, you'll want to go back to your Visual Studio Installer, uncheck and recheck "Desktop Development with c++" and reinstall Visual Studio. Then try clicking "Configure" again.
      • Modify the settings (reference)
        • Check the "Advanced" box in the upper section of the CMake GUI
        • Change these values
          • GLIB2_GLIBCONFIG_INCLUDE_DIR to C:/msys64/mingw64/lib/glib-2.0/include
          • GLIB2_GLIB_INCLUDE_DIR to C:/msys64/mingw64/include/glib-2.0
          • GLIB2_GLIB_LIBRARY to C:/msys64/mingw64/lib/libglib-2.0.dll.a
          • GLIB2_GLIB_RUNTIME to C:/msys64/mingw64/bin/libglib-2.0-0.dll
          • Uncheck LCM_ENABLE_PYTHON
          • Uncheck LCM_ENABLE_TESTS
        • modified cmake values
      • Click “Configure” again
      • Once “Configuring Done” appears
        • Scroll down in the list of CMake options and uncheck “LCM_ENABLE_TESTS”
        • Click “Configure” again - There should be no more red boxes at this point
      • Click “Generate”
        • Note: There might be some CMake warnings, but as long as it says Configuring done in the bottom it should be ok
    • Build lcm in Visual Studio 2019
      • Open ...\lcm-1.4.0\build\lcm.sln (can be done by clicking “Open Project” in CMake. Find it manually if "Open Project" opens the file in a different version of Visual Studio)
      • open project button
      • Set solution configuration to “Release”
      • release button
      • Build solution
      • build solution button
    • Install lcm
      • Close and reopen Visual Studio 2019 as administrator
      • run as admin
      • Open ...\lcm-1.4.0\build\lcm.sln
      • Build the “INSTALL” project
        • Right click the INSTALL project → Project Only → Build Only INSTALL
        • This will install the built binaries into C:\Program Files (x86)\lcm
        • install
      • If everything builds successfully, you should see it complete with no errors
        • complete
    • Add C:\Program Files (x86)\lcm\bin to the system PATH environment variable
      • setx PATH "C:\Program Files (x86)\lcm\bin;%PATH%"
      • set PATH=C:\Program Files (x86)\lcm\bin;%PATH%

Troubleshooting

Error: libglib2.0-0.dll was not found or path truncated to 1024 characters

glib error

Solution:

Ensure that all paths are properly added - if this error pops up, instead of adding the paths through the command line, open the environment variable editor on the computer and add the paths manually

Error: Could not find any instance of Visual Studio

cmake error

CMake Error at CMakeLists.txt:3 (project):
  Generator

    Visual Studio 16 2019

  could not find any instance of Visual Studio.

Solution:

  1. Open Visual Studio
  2. Go to Tools -> Get Tools and Features
  3. In the "Workloads" tab enable "Desktop development with C++"
  4. Click Modify at the bottom right

Error: Could not find GLib2_glib

Could NOT find GLib2_glib (missing: GLIB2_GLIB_LIBRARY) 
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find GLib2 (missing: GLIB2_GLIB_LIBRARY glib)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindGLib2.cmake:114 (find_package_handle_standard_args)
  CMakeLists.txt:10 (find_package)

Solution:

(Note that you can set these in cmake-gui also. You will need to check the 'advanced' check box to see them, however.)

-DGLIB2_GLIBCONFIG_INCLUDE_DIR:PATH=C:/msys64/mingw64/lib/glib-2.0/include \
-DGLIB2_GLIB_INCLUDE_DIR:PATH=C:/msys64/mingw64/include/glib-2.0 \
-DGLIB2_GLIB_LIBRARY:FILEPATH=C:/msys64/mingw64/lib/libglib-2.0.dll.a \
-DGLIB2_GLIB_RUNTIME:FILEPATH=C:/msys64/mingw64/bin/libglib-2.0-0.dll \

Error: My build in Visual Studio has 200+ errors

Solution:

Need to make these edits https://github.com/lcm-proj/lcm/issues/256

In lcm/windows/WinPorting.cpp, include winsock2.h before Mswsock.h, i.e., replace

#include <Mswsock.h>
#include <stdio.h>
#include <winsock2.h>

with

#include <stdio.h>
#include <winsock2.h>
#include <Mswsock.h>

In lcmgen/emit_go.c, replace

#include <unistd.h>
#ifdef WIN32
#define __STDC_FORMAT_MACROS  // Enable integer types
#endif

with

#ifndef WIN32
#include <unistd.h>
#endif
#ifdef WIN32
#define F_OK 0                /* Test for existence.  */
#define __STDC_FORMAT_MACROS  // Enable integer types
#endif

In the CMake GUI, uncheck LCM_ENABLE_GO, LCM_ENABLE_LUA, LCM_ENABLE_TESTS. Hopefully I won't need those. I didn't spend too much time troubleshooting.

Build in Release. (I don't have the debug Python library python36_d.lib.)

Or use this repository which fixes them: https://github.com/AmyPhung/lcm

Unused Notes

(Note: using gvsbuild instructions to work with Visual Studio. Follow the [gvsbuild instructions] here's a few install notes + Follow these instructions to set-up (https://github.com/wingtk/gvsbuild) + Install MSYS2 (https://www.msys2.org/) + Note: I had MSYS2 already installed but it wouldn't update properly for me so I reinstalled it + pacman -Syu + Install Python 3.6 + Note: I already had this installed + If you get really weird errors when running the pacman commands, try rebooting your computer, deleting the MSYS folder, and reinstalling.

cd C:\gtk-build\github\gvsbuild

Use install command for 64-bit system and Visual Studio 2019 python .\build.py build -p x64 --vs-ver 19 gtk3

GLib (Run-time, dev) gettext-runtime (Run-time)

⚠️ **GitHub.com Fallback** ⚠️