Skip to content
Advertisement

Bash on Ubuntu on Windows, Run Linux Commands to Install a Windows Program

I am new to Linux, but I am having a lot of trouble installing an R package that does not have windows binaries. I would rather not install a full Linux install and move everything. Judging by Windows Interoperability it seems like this should be possible. I want to do any one of the options from the GNU R package cplexAPI documentation below in the block quote. I have tried:

C:Userszejas>bash
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ R CMD INSTALL cplexAPI_1.3.2.tar.gz
The program 'R' is currently not installed. You can install it by typing:
sudo apt-get install r-base-core
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$

Based on the example:

$/mnt/c/Windows/System32/notepad.exe

I have tried:

zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ $/mnt/C/Program Files/Microsoft/MRO-3.3.1/bin
bash: $/mnt/C/Program: No such file or directory
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/C/Program Files/Microsoft/MRO-3.3.1/bin
bash: /mnt/C/Program: No such file or directory
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: /mnt/C/Program: No such file or directory
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ $/mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: $/mnt/C/Program: No such file or directory
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: C/Program: No such file or directory
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ $/mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: $/mnt/C/Program: No such file or directory
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/C/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
bash: /mnt/C/Program: No such file or directory
zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/c/Program Files/Microsoft/MRO-3.3.1/bin/R.exe
 bash: /mnt/c/Program: No such file or directory
 zejas@DESKTOP-JASON:/mnt/c/Users/zejas$ /mnt/c/Windows/System32/notepad.exe
 bash: /mnt/c/Windows/System32/notepad.exe: cannot execute binary file: Exec format error

Any ideas?

—————————————————————————-

Linux and MacOS X installation

—————————————————————————-

The locations of the CPLEX callable library and the CPLEX include directory can be found in /README.html>, where is the CPLEX installation directory. Also have a look at the variables CLNFLAGS and COPT in the example Makefile of your CPLEX installation. There, the variable CPLEXLIBDIR points to the callable library directory.

There are several ways of installing the cplexAPI package:

1) Set variables PKG_CFLAGS, PKG_CPPFLAGS and PKG_LIBS directly, e.g.:

R CMD INSTALL –configure-args =” PKG_CFLAGS=’-m64 -fPIC’
PKG_CPPFLAGS=’-I/cplex/include’
PKG_LIBS=’-L${CPLEXLIBDIR} -lcplex -m64 -lm -pthread'”
cplexAPI_x.x.x.tar.gz

PKF_CFLAGS is optional, but both PKG_CPPFLAGS and PKG_LIBS must be given.

2) Use –with-cplex-:

–with-cplex-include=PATH with PATH being the include directory of CPLEX

–with-cplex-lib=PATH with PATH being the directory containing the callable library of CPLEX.

R CMD INSTALL –configure-args=” –with-cplex-include=/path/to/include/dir –with-cplex-lib=/path/to/lib/dir” cplexAPI_x.x.x.tar.gz

When using –with-cplex-, both arguments –with-cplex-lib and –with-cplex-include must be given.

–with-cplex-link=-l… libraries to path to the linker during compilation.

If –with-cplex-link is not given, ‘-lcplex -lm -pthread’ will be used as default.

–with-cplex-cflags=… optional CFLAGS

A further argument can be used in order to use the debuging routines included in the C API of CPLEX:

–with-cplex-check=PATH with PATH being the directory containing the file check.c from the CPLEX examples directory.

R CMD INSTALL –configure-args=”
–with-cplex-lib=’/path/to/lib/dir’ –with-cplex-include=’/path/to/include/dir’ –with-cplex-link=’-lcplex -m64 -lm -pthread’ –with-cplex-cflags=’-m64 -fPIC’ –with-cplex-check=’/path/to/examples/dir/examples/src/c'” cplexAPI_x.x.x.tar.gz

3) Give the location of the CPLEX installation:

–with-cplex-dir=PATH with PATH being the CPLEX directory. This is not the CPLEX installation directory , it is the directory including the lib/ include/ and examples/ directory. Usually this is /cplex.

R CMD INSTALL –configure-args=”
–with-cplex-dir=’/cplex'” cplexAPI_x.x.x.tar.gz

This procedure will take the first system type and library format it finds. Information reqired for the compilation is taken from the example Makefile.

4) Give no information:

R CMD INSTALL cplexAPI_x.x.x.tar.gz This procedure will try to find the CPLEX interactive optimizer, or the CPLEX_BIN environment variable pointing to the CPLEX interactive optimizer will be used. The directory two levels above is used as CPLEX directory, all other information is taken from teh CPLEX example Makefile as in #3 above.

Advertisement

Answer

First, to access a path with spaces in it, use double quotes:

"/mnt/c/Program Files/Microsoft/MRO-3.3.1/bin/R.exe"

Second, you can only run Windows programs from bash if you have build 14951 of Windows 10 or later. This is noted at the top of the MSDN page you linked to:

The Windows Subsystem for Linux can invoke native Windows binaries and be invoked from a Windows command line. This feature is available to Windows 10 users running Anniversary Update build 14951.

This build is still in Windows Insider release, so isn’t generally available yet (latest GA is build 14393 as of 16 Jan 2017). For now, you can install cbwin if you want this functionality.

Third, running R from a Linux shell won’t magically solve the reason why a precompiled binary package isn’t available: cplexAPI depends on the CPLEX Studio application from IBM, and you still need to have this available for the R package to work. Assuming you do have this available, you can download the cplexAPI source and compile the package from Windows, without touching the bash shell.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement