weikipeng / javacpp

Automatically exported from code.google.com/p/javacpp
GNU General Public License v2.0
0 stars 0 forks source link

passing compiler options does not work #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am not sure if I am using everything correctly, but unfortunately I could not 
find any description on how to pass command line parameters to the compiler.

What steps will reproduce the problem?
1. Try to add "options" annotation value to a class like this:

@Properties({
@Platform(include = { "...", "..." }, link = {"...", "..."}),
@Platform(value = "linux", includepath = linuxIncludepath, linkpath = 
linuxLinkpath, options = "-std=c++0x" ),
...
})

What is the expected output? What do you see instead?

Expected output would be to see g++ called with -std=c++0x parameter added.

NPE is thrown instead:
Exception in thread "main" java.lang.NullPointerException
        at com.googlecode.javacpp.Loader.appendProperty(Loader.java:192)
        at com.googlecode.javacpp.Loader.appendProperties(Loader.java:175)
        at com.googlecode.javacpp.Builder.generateAndCompile(Builder.java:254)
        at com.googlecode.javacpp.Builder.build(Builder.java:585)
        at com.googlecode.javacpp.Builder.main(Builder.java:663)

What version of the product are you using? On what operating system?
 * javacpp v0.2
 * Linux, ia64, Debian 6.0, Oracle VM 1.7.0_05

Thank you!

Original issue reported on code.google.com by buciena...@gmail.com on 17 Sep 2012 at 3:11

GoogleCodeExporter commented 9 years ago
I've made the `options` element special in the sense that it refers to a 
property name. So something like `options="cpp11"` would actually take the 
compiler options from the `compiler.options.cpp11` property, that should be 
added to the property files for ease-of-use, and passed with the 
`-propertyfile` command option of JavaCPP for example. I made it this way 
because compiler options differ between, for example, GCC and MSVC while we 
tend to use the same set of options across classes and projects, so, it thought 
it was a good idea to avoid duplication of code. I should add a better error 
message than just throwing a NPE, I'll do that at least.

But then, if you're only interested in something that works for the purpose of 
a build, I added a `-Xcompiler` option to the Builder, so calling `java -jar 
javacpp.jar -Xcompiler -std=c++0x ...` also works. This may be what you are 
looking for?

Original comment by samuel.a...@gmail.com on 18 Sep 2012 at 2:17

GoogleCodeExporter commented 9 years ago
Thank you for your fast reply!

So as you described I created a properties file, and added the compiler 
parameters there like this:

$ cat javacpp.properties
compiler.options.gcc11=-std=c++0x

Added the -propertyfile "javacpp.properties" to the javacpp invocation, and 
added options="gcc11" to the @Platform annotation.

This way the compilation works fine with the released v0.2.

Anyhow, a more descriptive error message would be great! :)

Thanks again!

Original comment by buciena...@gmail.com on 18 Sep 2012 at 10:13

GoogleCodeExporter commented 9 years ago
I've added better handling in JavaCPP 0.3. Let me know if it's still confusing 
for some reason, thanks!

Original comment by samuel.a...@gmail.com on 5 Nov 2012 at 11:19