Can we use jdk7 javac to compile code with java7 features into java6 bytecode - compatibility

I was considering if a java project could produce 2 jars: one for java7 and one for java6, yes, the source code might use some some java7 new features.
so to generate the java6 jar, the command line would be like:
javac -target 1.6 -bootclasspath jdk1.6.0\lib\rt.jar -extdirs "" MyApp.java
Unfortunately,
It simply emits an error:
javac: target release 1.6 conflicts with default source release 1.7
According to this document, it should be possible for jdk6 vs jdk5, anybody knows why it doesn't work in jdk7 vs jdk6? did I do something wrong, or is it just officially not supported?
Thanks.

AFAIK, the source and target have to be the same. Even for Java 6. The only exception is the source can be 1.1 and the target 1.0.
Given there is little difference in the JVM between the latest JVM for Java 6 and Java 7, I suggest you consider upgrading. Also Java 6 will be, End Of (free) Service in Nov 2012, which three months from now...

Even if it were possible it's generally a bad idea - if you want to be sure your code will work on java 6 then you have to build it on java 6. Each new version of java introduces new classes in the class library, and adds new methods to existing classes, and even if you set your java 7 compiler to generate 6-compatible bytecode it won't catch cases where you call a 7-only method.

Related

command line compiling generates bigger file than the online version

I am testing google closure compiler on command line.
I took the latest version :
java -jar closure-compiler.jar --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20190618
Built on: 2019-06-21 17:24
I am generating a compressed version of my javascript like this :
java -jar closure-compiler.jar my_script.js > out.js
The problem is that the generated code is bigger than the one I get when I use the online service at https://closure-compiler.appspot.com/home
I noticed that the command line version added, at the beginning, the following code :
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,c,b){a instanceof String&&(a=String(a));for(var d=a.length,e=0;e<d;e++){var f=a[e];if(c.call(b,f,e,a))return{i:e,v:f}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,c,b){a!=Array.prototype&&a!=Object.prototype&&(a[c]=b.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];e in b||(b[e]={});b=b[e]}a=a[a.length-1];d=b[a];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}};$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,b){return $jscomp.findInternal(this,a,b).v}},"es6","es3");
I do not have such a code in my script: Where does it come from ?
how can I produce the same output as the online version ?
To get the compiler command line work as the web service, I just added an option :
--language_out=ECMASCRIPT_2015
This is likely a discrepancy between the settings on the web service and the ones you're using locally.
Have a look at a Closure Compiler: Flags and Options to see what settings you might prefer.
If you'd share your source, it'd be possible to try and help you narrow down the options.
As for the extra code, I believe it is at least partially a polyfill for Array.prototype.find (aka [].find), which I assume is in your code?
If so, that's Closure injecting code to improve your cross browser compatibility.

Build Qt 5.2 for windows ce 6

I tried to build qt 5.2.1 (opensource.zip) on a Windows 7 64 bit machine with Visual Studio 2005 Professional while having ActivePerl etc. installed. I used the Visual Studio 2005 Command prompt with the following line for configure:
configure -platform win32-msvc2005 -xplatform wince60standard-armv4i-msvc2005 -opensource -nomake examples
which ends up in the following output after about 2 min.:
…
qglobal.cpp
qmalloc.cpp
qlibraryinfo.cpp
qnumeric.cpp
qlogging.cpp
D:\qt-source5.2.1\qtbase\src\corelib\global\qlogging.cpp(96) : error C3861: “GetConsoleWindow”: identifier not found.
Code will be generated…
NMAKE : fatal error U1077: ““C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\cl.EXE”“: return code “0×2”
Stop.
Building qmake failed, return code 2
I also tried to do just a simple:,
configure
within Visual Studio 2005 Command Prompt -> Ends up in the same error.
Does anybody know what wents wrong here? Am i doing something totally wrong or missing something?
I also posted this to the qt Forums of a thread created by a user who had a similar problem -> http://qt-project.org/forums/viewthread/36177/
But nobody replied there.
EDIT: Today i updated my question in QT forums. See -> http://qt-project.org/forums/viewthread/36177/ I modified the problem file qtbase\src\corelib\global\qlogging.h and added the following on top of it:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0×0500
#endif
I found this solution while searching for “getConsoleWindow” problems. The reference is written down as remark here -> http://msdn.microsoft.com/en-us/library/windows/desktop/ms683175(v=vs.85).aspx
After this my configure runs fine without any problems. But now I expected the following error after calling nmake. After nmake runs ~30 mins i got this output:
d:\readonly\qtsrc\qtbase\include\qtcore\../../src/corelib/tools/qvector.h(666) : error
C2244: 'QVector<T>::erase' : unable to match function definition to an existing declaration definition 'QVector<T>::iterator QVector<T>::erase(QTypedArrayData<T>::iterator,QTypedArrayData<T>::iterator)'
existing declarations
'QTypedArrayData<T>::iterator QVector<T>::erase(QTypedArrayData<T>::iterator)'
'QTypedArrayData<T>::iterator QVector<T>::erase(QTypedArrayData<T>::iterator,QTypedArrayData<T>::iterator)'
There are some more errors but all with QVector::insert and QVector::erase. I Googled a bit and found this post here which looks like a similar problem and is also not replied yet: http://qt-project.org/forums/viewthread/36735
I think i have to say that i compile for custom ce sdk. So i changed the qtbase\mkspecs\wince60standard-armv4i-msvc2005\qmake.conf and added additional includes and libraries there. I also use the following defines there:
DEFINES += WINCE WINDOWS WINDOWS_CE_OS _WIN32_WCE=0×600 UNDER_CE=0×600 ARM _ARM ARMV4I UNICODE UNICODE _USE_32BIT_TIME_T _CRT_SECURE_NO_DEPRECATE $$CE_ARCH _AMRV7 armv7 ARM QT_NO_CLIPBOARD QT_NO_ACCESSIBILITY QT_NO_NATIVE_GESTURES QT_NOSTANDARDSHELL_UI_MODEL
Is it so hard to compile qt 5.2.1 for ce? Should i use an older version of qt (i need at least qt5 for JSON handling)? Any suggestions regarding this issue here?
Use thirdpaty library for JSON. Visual Studio 2005 is too old compiler. For example - jsoncpp or QJson.

javacc testing Simple1.jj

If you see my other question, you will now better my goals. Take a look at: https://stackoverflow.com/questions/19510039/from-regex-to-parser-generators .
As I'm trying to be a good boy, I'm reading the README (see https://java.net/projects/javacc/sources/svn/show/tags/release_60/examples/SimpleExamples?rev=555 ).
Run javacc on the grammar input file to generate a bunch of Java files that implement the parser and lexical analyzer (or token
manager):
javacc Simple1.jj
Now compile the resulting Java programs:
javac *.java
The parser is now ready to use. To run the parser, type:
java Simple1
My try:
D:\tests\javacc\simple1>javacc ..\Simple1.jj
Java Compiler Compiler Version 6.0_beta (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file ..\Simple1.jj . . .
File "TokenMgrError.java" does not exist. Will create one.
File "ParseException.java" does not exist. Will create one.
File "Token.java" does not exist. Will create one.
File "SimpleCharStream.java" does not exist. Will create one.
Parser generated successfully.
D:\tests\javacc\simple1>javac *.java
SimpleCharStream.java:474: error: non-static variable this cannot be referenced from a static context
static void setTrackLineColumn(boolean trackLineColumn) { this.trackLineColumn = trackLineColumn; }
^
1 error
My java version:
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Client VM (build 24.45-b08, mixed mode, sharing)
I'm sure that "these" guys known what they are doing, I'm sure I did something wrong, but what? Getting a simple error like that in the first test with javacc?
How can I fix that and continue my lecture?
I suggest using version 5.0 for now. There are a lot of changes in version 6 and these came along with some bugs. There should be an update to version 6 soon. https://java.net/projects/javacc/downloads
Will you put the code to look it or your complete call. I think, that it´s a code error or that you call a bad .java archive. For example:
I have: Mytokens.jj and javaCode.java ok? Good, you need said:
javacc Mytokens.jj
javac javaCode.java
java javaCode <test1.txt>
I give you my *.bat for the test. You create a new txt and write it:
CALL javacc nameJJ.jj
#pause
CALL javac NameJava.java
#pause
java NameJava <prueba1> salida.txt
type salida.txt
#pause
This do the test for you when you do a double-click on it if you have a copy in your javacc/bin and your practice directories.

Programming Arduino with Ada

I am am unable to get avr-elf-windows and WinAVR to work. I have managed to build the example supplied with avr-elf-windows (ATmega2560). But if I try and expand to use another chip or start using the WinAVR supplied packages and projects I keep getting errors I cannot work out.
Method 1:
Modify the ATmega2560 example to use the WinAVR packages.
Changed:
with Atmega2560; use Atmega2560;
to:
with AVR; use AVR;
with AVR.Atmega328p; use AVR.atmega328p;
Create a project file to include:
with "C:\WinAVR-20100110\lib\gnat\avr.gpr";
with "C:\WinAVR-20100110\lib\gnat\avr_app.gpr";
Running make I get the following error:
avr-gnatmake: "C:\WinAVR-20100110\lib\gnat\avr_lib\avr-int_img.adb" compilation error
Great, I have a compilation issue, but I cannot see the error.
Method 2:
Open the above project file in GPS. Change the build setting to be gnatmake. GPS now starts reporting errors and warnings:
Project warning: object directory "avr_lib/avr5/obj" not found
Project library directory "C:\WinAVR-20100110\lib\gnat\avr_lib\avr5\lib\" does not exist
The latter issue is very clearly the fact that I have not set up GPS correctly to tell it the values of microcontroller and architecture, but I cannot seem to find anything to resolve this.
Method 3:
To use the WinAVR set up directly using makefiles which then gives me the error:
avr-gnatmake: RTS path not valid: missing adainclude and adalib directories
If I follow the instructions I can find by searching the web I can only find details for building the required libraries under Linux.
Platform: Windows 7.
With the combination of the two answers above I have now managed to link my sample code. As to wether it will work on the Arduino, that is a different issue.
Many thanks for the help.
I have found it a bit frustrating to get this far, and I wonder if there are others out there who may just give up on Ada on the Arduino and go back to the Arduino IDE and therefore missing out on the opportunity to learn a language with more structure. There are many misleading pages out there that also do not help.
You might want to take a look in the paper Integrating 8-bit AVR Micro-Controllers in Ada. Basically you can use a GPS project file arduino.gpr like
project Arduino is
for Source_Dirs use (".", "src");
for Object_Dir use "obj";
for Exec_Dir use "bin";
for Main use ("main.adb");
package Compiler is
for Default_Switches ("ada") use ("-mmcu=avr5");
end Compiler;
package Ide is
for Gnat use "avr-gnat";
for Gnatlist use "avr-gnatls";
for Debugger_Command use "avr-gdb";
end Ide;
package Builder is
for Executable_Suffix use ".elf";
for Default_Switches ("ada") use ("--RTS=rts-zfp");
end Builder;
package Linker is
for Default_Switches ("ada") use ("obj\crtm328p._o", "-nostdlib", "-lgcc", "-mavr5", "-Tdata=0x00800200", "-mmcu=avr5");
end Linker;
end Arduino;
and you can code a spec for your ATmega328P like
with Interfaces; use Interfaces;
with System;
package ATmega328P is
-- PORTB: Port B Data Register
PORTB : Unsigned_8;
for PORTB'Address use System'To_Address (16#25#);
-- DDRB: Port B Data Direction Register
DDRB : Unsigned_8;
for DDRB'Address use System'To_Address (16#24#);
-- PINB: Port B Input Pins
PINB : Unsigned_8;
for PINB'Address use System'To_Address (16#23#);
end ATmega328P;
to be imported by your main file or libraries.
Bear with me if this isn't the immediate answer; I have only used the AVR-Ada toolchain on Linux, so we may have to iterate towards a solution unless someone else spots the problem first.
The first thing to decipher is which version of the AVR-Ada tools you have:
your project file USED to need (using avr-ada 1.1)
with "C:\WinAVR-20100110\lib\gnat\avr.gpr";
Now with avr-ada 1.2.1 you need (instead)
with "C:\WinAVR-20100110\lib\gnat\avr_app.gpr";
for building applications, and <same path>/avr_lib.gpr for libraries.
I don't believe you ever need both! And they may conflict with each other.
I don't know the state of the Windows binary build, but if you need the latest version (recommended : it's a real improvement) you may need to build it from source.
Method 1 : were you running Make from a command line? If so, I would expect to see errors in all their gory details.
Method 2 : can't help you here, I don't know GPS well enough. However I can say that on Linux there are no "avr5" folders in [wherever]/avr/lib/gnat/avr_lib. (AVR5 is correct for the 328p)
Instead there IS a [wherever]/avr/lib/avr5 containing libc and other C-related objects - including the crtm328p.o that Rego names in his linker switches, and a [wherever]/lib/gcc/avr/4.7.2/avr5 folder containing libgcc.a. You probably need to find the former and point GPS at it...
Method 3 : This looks the easiest to fix. The "gnatmake" command needs an --RTS= option pointing at the correct RTS for the 328p. This should be --RTS=rts/avr5 assuming the RTS is correctly installed.
Alternatively a full path ought to work. Here, that would be
--RTS=/opt/avr_472_gnat/lib/gcc/avr/4.7.2/rts/avr5
on Windows you may have to poke around to find the correct path.
Using Method 1 this --RTS option is automatically generated by avr_app.gpr.
It appears that having a mix of 3 or 4 tool chains installed that provide one of aspects of WinAvr, AvrAda causes significant problems (these included WinAvr, Avr-Ada, Cygwin, AVR compiler by Adacore and MinWG).
Starting with a brand new Win7 or Win8 installation perform the following:
Install WinAVR-20100110 to C:\WinAVR-20100110
Copy the content of the Avr-Ada-1.2.0_bin to C:\avr-ada-1.2.0
Add C:\avr-ada-1.2.0\bin to the PATH
Compiling the content of each of the examples in C:\avr-ada-1.2.0\share\doc\avr-ada\apps identifies that some DLLs are missing: libiconv-2.dll, libgmp-10.dll, libmpc-2.dll, libmpfr-1.dll
These can be found in a MinGW installtion.
Create a virtual machine to install MinGW on, in order to ensure it did not mess with the main PC.
Copy the missing DLLs in C:\WinAVR-20100110\bin
The example in DS1820 will not compile due to crc_lib being missing.
In order to upload to the Arduino the makefiles must be modified for your local installation, board type etc.

How to set "C++ Standard Library Type" to "static" in Xcode 4?

I have an Xcode 3.2 project (sqlite3 with icu) that builds correctly, and I'm trying to recreate it in Xcode 4. I'm getting link errors:
Undefined symbols for architecture x86_64:
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for icu_48::SortKeyByteSinkin libicui18n.a(ucol.ao)
...
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in libicui18n.a(uregex.ao)
...
I had this once before, with Xcode 3.2. I it then by changing build setting Linking-> C++ Standard Library Type to static (the default is dynamic). If I understand the docs correctly, the actual flag is STANDARD_C_PLUS_PLUS_LIBRARY_TYPE.
But I can't find that setting in Xcode 4!
EDIT
The main module (sqlite3) is C, but the ICU library is C++, presumably with C declarations. I can build sqlite3 fine by itself, it's when I need to link in the ICU library that the trouble starts.
Your app may be C but it looks like libicui18n includes C++.
What happens if you rename your main.m to main.mm? That should cause it to be linked against the standard C++ library.

Resources