The Using the GNU Compiler Collection manual for gcc version 6.3.0 indicates support for the language option -x java on page 28 (page 42 of the pdf). Attempting this on debian stretch:
$ gcc -x java HelloWorld.java
gcc: error trying to exec 'ecj1': execvp: No such file or directory
Installing what seems to be the required package:
$ sudo apt-get install ecj1
Reading package lists... Done
...
Unpacking ecj1 (3.11.1-1) ...
Setting up ecj1 (3.11.1-1) ...
....
Reading state information... Done
However, I get the same error message when running gcc after this. In fact looking into /usr/bin, no executable ecj1 has been installed, and running apt-cache search ecj1 does not suggest any other package than the one I have installed.
$ gcc --version
gcc (Debian 6.3.0-11) 6.3.0 20170321
$ uname -a
Linux right 4.8.0-1-amd64 #1 SMP Debian 4.8.5-1 (2016-10-28) x86_64 GNU/Linux
Any suggestion as to what else I could try to get this running?
The GNU compiler for Java has to be installed:
$ apt-get install gcj-4.9 gcj-4-9-jdk
Use apt-file to search for packages containing ecj1 as a file. Note that apt-cache only searches for package names/descriptions matching the search.
After the installation I was able to run it using
$ gcj-4-9 HelloWorld.java
instead of gcc.
Even though gcj is a front-end to gcc, gcc didn't work for me and was complaining about the classpath not being set. To get gcc working, it would probably require a different, more complex command.
If you're compiling a class that contains a main method, use the --main option.
$ gcj-4-9 --main=HelloWorld HelloWorld.java
Related
I have a docker image where the building process roughly looks like this:
FROM centos:latest
...
RUN yum install -y java-1.8.0-openjdk-devel
...
I highly depend on the specific java version, so changing that is not an option.
Right now I need to add openjfx to this and make it work, yet all the available documentation seems to be not working on my centos/openjdk combination.
Downloading the zip file and adding it to my container and running the following commands as described here:
RUN export PATH_TO_FX=/var/lib/javafx/lib \
&& javac --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX.java \
&& java --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX
Failes, as:
javac: invalid flag: --module-path
What would be the correct way to add it to this docker image?
I am trying to install the rJava package on OS X 10.11.6 with R version 3.4.0:
install.packages("rJava", type = "source")
and I get the following error:
clang -o libjri.jnilib Rengine.o jri.o Rcallbacks.o Rinit.o globals.o rjava.o -dynamiclib -framework JavaVM -fopenmp -L/usr/local/lib -F/Library/Frameworks/R.framework/.. -framework R -lpcre -llzma -lbz2 -lz -licucore -lm -liconv
clang: error: unsupported option '-fopenmp'
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’
From what I can tell, clang is being used as the compiler, using 'fopenmp' which doesn't appear to be supported by clang. Can anyone see a way around this, potentially forcing a different compiler to be used? (note: I know almost nothing about compilers)
Thanks in advance.
This is caused because R 3.4.0 is compiled by CRAN with llvm-4.0.0 (which supports OpenMP), but Apple's fork (installed by default on macOS) does not support OpenMP. There are three solutions
Use the package binaries provided by CRAN, e.g. install.packages(type = "binary").
Install a compiler that does support OpenMP, such as gcc or clang from hombrew, however you will also have to modify variables in your personal makevars file (~/.R/Makevars).
Unset SHLIB_OPENMP_CFLAGS and SHLIB_OPENMP_CXXFLAGS in your ~/.R/Makevars
For 2. you can install the compilers with brew install llvm or brew install gcc --without-multilib then you will have to add the compiler path to your ~/.R/Makevars file.
CC=/usr/local/opt/llvm/bin/clang
CXX=/usr/local/opt/llvm/bin/clang++
# Also potentially CXX11 (for C++11 compiler)
CXX11=/usr/local/opt/llvm/bin/clang++
or for gcc use (double check gcc executable exists and is correctly named)
CC=/usr/local/bin/gcc-7
CXX=/usr/local/bin/gcc-7
# Also potentially CXX11 (for C++11 compiler)
CXX11=/usr/local/bin/gcc-7
Alternatively you can install a CRAN Provided LLVM 4.0 and set the Makevars file appropriately.
For 3. you simply need to unset the SHLIB_OPENMP_CFLAGS
SHLIB_OPENMP_CFLAGS=
SHLIB_OPENMP_CXXFLAGS=
For more details see OpenMP support in Writing R Extensions.
Note this error has nothing to do with Java or the rJava package in particular, so ideally the question could be renamed to clang: error: unsupported option '-fopenmp'.
Running following in terminal fixes the package download in RStudio too and you can run the Rjava or r-app without any issues.
brew cask install r-app
brew install homebrew/versions/gcc49 --without-multilib
sudo chown -R $(whoami):admin /usr/local
brew link --overwrite --force gcc49
brew unlink gcc49 && brew link gcc49
brew install llvm
mkdir ~/.R; touch ~/.R/Makevars
I'm trying to compile a jar on my mac using 1.8 as a target release, but javac fails with the message "invalid target release".
When I run javac -version it gives me "javac 1.6.0_29".
I have the 1.8 jdk installed under "/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk", but even when I run /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/javac -version it gives me "javac 1.6.0_29".
Sym linking the CurrentJDK folder in "/System/Library/Frameworks/JavaVM.framework/Versions/" to the jdk folder in Library didn't change anything. Neither did sym linking the javac inside /usr/bin to the javac in my jdk folder.
Any ideas how to get javac to use my 1.8 version ?
Thank you very much!
UPDATE
My path variables output the following:
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin:/opt/X11/bin:/usr/local/git/bin:/Developer/Tools/Panda3D
echo $JAVA_HOME (since I set it already in order to get javac to work)
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/
Preprending /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/ to the $PATH variable didn't change the output for javac -version either.
UPDATE 2
Other question: What does javac do? Is it executing its code directly or depending on other binaries in the system? If so the link for them could be broken. Otherwise I wonder why executing the binary inside my 1.8 jdk folder gives me the version 1.6.
The proper Debian/Ubuntu way to configure which javac is pointed to by /usr/bin/javac is to use the update-alternatives command. You can do it interactively, and select from a list of available options:
sudo update-alternatives --config javac
and for java:
sudo update-alternatives --config java
In addition to what #Zakaria said, this command will show you all Java packages installed on the system, e.g.:
$ update-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64
This one an overview of the Java tools and which version will be used, e.g.:
$ update-alternatives --get-selections | grep java
...
java manual /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
javac auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
javadoc auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc
...
As shown above here java would run from version 8, and javac from version 7.
If you want to update selections for all of the Java tools in one go try the following replacing the package name with one of your choice:
$ sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
Verify that this has actually worked. If it didn't or partially did you have to resort to a semi-manual way, for example:
$ for i in $(update-alternatives --get-selections | grep java | awk '{system("basename "$3)}'); do sudo update-alternatives --config $i; done
where does the /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK link refer to?
Make sure it refers to the proper JDK
/Library/Java/JavaVirtualMachines/jdk{major}.{minor}.{macro[_update]}.jdk
Please check that both JAVA_HOME and PATH environment variables point to the 1.8 folder and have no link to the 1.6 java folder, especially the PATH.
Check:
echo %PATH%
Set:
export PATH="java8 folder":$PATH
or check this page: Set environment variables on Mac OS X Lion
Do the following steps
In the Windows Search bar, type "environment".
In your environment variables (account), create a variable called JAVA_HOME. Set it to C:\Program Files\Java\jdk1.8.0_65 (or wherever your JDK is).
In your system environment variables, edit PATH. Put this at the beginning of the PATH value: %JAVA_HOME%\bin;
Press OK.
Exit any command windows you are in.
Launch a command window. Type javac -version.
you should get this response: javac 1.8.0_65
I am following "working with Hadoop under Eclipse" and trying to run
$ mvn install -DskipTests
After a while, I received an error:
[ERROR] Failed to execute goal org.apache.hadoop:hadoop-maven-plugins:3.0.0-SNAPSHOT:protoc (compile-protoc) on project hadoop-common: org.apache.maven.plugin.MojoExecutionException: protoc version is 'libprotoc 2.4.1', expected version is '2.5.0' -> [Help 1]
It is the same as what is reported in this page.
Does anyone know how to solve it? How should I do to upgrade libprotoc?
Protocol Buffers is used as an RPC protocol between different daemons. Some of the Linux releases don't have the required version. So, Protocol Buffers code has to be downloaded from here, built and installed. These are the instructions from the README.txt in the downloaded bundle.
To build and install the C++ Protocol Buffer runtime and the Protocol Buffer compiler (protoc) execute the following:
$ ./configure
$ make
$ make check
$ make install
If "make check" fails, you can still install, but it is likely that some features of this library will not work correctly on your system. Proceed at your own risk. "make install" may require superuser privileges.
Execute this bash function, which will download protobuffer 2.5.0 and install with sudo permission. (Tested in ubuntu 13.04)
configureProtoc(){
sudo apt-get install -y gcc g++ make maven cmake zlib zlib1g-dev libcurl4-openssl-dev
curl -# -O https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz
gunzip protobuf-2.5.0.tar.gz
tar -xvf protobuf-2.5.0.tar
cd protobuf-2.5.0
./configure --prefix=/usr
make
sudo make install
}
Dont forget to link shared libraries after installing protoc :
ldconfig
I tried to mvn install and got this message:
Compilation failure
Unable to locate the Javac Compiler in:
/usr/lib/jvm/java-7-openjdk-amd64/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
Well, there is an open jdk, I also downloaded another one. I tried to point JAVA_HOME to both, now it is set:
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_03
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
I also tried to choose one of those open with sudo update-alternatives --config java but got the same error with different jdk versions in it.
How can I fix that? Thanks in advance.
it seems like your PATH is not picked up correctly... does the output of "echo $PATH" contain the directory where javac resides?
I would suggest following:
open terminal and do an:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_03
export PATH=$PATH:$JAVA_HOME/bin
javac -version
which javac
if javac -version still does not work create a symlink in /usr/local/bin pointing to your javac binary:
cd /usr/local/bin
ln -s /usr/lib/jvm/jdk1.7.0_03/bin/javac javac
this should get you up an running...
an alternative is to try setting up java via your package management system (e.g. "apt-get install java" or sth. similar)
I faced similar error on an ubuntu machine while running a maven build from Jenkins. If output of 'javac -version' prompts below messages:
"The program 'javac' can be found in the following packages:
default-jdk
ecj
gcj-5-jdk
openjdk-8-jdk-headless
gcj-4.8-jdk
gcj-4.9-jdk
openjdk-9-jdk-headless
Try: apt install "
Then you can install "openjdk-8-jdk-headless" using:
apt install openjdk-8-jdk-headless
This solved my problem and the maven build went through ok.