Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32 x64 Install Issues #99

Open
kheaactua opened this issue Sep 1, 2016 · 21 comments
Open

Win32 x64 Install Issues #99

kheaactua opened this issue Sep 1, 2016 · 21 comments

Comments

@kheaactua
Copy link

I can't seem to install LCM v1.3.1 on Windows with msvc-12.

I followed the advice in the WinSpecific folder for GLIB, i.e. I've installed msys2 and mingw. In the msys shell I installed the mingw-w64-x86_64-gcc package along with autoconf, automake, and other utilities (git, vim, etc)

Am I suppose to build LCM in the msvc environment? If I do, I can't seem to link. At first because at first it was missing ws2_32, but even after that it's missing a bunch of it's own symbols it seems like lcm_internal_pipe_write. Even just to get to that point, in lcm/windows/WinPorting.h:10 I have to comment out lines 10 and 11 to avoid conflicts.

I noticed there are CMake files here that have a lot of if (WIN32), but when running cmake from cmd, I can't get them to find my glib-2.0 libs no matter what I set GLIB_PATH to.

I'm going to go back to trying to build glibc without mingw to see if that helps.. But overall I've now lost two full work days trying to build LCM on Windows (whereas on Linux it took me under a minute I think from cloning to having it built.)

@kheaactua
Copy link
Author

kheaactua commented Sep 2, 2016

So it's been 2.5 days, but I finally got it to build.

The steps I recommend are:

  • Install msys, perform the updates, etc. And install
    • mingw-w64-x86_64-gcc
    • mingw-w64-x86_64-glib2
    • glib2-devel
      Note, pacman timesout after 10 seconds, so it fails on most packages. To resolve that, read /etc/pacman.d/* for a list of mirrors, wget the packages you need, and install them with pacman -U <package name>.tar.xz
  • In cmd, go to your LCM directory, and run CMake, i.e. cmake .. -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=<path to install>, and never mind about setting GLIB_PATH or anything, it would work.
  • Open cmake-gui . in your build directory, and set all the glib options manually, for instance in mine:
    • GLIB2_GLIBCONFIG_INCLUDE_DIR=C:\msys64\mingw64\lib\glib-2.0\include
    • GLIB2_GLIB_INCLUDE_DIR=C:\msys64\usr\include\glib-2.0
    • GLIB2_GLIB_LIBRARY=C:\msys64\mingw64\lib\libglib-2.0.dll.a
    • GLIB2_GLIB_RUNTIME=C:\msys64\mingw64\bin\libglib-2.0.dll

Then, for msvc-12 (Visual Studio 2013), you'll have to modify the source to get it to work.

  • in ioutils.h, remove the inlines, i.e.
-static inline int fwrite32(FILE *f, int32_t v)
+static int fwrite32(FILE *f, int32_t v)
  • In buftest-sender.c, change snprintf to _snprintf

This should now build.

@tprk77
Copy link
Member

tprk77 commented Sep 2, 2016

Hi Matthew, I just wanted to thank you for your efforts. I know no one likes build problems, and 2.5 days sounds pretty rough. Please accept our apologies, for you having to go through that! Fortunately, you've given us alot of good information. I think we can update the Win32 README and source so this doesn't happen again. Thanks for contributing!

@mwoehlke-kitware
Copy link
Contributor

I noticed there are CMake files here that have a lot of if (WIN32), but when running cmake from cmd, I can't get them to find my glib-2.0 libs no matter what I set GLIB_PATH to.

Drake is building LCM just fine on Windows, at least with VS 2015. Note that we use pre-built GTK from http://win32builder.gnome.org/gtk+-bundle_3.6.4-20131201_win64.zip. (We might not be building the tests, however...)

Also, with CMake, you may want to pass -DCMAKE_PREFIX_PATH=path/to/gtk/root (i.e. the top level directory of the unpacked GTK zip file) instead of setting $ENV{GLIB_PATH}. You should not need to set the various GTK variables directly.

In buftest-sender.c, change snprintf to _snprintf

WinPorting.h should take care of this sort of nonsense... it looks like buftest-sender.c doesn't include it, though.

@kheaactua
Copy link
Author

hey @mwoehlke-kitware I THINK (if I remember right) that WinPorting.h takes care of the snprintf issue in VS 2015, but not VS 2013. I could be wrong, this was weeks ago and there were a lot of issues I looking up. :)

I looked everywhere for pre-built GTK/glib, that's awesome that you posted a location. I just posted that link to some SO answers I had found when searching that were linking to dead links.

@mwoehlke-kitware
Copy link
Contributor

WinPorting.h has this:

#if _MSC_VER < 1900
#define snprintf    _snprintf
#endif

As I read it, that says that VS 2015 has snprintf (as specified by C99) and should not use _snprintf, while on earlier versions, snprintf is preprocessor-replaced with _snprintf. (IIRC, I added the version check because VS 2015 didn't like _snprintf being used.)

Possibly you are recalling backwards? 😉

At any rate, it looks like buftest-sender.c ought to include WinPorting.h. I'll try to take a look at the unit tests on Windows at some point, but I'm using VS 2015 (which likely hides this issue) and my access to a Windows machine is a little sporadic. If you can submit a PR, that would be awesome!

Thanks for debugging this, and my apologies also for the time you lost.

@yoojinoh
Copy link

yoojinoh commented Jan 4, 2017

Hi Matthew, thank you for your efforts!
I'm trying to install LCM on windows, but I just can't understand how this works..I'm fairly new to cmake and using cmd. I've searched for every tutorial on how to install it properly, but it seems that is has a lot of gaps for a beginner to deal with.

In cmd, go to your LCM directory, and run CMake, i.e. cmake .. -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=, and never mind about setting GLIB_PATH or anything, it would work.
Open cmake-gui . in your build directory, and set all the glib options manually, for instance in mine:
GLIB2_GLIBCONFIG_INCLUDE_DIR=C:\msys64\mingw64\lib\glib-2.0\include
GLIB2_GLIB_INCLUDE_DIR=C:\msys64\usr\include\glib-2.0
GLIB2_GLIB_LIBRARY=C:\msys64\mingw64\lib\libglib-2.0.dll.a
GLIB2_GLIB_RUNTIME=C:\msys64\mingw64\bin\libglib-2.0.dll

could you explain with a little more detail on the above steps, like how to set the "install path", and if I run cmake in cmd it says "does not appear to contain CMakeLists.txt". How do I solve this? Also, in the cmake-gui, what do I set for the "source code" blank and the "build the binary" path?
I would really appreciate your help! I spent the whole week installing and deleting and reinstalling...

@mwoehlke-kitware
Copy link
Contributor

When building software with CMake, there are two directories to keep in mind. The "source directory" refers to the top level directory of the project you want to build, which contains the project's sources. The "build directory" (or "binary directory") is where the build artifacts are created. It is recommended that these be different (an "out of source build"). For example, if you cloned the LCM repository to C:\Users\Joy\code\lcm, that would be your source directory. Many users, especially beginners, will use a build directory like C:\Users\Joy\code\lcm\build. These are the directories that appear at the very top of the GUI.

CMAKE_INSTALL_PREFIX (this is a CMake variable; it will appear in the "main" section of the GUI after you 'configure' for the first time) specifies the root directory of where the project will be installed when you build the install target. On Windows, this might be e.g. C:\Program Files\LCM.

if I run cmake in cmd it says "does not appear to contain CMakeLists.txt". How do I solve this?

When using the CLI version of CMake (or ccmake, on *nix), you must give it the path to either a) the source tree you want to build or b) an existing build tree. The instruction that says to run cmake .. assumes that you want to build in a subfolder (usually named build; see above) that is a direct descendant of your source tree, and that you have cdd into this directory. (Note: when pointing to a source tree, the current working directory will become the build tree.)

@yoojinoh
Copy link

yoojinoh commented Jan 6, 2017

Thank you! I think I have successfully generated the cmake.

In the README file in the WinSpecific of the original file, it says build the /WinSpecific/vs12/LCM.sln in visual studios. But, when I do, I get a bunch of errors at first saying missing glib.h, which I then manually set the directory in the Project Properties for all projects in the LCM solution.
Also, I encounter 'lcmtest-primitives_t.h': No such file or directory, and a lot of LNK 1120: unresolved externals and LNK2001: unresolved external symbol (ex. _g_cond_brodcast, _g_free, etc.) as well.

Could you help me on this? I am so desperate to install LCM on windows! I lost the whole week trying to get it right but there seems to be no detailed tutorial on how to install LCM on windows..

@mwoehlke-kitware
Copy link
Contributor

In the README file in the WinSpecific of the original file, it says build the /WinSpecific/vs12/LCM.sln in visual studios.

Huh. Um... don't do that. Use the build files generated by CMake.

The process should be:

  1. Use CMake to generate build files. (You probably want to select the appropriate VS project type when asked what sort of build files to create / what "generator" to use.)
  2. Open the resulting solution in VS and build the "ALL_BUILD" target.

There may be no specific tutorial for LCM because building LCM should not be appreciably different than building any other project that uses CMake.

(If I can ever get my Windows machine to let me log in, I'll try to take a look at making things better with the strangely packaged MSYS version of glib...)

@mwoehlke-kitware
Copy link
Contributor

In the README file in the WinSpecific of the original file, it says build the /WinSpecific/vs12/LCM.sln in visual studios.

So... I took another look at this, and I am confused. There are not .sln files (except for .NET) provided in master, which uses CMake, and there are no CMake files provided in 1.3-LTS. Exactly what version of LCM are you trying to build?

Note: I actually have never tried to build non-CMake LCM on Windows, and it's very possible that things on the MSYS side have changed since it was last tested that may make it difficult to build 1.3-LTS without also using an older glib package.

@yoojinoh
Copy link

I was confused with the instructions provided in the original LCM-1.3.1 zip file and the master file provided here. The master file doesn't have the LCM.sln file, so I used the original LCM file.

Anyways, When I try to build the ALL__BUILD project file, I still encounter "Cannot open include file 'lcmtest_primitives_t.h" and lcmtest/primitives_t.h': No such file or directory" and a bunch of LNK2001: unresolved external symbol g(something).

I should try to build it from the beginning to see if I have done anything wrong. Thank you.

@braanan
Copy link

braanan commented Jan 24, 2017

Thanks to the insightful comments above I was able to build LCM on Windows 7 64.

Here's an attempt to document the installation process (that worked for me) on a clean Windows machine. Hopefully someone will find this useful...

Approach overview:

  1. Use minGW via MSYS2 is install glib2 dependencies.
  2. Build LCM using Cmake and MS Visual Studio 2015 Community.

1. Install dependencies

  • Install Python (64bit):
    • Define PYTHONPATH environment variable:
      PYTHONPATH=C:\Python27;C:\Python27\Scripts;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;
    • Add PYTHONPATH to windows system PATH.
  • Install Git.
  • Install Cmake.
  • Install MSYS2, perform the updates, etc.
  • Open MSYS shell and install:
    pacman -S base-devel
    pacman -S gcc
    pacman -S glib2 glib2-devel mingw-w64-x86_64-glib2
  • Add <msys2_root>\mingw64\bin to windows system PATH
  • Define GLIB_PATH environment variable:
    GLIB_PATH=<msys2_root>\mingw64
  • Clone LCM
    git clone https://github.com/lcm-proj/lcm.git

2. Build LCM

Open CMD as administrator.

> mkdir build
> cd build
> cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release -DLCM_ENABLE_TESTS=OFF -DCMAKE_INSTALL_PREFIX=<path to install>

Issue (I think):
FindGLib2.cmake isn't finding glib2.0 dependencies that are installed in the mingw64\lib\ folder.

Workaround...
In build\: open cmake-gui, and set missing glib2 options manually (thanks @kheaactua!).
For example:

GLIB2_GLIBCONFIG_INCLUDE_DIR=C:\msys64\mingw64\lib\glib-2.0\include
GLIB2_GLIB_INCLUDE_DIR=C:\msys64\mingw64\include\glib-2.0
GLIB2_GLIB_LIBRARY=C:\msys64\mingw64\lib\libglib-2.0.dll.a
GLIB2_GLIB_RUNTIME=C:\msys64\mingw64\bin\libglib-2.0.dll
  • Click Configure, and then Generate to create lcm.sln.
  • Finally, call cmake's build and install from CMD:
    cmake --build . --target INSTALL --config Release
  • Add <path to install>\bin to system PATH.
  • Add <path to install>\lib\site-packages to PYTHONPATH.

That should do it.

@mwoehlke-kitware
Copy link
Contributor

Open CMD as administrator

I would note that this is only needed to perform the install, assuming you are installing to a "protected" location.

FindGLib2.cmake isn't finding glib2.0 dependencies that are installed in the mingw64\lib\ folder.

You might be able to get FindGLib2.cmake to work more out-of-the-box with set CMAKE_PREFIX_PATH="C:\msys64\mingw64".

@braanan
Copy link

braanan commented Jan 25, 2017

Thanks @mwoehlke-kitware.

You might be able to get FindGLib2.cmake to work more out-of-the-box with set CMAKE_PREFIX_PATH="C:\msys64\mingw64".

Actually tried that per your suggestion above - didn't work.

@avikde
Copy link

avikde commented Jun 3, 2017

I just did this and thought I would add to @braanan 's very helpful post that instead of opening the GUI which did not work for me, placing all the commands in command prompt did:

cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release -DLCM_ENABLE_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../build -DGLIB2_GLIBCONFIG_INCLUDE_DIR="C:\msys64\mingw64\lib\glib-2.0\include" -DGLIB2_GLIB_INCLUDE_DIR="C:\msys64\mingw64\include\glib-2.0" -DGLIB2_GLIB_LIBRARY="C:\msys64\mingw64\lib\libglib-2.0.dll.a" -DGLIB2_GLIB_RUNTIME="C:\msys64\mingw64\bin\libglib-2.0.dll"

@obiben
Copy link

obiben commented Sep 22, 2017

Did anyone make any progress with this? I remember taking 2 days to successfully build LCM the first time, and can't remember what I did different the last time and am trying to compile python bindings for a second machine with no luck - glib giving me trouble with both the mingw glib install and a pre-packaged version I found last time.

Generating the projects works, but building dlls complains about unresolved external symbols.

@obiben
Copy link

obiben commented Sep 25, 2017

@avikde 's command worked for me (with Visual Studio 15 2017 Win64) after I:

  • Installed windows 10 sdk
  • Reinstalled python 3.6 x64 (default download was 32, duh)
  • Switched configuration to Debug in visual studio

Some of these might not have been necessary.

@cmpute
Copy link

cmpute commented Feb 24, 2018

Guys, you could try vcpkg to install lcm now 😃

@mshaheerm
Copy link

@cmpute how can i use this lcm.dll generated from vcpkg for python then?

@mshaheerm
Copy link

capture
i am trying to build from cmake but it seems to throw an error. how can i fix this

@avikde
Copy link

avikde commented Aug 14, 2018

@mshaheerm you need to run that in a "Developer Command Prompt"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants