lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
944 stars 385 forks source link

lcm-1.5.0 doesn't build on Ubuntu 18.04 (WSL2) - RESOLVED: Issue was a Windows MSYS2 install being used by cmake #483

Closed DanielChaseButterfield closed 6 months ago

DanielChaseButterfield commented 6 months ago

I am trying to build lcm-1.5.0 on Ubuntu 18.04 (in Windows Subsystem for Linux).

I have installed cmake-3.28 from source, as lcm requires a cmake version of 3.12+, and the default cmake version installed through apt was 3.10. I have also installed build-essential and libglib2.0-dev as required

I ran the following commands in the root of the lcm repository:

mkdir build
cd build
cmake ..
make

The make process get to about 2%, and then fails. Here is my standard output:

[  1%] Built target lcm_use_file
[  2%] Building C object lcm/CMakeFiles/lcm-static.dir/lcm.c.o
lcm/CMakeFiles/lcm-static.dir/build.make:89: recipe for target 'lcm/CMakeFiles/lcm-static.dir/lcm.c.o' failed
CMakeFiles/Makefile2:568: recipe for target 'lcm/CMakeFiles/lcm-static.dir/all' failed
Makefile:165: recipe for target 'all' failed

And here is a VERY SMALL SAMPLE of the 9000+ lines of error output:

In file included from /usr/include/glib-2.0/glib/glist.h:32:0,
                 from /usr/include/glib-2.0/glib/ghash.h:33,
                 from /usr/include/glib-2.0/glib.h:50,
                 from /home/dnois/lcm-1.5.0/lcm/lcm.c:5:
/usr/include/glib-2.0/glib/gmem.h: In function ‘__declspec’:
/usr/include/glib-2.0/glib/gmem.h:366:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘GMemVTable’
 GLIB_VAR GMemVTable *glib_mem_profiler_table;
          ^~~~~~~~~~
In file included from /mnt/c/msys64/mingw64/lib/glib-2.0/include/glibconfig.h:9:0,
                 from /usr/include/glib-2.0/glib/gtypes.h:32,
                 from /usr/include/glib-2.0/glib/galloca.h:32,
                 from /usr/include/glib-2.0/glib.h:30,
                 from /home/dnois/lcm-1.5.0/lcm/lcm.c:5:
/usr/include/glib-2.0/glib/gmem.h:367:1: error: expected declaration specifiers before ‘__attribute__’
 GLIB_DEPRECATED_IN_2_46
 ^
In file included from /usr/include/glib-2.0/glib/glist.h:33:0,
                 from /usr/include/glib-2.0/glib/ghash.h:33,
                 from /usr/include/glib-2.0/glib.h:50,
                 from /home/dnois/lcm-1.5.0/lcm/lcm.c:5:
/usr/include/glib-2.0/glib/gnode.h:36:24: error: storage class specified for parameter ‘GNode’
 typedef struct _GNode  GNode;
                        ^~~~~
/usr/include/glib-2.0/glib/gnode.h:47:3: error: storage class specified for parameter ‘GTraverseFlags’
 } GTraverseFlags;
   ^~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gnode.h:56:3: error: storage class specified for parameter ‘GTraverseType’
 } GTraverseType;
   ^~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gnode.h:58:40: error: expected declaration specifiers or ‘...’ before ‘GNode’
 typedef gboolean (*GNodeTraverseFunc) (GNode        *node,
                                        ^~~~~
/usr/include/glib-2.0/glib/gnode.h:60:36: error: expected declaration specifiers or ‘...’ before ‘GNode’
 typedef void  (*GNodeForeachFunc) (GNode        *node,
                                    ^~~~~
/usr/include/glib-2.0/glib/gnode.h:75:20: error: storage class specified for parameter ‘GCopyFunc’
 typedef gpointer (*GCopyFunc)            (gconstpointer  src,
                    ^~~~~~~~~
/usr/include/glib-2.0/glib/gnode.h:83:3: error: expected specifier-qualifier-list before ‘GNode’
   GNode   *next;
   ^~~~~
/usr/include/glib-2.0/glib/gnode.h:114:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*  g_node_new  (gpointer    data);
      ^
/usr/include/glib-2.0/glib/gnode.h:116:24: error: expected declaration specifiers or ‘...’ before ‘GNode’
 void  g_node_destroy  (GNode    *root);
                        ^~~~~
/usr/include/glib-2.0/glib/gnode.h:118:23: error: expected declaration specifiers or ‘...’ before ‘GNode’
 void  g_node_unlink  (GNode    *node);
                       ^~~~~
/usr/include/glib-2.0/glib/gnode.h:120:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*   g_node_copy_deep       (GNode            *node,
      ^
/usr/include/glib-2.0/glib/gnode.h:124:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*   g_node_copy            (GNode            *node);
      ^
/usr/include/glib-2.0/glib/gnode.h:126:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*  g_node_insert  (GNode    *parent,
      ^
/usr/include/glib-2.0/glib/gnode.h:130:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*  g_node_insert_before (GNode    *parent,
      ^
/usr/include/glib-2.0/glib/gnode.h:134:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*   g_node_insert_after    (GNode            *parent,
      ^
/usr/include/glib-2.0/glib/gnode.h:138:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*  g_node_prepend  (GNode    *parent,
      ^
/usr/include/glib-2.0/glib/gnode.h:141:25: error: expected declaration specifiers or ‘...’ before ‘GNode’
 guint  g_node_n_nodes  (GNode    *root,
                         ^~~~~
/usr/include/glib-2.0/glib/gnode.h:142:6: error: expected declaration specifiers or ‘...’ before ‘GTraverseFlags’
      GTraverseFlags    flags);
      ^~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gnode.h:144:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*  g_node_get_root (GNode    *node);
      ^
/usr/include/glib-2.0/glib/gnode.h:146:30: error: expected declaration specifiers or ‘...’ before ‘GNode’
 gboolean g_node_is_ancestor (GNode    *node,
                              ^~~~~
/usr/include/glib-2.0/glib/gnode.h:147:6: error: expected declaration specifiers or ‘...’ before ‘GNode’
      GNode    *descendant);
      ^~~~~
/usr/include/glib-2.0/glib/gnode.h:149:23: error: expected declaration specifiers or ‘...’ before ‘GNode’
 guint  g_node_depth  (GNode    *node);
                       ^~~~~
/usr/include/glib-2.0/glib/gnode.h:151:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
 GNode*  g_node_find  (GNode    *root,
      ^
/usr/include/glib-2.0/glib/gnode.h:239:24: error: expected declaration specifiers or ‘...’ before ‘GNode’
 void  g_node_traverse (GNode    *root,
                        ^~~~~
/usr/include/glib-2.0/glib/gnode.h:240:6: error: expected declaration specifiers or ‘...’ before ‘GTraverseType’
      GTraverseType    order,
      ^~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gnode.h:241:6: error: expected declaration specifiers or ‘...’ before ‘GTraverseFlags’
      GTraverseFlags    flags,
      ^~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gnode.h:243:6: error: unknown type name ‘GNodeTraverseFunc’; did you mean ‘GCompareFunc’?
      GNodeTraverseFunc func,

... and so on...

Does anyone have any idea of what could be going wrong? There seems to be an incredible high number of glib errors, but since I've installed libglib2.0-dev with apt, I'm pretty confident that my installation is correct.

ihilt commented 6 months ago

I tested on Ubuntu 18.04 WSL2 and it built successfully. A difference from your setup is I installed CMake with pip instead of from source. What version of WSL do you have, wsl --version?

DanielChaseButterfield commented 6 months ago

@ihilt My wsl version is 2 as well. This the output of running wsl --version on the Windows Command Prompt:

WSL version: 2.0.14.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22635.2841

You mentioned that you got it working by installing cmake with pip, so I also tried with that setup. I uninstalled cmake from source by running sudo make uninstall in the source directory, and I also uninstalled an older version of cmake from apt by running sudo apt remove cmake. I installed cmake again through Python3 pip with the command python3 -m pip install cmake, which installed cmake 3.27. I ran hash -r to forget the path to the previous cmake install, and when I run cmake --version, I now get:

cmake version 3.27.9

This tells me that I've now replicated your cmake install. However, after deleting the build directory for lcm, and re-running the commands, I get the same error output:

...resuming near the end...

/usr/include/glib-2.0/glib/gnode.h:36:24: error: declaration for parameter ‘GNode’ but no such parameter
 typedef struct _GNode  GNode;
                        ^~~~~
In file included from /usr/include/glib-2.0/glib/glist.h:32:0,
                 from /usr/include/glib-2.0/glib/ghash.h:33,
                 from /usr/include/glib-2.0/glib.h:50,
                 from /home/dnois/lcm-1.5.0/lcm/lcm.c:5:
/usr/include/glib-2.0/glib/gmem.h:362:19: error: declaration for parameter ‘g_mem_gc_friendly’ but no such parameter
 GLIB_VAR gboolean g_mem_gc_friendly;
                   ^~~~~~~~~~~~~~~~~
/home/dnois/lcm-1.5.0/lcm/lcm.c:508:1: error: expected ‘{’ at end of input
 }
 ^
lcm/CMakeFiles/lcm-static.dir/build.make:89: recipe for target 'lcm/CMakeFiles/lcm-static.dir/lcm.c.o' failed
make[2]: *** [lcm/CMakeFiles/lcm-static.dir/lcm.c.o] Error 1
CMakeFiles/Makefile2:568: recipe for target 'lcm/CMakeFiles/lcm-static.dir/all' failed
make[1]: *** [lcm/CMakeFiles/lcm-static.dir/all] Error 2
Makefile:165: recipe for target 'all' failed
make: *** [all] Error 2

My cmake build process seems to work fine though:

CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 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.

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GLib2_glib: /mnt/c/msys64/mingw64/lib/libglib-2.0.a
-- Found GLib2: /mnt/c/msys64/mingw64/lib/libglib-2.0.a  found components: glib
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__std_gnu99
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__std_gnu99 - Success
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wall
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wall - Success
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wshadow
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wshadow - Success
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wuninitialized
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wuninitialized - Success
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wunused_variable
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wunused_variable - Success
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Werror_return_type
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Werror_return_type - Success
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wno_unused_parameter
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wno_unused_parameter - Success
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wno_format_zero_length
-- Performing Test CMAKE_C_COMPILER_SUPPORTS__Wno_format_zero_length - Success
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wall
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wall - Success
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wshadow
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wshadow - Success
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wuninitialized
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wuninitialized - Success
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wunused_variable
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wunused_variable - Success
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Werror_return_type
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Werror_return_type - Success
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wno_unused_parameter
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wno_unused_parameter - Success
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wno_format_zero_length
-- Performing Test CMAKE_CXX_COMPILER_SUPPORTS__Wno_format_zero_length - Success
-- Building LCM 1.5.0 (ABI v1)
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Found Python: /usr/bin/python3.6 (found version "3.6.9") found components: Interpreter
-- Found Python: /usr/bin/python3.6 (found version "3.6.9") found components: Interpreter Development Development.Module Development.Embed
-- Found Java: /usr/bin/java (found suitable version "11.0.19", minimum required is "1.8")
-- Found Lua: /usr/lib/x86_64-linux-gnu/liblua5.3.so;/mnt/c/msys64/mingw64/lib/libm.a (found version "5.3.3")
Unable to parse the Go version string:
-- Could NOT find Go (missing: GO_VERSION GO_PLATFORM GO_ARCH)
CMake Deprecation Warning at lcm-cmake/lcmUtilities.cmake:34 (cmake_minimum_required):
  Compatibility with CMake < 3.5 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.
Call Stack (most recent call first):
  test/types/CMakeLists.txt:1 (include)

-- CPack: Packages will be placed under /home/dnois/lcm-1.5.0/build/packages
-- Configuring done (30.3s)
-- Generating done (0.1s)
-- Build files have been written to: /home/dnois/lcm-1.5.0/build

From this, I conclude that my cmake install is probably correct. Seeing as my WSL2 install also matches yours, I'm more or less at a loss of what could be the issue.

ihilt commented 6 months ago

Interesting, CMake is finding GLib installed from MSYS.

-- Found GLib2: /mnt/c/msys64/mingw64/lib/libglib-2.0.a  found components: glib

My output shows:

-- Found GLib2: /usr/lib/x86_64-linux-gnu/libglib-2.0.so  found components: glib

I installed GLib with apt-get install libglib2.0-dev.

DanielChaseButterfield commented 6 months ago

Okay, that was it. I have a MSYS2 installed on my Windows Desktop. Somehow, cmake was able to see my glib installation for the windows side, and was using that instead of my libglib2.0-dev install. I uninstalled MSYS2 on the Windows side, and I got the correct output in my cmake .. command:

-- Found GLib2_glib: /usr/lib/x86_64-linux-gnu/libglib-2.0.so
-- Found GLib2: /usr/lib/x86_64-linux-gnu/libglib-2.0.so  found components: glib

Now, it properly builds and installs! Thanks so much @ihilt.

Obviously, this is out of the scope of this project, but I wonder why cmake could see files from the Windows side while it was in WSL...