Yarp: Unknown CMake command "swig_add_library" error, while compiling bindings

Created on 17 Feb 2018  Â·  10Comments  Â·  Source: robotology/yarp

Related: #1178

The main issue here is that from here we see swig_add_library was introduced in CMake 3.8.0, while http://wiki.icub.org/wiki/YARP_Supported_Distributions indicates it's safe to use CMake 3.0.2 (maybe say 3.2.2, or at least Xenial's 3.5.1).

Current master (YARP 2.3.72) seems to use swig_add_library consistently in a mandatory fashion (no conditionals), at least for python and java.

CMake YARP v3.0.0 Bug Fixed

Most helpful comment

I can confirm that the steps described above no longer lead to the described error: both configure and compilation are successful (same distro: Ubuntu Xenial).

All 10 comments

More refs: https://cmake.org/cmake/help/v3.8/module/UseSWIG.html (and switching to CMake version 3.7 and below).

...goes back to commit 86b118c91fa3c84b22a43597db5c2ebde4dd362f : Bindings: Use swig_add_library instead of swig_add_module; This is now in YCM UseSWIG version.

Will try to trace back which UseSWIG version is being used...

There was actually a pretty live discussion at mentioned commit 86b118c, but not exactly the issue in this case.

Solution on my machines (CMake 3.5.1): the issue was, in fact, having a previously installed YCM version (for accelerating ycm-dependent builds, even if updated to master). Some strange shadowing must have been happening such that the /usr/share/cmake/Modules/UseSWIG.cmake was being invoked rather than any YCM version. So... the solution was to uninstall YCM.

@drdanz et Al: Feel free to close this issue for the historic, and/or open a new YCM issue if you think this is relevant.

@jgvictores Did you have this issue compiling the bindings from yarp build or from an external build?

If it is the second case, I think this might have been fixed by e8b5de1c84deca68f5cfcc5cff11c49dbff2f22b. Do you have a way to try?

The issue the first case, compiling the bindings from yarp build, and still persists. It's easy to replicate:

  1. Install YCM (https://github.com/robotology/ycm)
  2. Download fresh YARP (https://github.com/robotology/yarp)
  3. During cmake step of mkdir build && cd build && cmake .. -DYARP_COMPILE_BINDINGS=ON -DCREATE_PYTHON=ON output:
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable exact version "2.7.12") 
CMake Error at bindings/python/CMakeLists.txt:33 (swig_add_library):
  Unknown CMake command "swig_add_library".
-- Configuring incomplete, errors occurred!

Obscure shadowing, right?

PS: The external build fix will probably be good for the workflow I follow on Windows (broken as of YARP 2.3.72 (2018-02-12), which involves downloading binaries and compiling bindings separately. It's a nice workflow against which I would not put error messages, we can get back to that in the future.

@jgvictores
Add this:
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

This is an upstream issue solved at current YCM master, see https://github.com/robotology/ycm/pull/139.

This is an upstream issue solved at current YCM master, see robotology/ycm#139.

Shall we close this issue?

Sure. Let me give more visibility to https://github.com/robotology/ycm/pull/146, which is a follow-up for future YCM 0.8.

I can confirm that the steps described above no longer lead to the described error: both configure and compilation are successful (same distro: Ubuntu Xenial).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lornat75 picture lornat75  Â·  4Comments

traversaro picture traversaro  Â·  4Comments

diegoferigo picture diegoferigo  Â·  3Comments

jeljaik picture jeljaik  Â·  3Comments

drdanz picture drdanz  Â·  3Comments