*.o: File format not recognized on Windows 7 - r

I wrote an R package called arbintools for some work-related data analysis and put it on Github. I wrote it and have been using it on my Mac for a while without issue; Today, I tried to install the dev-1 branch on a Windows 7 laptop and something related to compiling some Rcpp functions seems to go wrong:
devtools::install_github("mjlacey/arbintools", ref = "dev1")
I get this:
Downloading GitHub repo mjlacey/arbintools#dev1
from URL https://api.github.com/repos/mjlacey/arbintools/zipball/dev1
Installing arbintools
"C:/PROGRA~1/R/R-33~1.0/bin/x64/R" --no-site-file --no-environ --no-save \
--no-restore --quiet CMD INSTALL \
"C:/Users/matla332.USER/AppData/Local/Temp/Rtmp8WWkKC/devtools124c45026af1/mjlacey-arbintools-41dc363" \
--library="C:/Users/matla332.USER/Documents/R/win-library/3.3" \
--install-tests
* installing *source* package 'arbintools' ...
** libs
*** arch - i386
C:\Rtools\mingw_32\bin\nm.exe: RcppExports.o: File format not recognized
C:\Rtools\mingw_32\bin\nm.exe: Rcpp_functions.o: File format not recognized
c:/Rtools/mingw_32/bin/g++ -shared -s -static-libgcc -o arbintools.dll tmp.def RcppExports.o Rcpp_functions.o -Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.0/bin/i386 -lR
RcppExports.o: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'arbintools'
* removing 'C:/Users/matla332.USER/Documents/R/win-library/3.3/arbintools'
* restoring previous 'C:/Users/matla332.USER/Documents/R/win-library/3.3/arbintools'
Error: Command failed (1)
Installing other packages requiring some compilation (like dplyr) worked fine. I also updated R on my Mac to the same version (3.3.0) and reinstalled the package successfully, it's just on the Windows PC it doesn't work. This is beyond my understanding, if anyone has a suggestion or solution I'd be very grateful.

The issue is the .so and .o files are only viable with the same architecture e.g. OS X is 64 bit and Windows is 32bit (mingw_32). Please remove them from dev-1/src and then you should be good to go. These files are automatically built on package install as they are the result of using a compiler.
After they are removed, try to create a .gitignore file with the following:
src/*.o
src/*.so
src/*.dll
This will make OS specific files not selectable for staging and, in turn, commits.
As a general rule of thumb, only keep .cpp or .h files within /src while using Rcpp.

Related

Rserve : ld: library not found for -lssl

I am getting an error while trying to install Rserve 1.8.6. I can successfully install 1.7.3 from CRAN. This is on Mac OS High Sierra.
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [forward] Error 1
make: *** [all] Error 2
ERROR: compilation failed for package ‘Rserve’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rserve’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rserve’
The downloaded source packages are in
‘/private/var/folders/v7/hyxrfmk94p1_03gdrm27fnxncy3vq1/T/RtmpFHKNMe/downloaded_packages’
This worked for me (MacOS):
In terminal:
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
I'm running Mac OS 10.15 Catalina, I've spent 2 days trying to fix this same problem, scouring the internet for help. I finally managed it by cobbling together solutions from a few different sources.
The key thing I was missing was that Mac OS ships with its own version of openssl which it thinks is superior to anything else you can find. It is wrong. What you need to do is go and download the latest version of openssl, install that, then export THAT library to your library path variable. Here are the steps I took with openssl 1.1.1:
Get the version number for the latest version of openssl from the source (https://www.openssl.org/source/) and then manually install it directly where it's supposed to go:
cd /usr/local/src
If you're getting "No such file or directory", make it:
cd /usr/local && mkdir src && cd src
Download openssl using curl (shown) or using the link above to the source code (make sure you put the file in the directory you just made in the previous step):
curl --remote-name https://www.openssl.org/source/openssl-1.1.1f.tar.gz
Extract and cd in:
tar -xzvf openssl-1.1.1f.tar.gz
cd openssl-1.1.1f
Compile and install (these are the 64 bit Mac OS instructions. Refer to the openssl documentation for 32 bit and other OS instructions):
./Configure darwin64-x86_64-cc shared enable-ec_nistp_64_gcc_128 no-ssl2 no-ssl3 no-comp --openssldir=/usr/local/ssl/macos-x86_64
make depend
sudo make install
This created a new openssl folder so when you export the library path you have to feed it the right openssl folder:
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl#1.1/lib/
Hope that helps you if you haven't figured it out yet, and anyone else in the future who is ready to chuck their computer across the room, like I was.

Not able to install RopenCVLite in window os, while working in R

I am trying to install RopenCVLite, working in window os.
I am working in RStudio 3.5.0 in a Windows 7, 64-bit environment.
I am following the installation process tutorial
https://swarm-lab.github.io/ROpenCVLite/articles/install.html
First I have installed Cmake on my computer.
Then I tried to run below code in R, to install "RopenCVLite"
install.packages("pkgbuild") # pkgbuild is not available (for R version 3.5.0)
install.packages("devtools") # make sure you have the latest version from CRAN
library(devtools) # load package
devtools::install_github("r-lib/pkgbuild") # install updated version of pkgbuild from GitHub
library(pkgbuild) # load package
find_rtools() # should be TRUE, assuming you have Rtools 3.5
devtools::install_github("swarm-lab/ROpenCVLite")
I am getting following error
> devtools::install_github("swarm-lab/ROpenCVLite")
Downloading GitHub repo swarm-lab/ROpenCVLite#master
from URL https://api.github.com/repos/swarm-lab/ROpenCVLite/zipball/master
Installing ROpenCVLite
"C:/MANUAL~1/R-35~1.0/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD \
INSTALL \
"C:/Users/dell/AppData/Local/Temp/Rtmps5sa30/devtools1798506c6333/swarm-lab-ROpenCVLite-b9fcf19" \
--library="C:/Manually saved/R-3.5.0/library" --install-tests
* installing *source* package 'ROpenCVLite' ...
+ set -e
+ mkdir inst/tmp
+ mkdir inst/opencv/
+ cd inst/tmp/
+ Rscript -e 'download.file("https://github.com/opencv/opencv/archive/3.4.1.tar.gz", "opencv-3.4.1.tar.gz")'
trying URL 'https://github.com/opencv/opencv/archive/3.4.1.tar.gz'
Content type 'application/x-gzip' length 87051748 bytes (83.0 MB)
==================================================
downloaded 83.0 MB
+ tar zxvf opencv-3.4.1.tar.gz
+ cp ../cap_dshow.cpp opencv-3.4.1/modules/videoio/src/
+ cd opencv-3.4.1
+ '[' -d C:/MANUAL~1/R-35~1.0/bin/x64 ']'
+ mkdir build64
+ cd build64
+ cmake -G 'Unix Makefiles' -DCMAKE_C_COMPILER=C:/Rtools/mingw_64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/Rtools/mingw_64/bin/g++.exe -DCMAKE_RC_COMPILER=C:/Rtools/mingw_64/bin/windres.exe -DCMAKE_MAKE_PROGRAM=C:/Rtools/bin/make.exe -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_opencv_world=OFF -DBUILD_opencv_contrib_world=OFF -DBUILD_matlab=OFF -DPYTHON_EXECUTABLE=OFF -DBUILD_opencv_photo=OFF -DBUILD_PROTOBUF=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=../../../opencv/ ../
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
CMake Error: Error executing cmake::LoadCache(). Aborting.
ERROR: configuration failed for package 'ROpenCVLite'
* removing 'C:/Manually saved/R-3.5.0/library/ROpenCVLite'
In R CMD INSTALL
Installation failed: Command failed (1)
Any suggestion is always appreciated.
Avjit,hope this still help you install ROpenCVLite. I encountered similar error issue just today and it shows
cmake: not found
I was able to figure out and the reason why install is failing when using command:
devtools::install_github("swarm-lab/ROpenCVLite")
it's because when you install cmake, it create its own Path folder under Program Files (on my machine). The sequence should be to install Rtools first on the root folder C such as this:
C:\Rtools
After installation, then install CMake but need to change the Path folder to C:\Rtools, it will create and install CMake under Rtools. This installation message is how I figured out the sequence. THe script is looking at CMake under the Rtools folder:
+ cmake -G 'Unix Makefiles' -DCMAKE_C_COMPILER=C:/Rtools/mingw_64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/Rtools/mingw_64/bin/g++.exe -DCMAKE_RC_COMPILER=C:/Rtools/mingw_64/bin/windres.exe -DCMAKE_MAKE_PROGRAM=C:/Rtools/bin/make.exe -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_opencv_world=OFF -DBUILD_opencv_contrib_world=OFF -DBUILD_matlab=OFF -DPYTHON_EXECUTABLE=OFF -DBUILD_opencv_photo=OFF -DBUILD_PROTOBUF=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=../../../opencv/ ../
CMake Error: Could not find CMAKE_ROOT !!!
You should be able to install ROpenCVLite without any issue. Hope this helps and if so, kindly put a check mark.

R package installation - R CMD check throws ERROR: Installation Failed

I'm having trouble getting a package that I have written to install (on a Windows 10 machine).
I'm running R CMD build packagename (no errors), then R CMD check packagename_0.1.0.tar.gz (or R CMD INSTALL packagename)
After a number of successful log entries, the output reads
* checking whether package 'packagename' can be installed ...Warning: running command '"C:/PROGRA~1/R/R-3.4.0/bin/x64/Rcmd.exe" INSTALL -l
"C:/Work/parsimony_inapp/packagename.Rcheck" --no-html
"C:\Work\PARSIM~1\packagename.Rcheck\00_pkg_src\packagename"' had status 1
ERROR
Installation failed.
00install.out reports the error:
C:/MinGW/bin/gcc -shared -s -static-libgcc -o packagename.dll tmp.def fitch.o reorder.o -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-
4.9.3/local330/lib -LC:/PROGRA~1/R/R-3.4.0/bin/x64 -lR
C:/PROGRA~1/R/R-3.4.0/bin/x64/R.dll: file not recognized: File format not
recognized
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'packagename'
Oddly, I can install the package from GitHub using devtools::github_install('path/to/package').
Advice I've found elsewhere doesn't help:
setwd() in Rprofile - not present
Set R_WIN_NO_JUNCTIONS - no effect
I've updated to the latest version of R (3.4.0), RTools (34) and Cygwin, and checked that my PATH environment variable contains (in order) C:\Rtools\bin; C:\Rtools\mingw_32\bin; C:\Program Files\R\R-3.4.0\bin; C:\Program Files\R\R-3.4.0\bin\x64.
I've tried including and excluding C:\cygwin64\bin and C:\MinGW\msys\1.0\bin from the path, and have tried installations of Rtools with and without the Cygwin dlls, and have tried uninstalling Cygwin completely.

gcc error when installing Statnet package

Installing statnet on mac 10.10.3 with R 3.2.x (RStudio 0.99.441).
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [latentnet.so] Error 1
ERROR: compilation failed for package ‘latentnet’
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/latentnet’
Warning in install.packages :
installation of package ‘latentnet’ had non-zero exit status
ERROR: dependency ‘latentnet’ is not available for package ‘statnet’
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/statnet’
Warning in install.packages :
installation of package ‘statnet’ had non-zero exit status
I tried updating XCode/Command Line Tools. Also tried not installing dependencies. I have been able to install other packages, such as ergm and sna.
It looks like the install is looking for the GCC folder and not finding it.
whereis gcc
reveals that my gcc is in /usr/bin/gcc
It looks like the install is looking for it in /usr/local/lib/gcc/
Is there a way to fix this?
This is a compilation error that you only get if you are trying to install packages from source, or when a package requires a library to be compiled from source. Normally, if you don’t use the latest version of R, you can install statnet from binary and thus R won’t have to compile the source package.
The version you are mentioning at the beginning of your message (0.99.441) is the version of your R-Studio, and not R. The version of your R is 3.2.x (Hence its address in the Library folder: /Library/Frameworks/R.framework/Versions/3.2/Resources…). Before trying to fix the compilation error you may want to try to roll back your R to a version like 3.1.2 or 3.1.3 on which you can probably download and install statnet in binary format.
For the compiler, my guess is that even if you fix the address of your gcc with a symlink, you will still get an error about gfortran or the version of gcc. Once I solved this issue by installing R and the right version of gcc through Homebrew, but right now I don’t have the possibility to try the solution and tell you exactly how.
My experience (on Yosemite) is that if you use 3.1.2 or 3.1.3, even if there is need for compilation, the error with gcc won’t occur.
sudo mkdir /usr/bin/lib && sudo ln -s /usr/bin/gcc /usr/bin/lib/gcc
Creates a new directory in /usr/bin called `lib' and creates a symbolic link to gcc in that new directory.
If that doesn't fix the error, you can undo it with:
sudo rm -i /usr/bin/lib/gcc && sudo rm -id /usr/bin/lib

GLPK: No such file or directory error when trying to install R package

I am trying to install sparkTable in R 3.1.0 which depends on Rglpk. I manually installed GPLK on the system and added the libs folder to LD_LIBRARY_PATH before going into R for the install.packages("sparkTable") procedure. I get this error during the installation process. Any ideas?
* installing *source* package ‘Rglpk’ ...
** package ‘Rglpk’ successfully unpacked and MD5 sums checked
** libs
/bin/sh: line 0: cd: GLPK: No such file or directory
make: *** [GLPK.ts] Error 1
ERROR: compilation failed for package ‘Rglpk’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/Rglpk’
ERROR: dependency ‘Rglpk’ is not available for package ‘sparkTable’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/sparkTable’
sudo apt-get install libglpk-dev
did the trick for me.
I had this problem and took a good bit of digging in the package to understand what was happening. If Rgplk can't compile its test program when installing, it does something weird, including this bizarre cd to nowhere. Assuming glpk-devel is installed, the reason it can't compile the test program is that it can't find the gplk header as it is in a non-standard directory.
Just set the environment variable CPATH=/usr/include/glpk
and the test program will compile, allowing the package install to proceed normally.
I had this problem too. The following steps solved this issue for me. My current setup:
OS: Scientifc Linux version 6.5 (on a High Performance Cluster Server)
local user, no root access.
GLPK was not installed
Install GLPK in a local directory:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=/home/<username>/GLPK
make
make install
Install Rglpk (0.6-3):
cd ~
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-3.tar.gz
export LIBRARY_PATH=/home/<username>/GLPK/lib
R CMD INSTALL Rglpk_0.6-3.tar.gz
I landed on this page, because I could not update igraph under Windows 10/11, since igraph also requires glpk as per OP. Specifically:
igraph_glpk_support.h:36:10: fatal error: glpk.h: No such file or
directory #include <glpk.h>
^~~~~~~~ compilation terminated. make: *** [C:/PROGRA~1/R/R-4.1.1/etc/x64/Makeconf:238: feedback_arc_set.o] Error
1 ERROR: compilation failed for package 'igraph'
removing 'C:/Users/xxx/Documents/R/win-library/4.1/igraph'
restoring previous 'C:/Users/xxx/Documents/R/win-library/4.1/igraph' Warning
in install.packages : installation of package ‘igraph’ had non-zero
exit status
I am under Windows 11 (but would be same for Windows 10).
Simple resolution is suggested here:
start Rtools Bash (found in all apps, Rtools 4.0 in the Windows menu)
Run pacman -S mingw-w64-x86_64-glpk and confirm with yes (y)
Run pacman -S mingw-w64-x86_64-libxml2 and confirm with yes (y)
Updating igraph in Rstudio now leads to a clean
DONE (igraph)
(there is no need to install anything, add any path, etc... just the above 4 steps)
In ubuntu 14.04, all above doesn't work. the following however works, without the need of installing libglpk-dev using apt-get.
download the glpk package from gnu and extract it:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.55.tar.gz
tar xvf glpk-4.55.tar.gz
make a GLPK directory in your local path:
mkdir ~/GLPK
configure within glpk:
cd glpk-4.55
./configure --prefix=$HOME/GLPK
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
download the Rglpk package from cran and extract it:
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-0.tar.gz
tar xvf Rglpk_0.6_0.tar.gz
move the glpk directory into Rglpk/src and rename it to GLPK:
mv glpk-4.55 Rglpk/src/GLPK
now you can install:
R CMD INSTALL Rglpk
now a bit of explanation of what's going on. The "src/Makevars.in" file in the Rglpk package contains a line of code to enter a non-existing directory 'GLPK' within the src/ folder:
(line 11 of Makevars.in)
GLPK.ts:
#(cd GLPK && make)
touch $#
this is where the problem arises. obviously the code is trying to build glpk within that directory for some unknown reasons. and the solution above is achieved simply by moving the downloaded (and configured) glpk directory there...
If you're on a Debian-based Linux distribution, run this to install GLTK:
sudo apt install libglpk-dev
If you're on MacOS, run this to install GLTK:
brew install gltk
Finally, install the R library:
install.packages("Rglpk")
On Centos, have sudo rights. None of the above worked, but had to install GLPK in /usr/local as suggested in this SO answer. Been trying to install it for about 3 hours fml
You must install glpk dependency first.
On macOS (via homebrew):
brew install glpk
or in RStudio (via homebrew):
system("brew install glpk")
It worked for me when I combined the answers from Simón Ramírez Amaya and shadowleaves:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=$HOME/GLPK
make
make install
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
wget https://cran.r-project.org/src/contrib/Rglpk_0.6-4.tar.gz
R CMD INSTALL Rglpk_0.6-4.tar.gz
To load the library
dyn.load(file.path(Sys.getenv("HOME"), "GLPK", "lib", "libglpk.so"))
library(Rglpk)
The answer of Zhiying Cui is right, however, if your script has some special codes, such as foreach for parallel computing, it may raise an error.
A better way is as fellow
If your os is Centos, try
yum install glpk-devel
then just go to R or Rstudio server and
install.packages("Rglpk")

Resources