Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Error: Could NOT find SWIG (missing: SWIG_DIR)

I wanted to test out Pocketsphinx in Node.JS. It says I need to install Swig version 3.0.7 or above.

I think I installed all the other dependencies correctly. I can even type Swig commands in the Terminal now, but I keep getting this error whenever I run npm install pocketsphinx:

CMake Error at /usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find SWIG (missing: SWIG_DIR) (Required is at least version
  "3.0.7")
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindSWIG.cmake:75 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:4 (find_package)

I tried brew install swig, npm install swig, and npm install -g swig. I tried going to the swig download page and following the installation instructions, but nothing I seem to do stops the error from happening. I'm trying this on a Macbook by the way.

I really have no clue what I'm doing here. I just wanted to test out Pocketsphinx and now I've installed Swig in 4 different places, and CMake can't seem to recognise any of them.

Any help would be wonderful!

like image 479
MysteryPancake Avatar asked Jan 22 '18 13:01

MysteryPancake


2 Answers

Came here looking for the Windows-based error. I found a solution that seems to work for me, so decided to post it here.

  • Create two environment variables in the "System Variables" section: SWIG_DIR and SWIG_EXECUTABLE. These must point to /path/to/the/swig/dir/ and /path/to/the/swig/dir/swig.exe respectively.
  • After this, add one more entry to the PATH variable: /path/to/the/swig/dir. Test this out by typing swig in the command prompt. It should display a message must specify an input file. Use -help for available options.
  • Restart the computer to apply all environment variable changes. find_package(SWIG required) should work correctly now.
like image 160
Lycanthropeus Avatar answered Nov 15 '22 22:11

Lycanthropeus


Check the source code for the FindSwig.cmake.

Unfortunately, if a find script does not work as expected and you do not see right away why that is the case, you usually have to dig into its source. In your case, it looks like CMake was able to find and run the SWIG executable, but then failed to obtain the swig directory.

Try manually running swig -swiglib and check that the printed directory indeed contains a swig.swg file. Also, be sure that the swig executable found by CMake is actually the correct one (you can verify this by inspecting the value of SWIG_EXECUTABLE in either the cmake-gui, the ccmake curses interface, or in the CMakeCache.txt file directly).

Note that CMake will not update the executable path once it has been found! So if you make changes to your system that influence the executable location, you will have to clear the cache (eg. by deleting the CMakeCache.txt) and re-run CMake for the changes to take effect.

like image 26
ComicSansMS Avatar answered Nov 15 '22 22:11

ComicSansMS