Compile CUDA (.cu) file into a shared object (.so) using Ubuntu [duplicate] - r

I'm trying to compile CUDA code using nvcc on Ubuntu. However, when I do, I get this output:
> make
/usr/local/cuda/bin/nvcc -m64 --ptxas-options="-v" -gencode arch=compute_11,code=sm_11 -gencode arch=compute_13,code=sm_13 -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -o main main.cu
gcc: No such file or directory
make: *** [main] Error 1
Even when I'm trying to compile a file with only a main function in it, it still doesn't work:
> /usr/local/cuda/bin/nvcc main.cu
gcc: No such file or directory
nvcc seems to respond to --version, so it's definitely there. I'm not sure why it's invoking gcc though.

nvcc is not a compiler in itself. It's a "compiler driver", orchestrating the entire process of compiling device code, host code and linking it together. On Linux, it uses gcc for compiling the host code.
To install gcc on Ubuntu:
$ sudo apt-get --yes install build-essential

Related

Connecting kdb+ to R

I'm trying to run a make file to install qserver on my OSX machine.
The make file gives me an error when I try to run. see code below:
make
/Library/Frameworks/R.framework/Resources/bin/R CMD gcc -g -O -fpic -m64 -shared -D KXVER=3 -I. -I/Library/Frameworks/R.framework/Resources/share/include base.c c.o -lpthread -L/Library/Frameworks/R.framework/Resources/share/lib -lR -o qserver.so
/Library/Frameworks/R.framework/Resources/bin/R: /Library/Frameworks/R.framework/Resources/bin/R: cannot execute binary file
make: *** [all] Error 126
Hoping someone can give me a pointer here on how to fix it.
Do you have the right version of gcc? I build with gcc-4.8 and have no issues. I recall a thread on the kdb list that mentioned the build required some features available only in later gcc versions. Give that a try.
[EDIT]
Nevermind, just saw that the error says the R binary was not found. Edit the make file to use the appropriate path for your R installation. If you don't have R installed, I suggest installing with homebrew:
brew tap homebrew/science
brew install r
After that you can replace the path in the Makefile as appropriate. I personally changed the Makefile to use $(shell R RHOME) to find the R home path, rather than assume a specific location.
JPC was partially right about gcc.
My system had two different versions of gcc loaded and the default was the standard one. I changed the makefile to run 'gcc-4.8'.
Once I finished that I got a new error: the make file couldn't locate my 'R.h' file...so i just had to reference where my r h-files were located....once I did that the make problem executed.

Installation of rJava

I've tried to solve this using the previous questions/answers on SO but without any success. So, here's my problem.
I'm using RStudio on and Ubuntu box (14.04) and I tried to upgrade rJava from sources and in the process I managed to lose it.
I tried to install it again using,
install.packages("rJava")
which returned the following error message,
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/darren/R/x86_64-pc-linux-gnu-library/3.2/rJava’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
So, I went to the terminal and typed,
sudo R CMD javareconf
which also gave the following error,
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
#include <jni.h>
^
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/default-java
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
I tried to follow these links, one and two but they didn't seem to resolve my issue; there are more links on SO but I'm not sure which one to follow. I've also un-installed and re-installed RStudio via the Ubuntu Software Centre but this didn't make any difference.
Can anyone else help?
In short, I want to be able to use RStudio with rJava again without it destroying any other uses of Java (such as jmol).
You don't seem to have JDK installed. You will need at least
sudo apt-get install openjdk-7-jdk
then re-run
sudo R CMD javareconf
Make sure you do NOT set JAVA_HOME by hand - it will be detected automatically. You should then see something like this:
$ sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.7.0_91
Java home path : /usr/lib/jvm/java-7-openjdk-amd64/jre
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/../include
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/lib/jvm/java-7-openjdk-amd64/jre/../include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/java-7-openjdk-amd64/jre
Java library path: $(JAVA_HOME)/lib/amd64/server
JNI cpp flags : -I$(JAVA_HOME)/../include
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
What is wrong with sudo apt-get install r-cran-rjava ?
See for example this earlier answer and the question / thread around it.
For an installation from scratch, you could still much worse than starting from sudo apt-get build-dep r-cran-rjava. It will get you the JDK corresponding to your Ubuntu version.
First i would recommend installing Rstudio from its website: https://www.rstudio.com/products/rstudio/download/ (i.e. Rstudio 64bit: https://download1.rstudio.org/rstudio-0.99.489-amd64.deb). This does not solve the problem directly, but it helps to avoid other bugs with Rstudio.
Regarding the error, trying to make sure you have JDK install. I don't think the command java -version can tell if JDK is installed. You have to check the package of JDK itself, or based on the error message, do this:
locate jni.h
The output should match or compatible with your JAVAHOME, e.g:
/usr/lib/jvm/java-7-openjdk-amd64/include/jni.h
/usr/lib/jvm/java-7-oracle/include/jni.h
Update 1:
R CMD javareconf is looking for the jni.h file under $(JAVA_HOME)/include
You have JDK installed, but it is very likely that you are having default java to a JRE directory, that why the error happened.
You can see where default-java is really pointing to by doing this command:
jRealDir=$(readlink -f /usr/lib/jvm/default-java)
echo $jRealDir
# sample correct output: /usr/lib/jvm/jdk1.8.0_65
# or /usr/lib/jvm/java-8-oracle if you default to Oracle's
# now check jni.h
ls -l $jRealDir/include/jni.h
# sample expected output:
# /usr/lib/jvm/jdk1.8.0_65/include/jni.h
If the ls command failed, you have to setup so that javareconf ( and later rJava) can use the java from JDK not from JRE. You have two options:
Method 1: Do it system-wide
This is convenient, but may effect other program like the one you mentioned jmol. But don't worry, this is revertible, just re-run the command and pick the old one. Do the following command and pick the dir that has JDK:
sudo update-alternatives --config java
After that test how jmol works, if it works alright then congrat. You are now ready to test rJava. If not, try the second method below
Method 2: Do it for R only
put this in the .Rprofile under your home directory
Sys.setenv(JAVA_HOME = '/usr/lib/jvm/jdk1.8.0_65')
# this set JAVA_HOME for R to correct java home dir.
After updating or creating the .Rprofile DO restart R in Rstudio. The R CMD javareconf may still fail in this case, but it should be OK if you run it from Shell under Tools menu of Rstudio.
Regarding the installing or Rstudio from Ubuntu's stock repo. It would not make a difference for getting rJava running. Then again, I recommend installing Rstudio for its homepage because new version also has some nice features (i.e. better autocompletion, which I like the most).
Here is link on R-Bloggers that worked for me: https://www.r-bloggers.com/installing-rjava-on-ubuntu/
sudo apt-get install -y default-jre
sudo apt-get install -y default-jdk
sudo R CMD javareconf
install.packages("rJava")
I've been dealing with this exact issue, nothing in this thread or other that are similar have solved it. I'm on Ubuntu 16.04, here's how I got it to work:
apt-get install openjdk-9-jdk
rm -rf /usr/lib/jvm/default-java
ln -s /usr/lib/jvm/java-9-openjdk-amd64/ /usr/lib/jvm/default-java
You can see where the JAVA_HOME is in the error message.
Then use locate jni.h to find where is jni.h, next use soft link to link this location to $(JAVA_HOME)/include, just like #biocyberman mentioned.
This is what I did:
ln -s /usr/lib/jvm/java-8-openjdk-amd64/include/jni.h /opt/conda/include/jni.h
ln -s /usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h /opt/conda/include/jni_md.h
ln -s /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/
Since my JAVA_HOME is /opt/conda and I also don't have jni_md.h and -ljvm.
I am use Ubuntu 16.04.

How to build a Xen unikernel of Mirage OS

I read this document(http://openmirage.org/wiki/hello-world) and tried to build a xen unikernel as follows:
mirage configure --xen
make depend
make
But failed at compilation:
ocamlbuild -classic-display -use-ocamlfind -pkgs lwt.syntax,mirage-console.xen,mirage-types.lwt -tags "syntax(camlp4o),annot,bin_annot,strict_sequence,principal" -tag-line "<static*.*>: -syntax(camlp4o)" -cflag -g -lflags -g,-linkpkg,-dontlink,unix main.native.o
ocamlfind ocamldep -package mirage-types.lwt -package mirage-console.xen -package lwt.syntax -syntax camlp4o -modules main.ml > main.ml.depends
ocamlfind ocamlc -c -g -annot -bin-annot -principal -strict-sequence -package mirage-types.lwt -package mirage-console.xen -package lwt.syntax -syntax camlp4o -o main.cmo main.ml
ocamlfind ocamlopt -c -g -annot -bin-annot -principal -strict-sequence -package mirage-types.lwt -package mirage-console.xen -package lwt.syntax -syntax camlp4o -o main.cmx main.ml
pkg-config --print-errors --exists mirage-xen
Package mirage-xen was not found in the pkg-config search path.
Perhaps you should add the directory containing `mirage-xen.pc'
to the PKG_CONFIG_PATH environment variable
No package 'mirage-xen' found
make: *** [build] Error 1
I installed mirage-xen by opam install mirage-xen successfully.
But in my .opam directory, there are no mirage-xen.pc.
They should appear in your OPAM prefix. I get:
$ ls $(opam config var prefix)/lib/pkgconfig
gmp.pc mirage-xen-ocaml-bindings.pc mirage-xen-posix.pc
libminios-xen.pc mirage-xen-ocaml.pc openlibm.pc
mirage-xen-minios.pc mirage-xen.pc
(you may have fewer; mirage-xen.pc is the important one)
Assuming they're there, check the project's Makefile is setting PKG_CONFIG_PATH correctly.
Chances are that your version of mirage-xen is out of date. You can update it via OPAM by:
opam update -u
opam info mirage-xen
Make sure that you have mirage-xen version 2.1.1 or greater (the latest as of this comment is 2.1.3).
If you don't pick up the upgrade, then you may have a local Git checkout of the central package database. Confirm this by looking at the output of:
opam remote
The output of this should tell you where your local git checkout is, and so navigate there and refresh from git://github.com/ocaml/opam-repository and then run opam update -u.

Install therubyracer on OSX

I have a fresh install of ruby 2.1.1, a clean set of gem and I reinstalled V8 with homebrew but I get this 'unrecognized command line option' error.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/jspooner/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling accessor.cc
g++: error: unrecognized command line option '-rdynamic'
make: *** [accessor.o] Error 1
make failed, exit code 2
g++ version
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.8.3/libexec/gcc/x86_64-apple-darwin13.2.0/4.8.3/lto-wrapper
Target: x86_64-apple-darwin13.2.0
Configured with: ../configure --build=x86_64-apple-darwin13.2.0 --prefix=/usr/local/Cellar/gcc/4.8.3 --enable-languages=c,c++,objc,obj-c++,fortran --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.8.3 (GCC)
if Ubuntu users having this situation (e.g.: on a Ubuntu VM)
gem install therubyracer -v '0.11.4'
\Building native extensions. This could take a while...
ERROR: Error installing therubyracer:
ERROR: Failed to build gem native extension.
/home/deploy/.rbenv/versions/2.0.0-p247/bin/ruby extconf.rb
checking for main() in -lpthread... yes
creating Makefile
make "DESTDIR="
compiling accessor.cc
make: g++: Command not found
make: *** [accessor.o] Error 127
Gem files will remain installed in /home/deploy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/therubyracer-0.11.4 for inspection.
Results logged to /home/deploy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/therubyracer-0.11.4/ext/v8/gem_make.out
Ubuntu solution:
sudo apt-get install build-essential g++
I had to run brew update gcc.
brew upgrade gcc
==> Upgrading 1 outdated package, with result:
gcc 4.9.1
==> Upgrading gcc
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/gcc-4.9.1.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring gcc-4.9.1.mavericks.bottle.2.tar.gz
==> Caveats
GCC has been built with multilib support. Notably, OpenMP may not work:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670
If you need OpenMP support you may want to
brew reinstall gcc --without-multilib
==> Summary
🍺 /usr/local/Cellar/gcc/4.9.1: 1152 files, 203M
Changing the symbolic link of g++ and gcc worked for me on Mac OS 10.10.
ls -al /opt/local/bin/gcc
ls -al /opt/local/bin/g++
sudo rm /opt/local/bin/gcc
sudo rm /opt/local/bin/g++
sudo ln -s /usr/bin/llvm-gcc /opt/local/bin/gcc
sudo ln -s /usr/bin/llvm-g++ /opt/local/bin/g++
gem install therubyracer -v '0.12.1'
sudo rm /opt/local/bin/g++
sudo rm /opt/local/bin/gcc
sudo ln -s /opt/local/bin/g++-mp-4.9 /opt/local/bin/g++
sudo ln -s /opt/local/bin/gcc-mp-4.9 /opt/local/bin/gcc

/usr/bin/ld: cannot find -lfreetype qt

Compiling on Fedora 10.
I am using qt for the first time. I started by creating a simple GUI application with all the default settings. When I tried to build the project I got the following error messages.
However, when I did a search for -lfreetype I found it in the following directory.
/usr/lib/libfreetype.so.6
/usr/lib/libfreetype.so.6.3.18
Is there anyway to resolve this issue?
Many thanks for any advice
Running build steps for project test1...
Creating gdb macros library...
Configuration unchanged, skipping QMake step.
Starting: /usr/bin/make debug -w
make: Entering directory `/home/steve/projects/qt/test1/test1'
/usr/bin/make -f Makefile.Debug
make[1]: Entering directory `/home/steve/projects/qt/test1/test1'
g++ -Wl,-rpath,/opt/qtsdk-2009.01/qt/lib -o test1 debug/main.o
debug/mainwindow.o debug/moc_mainwindow.o
-L/opt/qtsdk-2009.01/qt/lib
-lQtGui -L/opt/qtsdk-2009.01/qt/lib -L/usr/X11R6/lib
-pthread -lfreetype
-lgobject-2.0 -lSM -lICE -pthread -pthread
-lXrender -lfontconfig
-lXext -lX11 -lQtCore -lm -pthread -lgthread-2.0 -lrt
-lglib-2.0 -ldl -lpthread
/usr/bin/ld: cannot find -lfreetype
collect2: ld returned 1 exit status
make[1]: *** [test1] Error 1
make[1]: Leaving directory `/home/steve/projects/qt/test1/test1'
make: *** [debug] Error 2
make: Leaving directory `/home/steve/projects/qt/test1/test1'
Exited with code 2.
Error while building project test1
When executing build step 'Make'
You have to install the freetype-devel package. The devel package contains the header files which in the case of freetype shoud be located at: /usr/include/freetype.
I had the same problem on Ubuntu 8.10, QT 4.5. I "fixed" it with the following bizarre hack:
After the build fails, rename the QT lib directory to something else - e.g. "mv ../../qtsdk-2009.01/qt/lib ../../qtsdk-2009.01/qt/lib2"
Run "make" again, and it will fail again.
Restore the lib directory
Run "make" again, and now it works.
I have no idea why this happens.
Install freetype1-dev libgtk2.0-dev
and it will compile ok.
On Ubuntu 9.04, installing freetype1-dev & libgtk2.0-dev solves this problem.
But to surprise everyone the hack mentioned by Ross also works, I would really like to know how and why.. M looking into the source code of QTcreator to see if i can find out the reason why. If any one already know the reason, please let me know.
Thanks..
Just installed a newly fresh ubuntu 9.04 (dell D820)- installed qt creator nothing else - same problem
use option from S R that works because it needs libgtk2.0-dev (this will also load freetype6 ) installed from package manager.
Same effect you will see if you also install qt designer from package manager (it will install all the right packages
regards
Nico
I had same problems with Elive, freetype1-dev and libgtk2.0-dev and for the /usr/bin/ld: cannot find -lSM thing xorg-dev fixed the problem.
The first thing you have to make sure is that you have libfreetype.so installed in your computer. Use the command 'locate libfreetype.so', and you may find there is a '/usr/lib/libfreetype.so.6' in the result. The compile software can't identify libfreetype.so.6 as a shared library, so, you have to make a symbolic link to the target. Use the command 'ln -s /usr/lib/libfreetype.so.6 /usr/lib/libfreetype.so', when you compile the program again, you will find the error had gone. You can also solve the errors likely. Good Luck!

Resources