I’m trying to create a JNI project on Windows. My JDK is in the usual place “C”\Program Files\Java". The following seems to work if I use a path to the JDK without spaces in it.
apply plugin: 'cpp-lib'
libraries {
main {
binaries.all {
if (toolChain == toolChains.visualCpp) {
compilerArgs '/I"C:\jdk1.7.0_21\include"'
compilerArgs '/I"C:\jdk1.7.0_21\include\win32"'
}
}
}
}
How should I specify the compilerArgs when the path contains spaces in it?
I’ve was able to find a way to do this, but it feels like a hack:
apply plugin: 'cpp-lib'
libraries {
main {
binaries.withType(SharedLibraryBinary) {
if (toolChain in VisualCpp) {
tasks.withType(CppCompile) {
includes.from("C:\Program Files\Java\jdk1.8.0\include")
includes.from("C:\Program Files\Java\jdk1.8.0\include\win32")
}
}
}
}
}
Hi Christo,
When I am trying to add include paths in a way you have specified I am getting below error. Can you please provide any pointers?
-
Where: Build file ‘H:\Work\CSF Onboarding\ClassifyCodeBase\CopiedCode\CopiedSourceCode\build.gradle’ line: 207
-
What went wrong: Could not compile build file ‘H:\Work\CopiedCode\CopiedSourceCode\build.gradle’. > startup failed:
build file ‘H:\Work\CopiedCode\CopiedSourceCode\build.gradle’: 207: unexpected char: ‘’ @ line 207, column 37.
includes.from("$project.buildDir…")
^
1 error
- Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Hi Minal
We’ve since moved on to use Gradle 2.0. To add the include path I’m using the following snippet, but I expect “org.gradle.internal.jvm.Jvm.current()” to break in a future version of Gradle.
binaries.withType(NativeBinary) {
// Define toolchain-specific compiler and linker options
if (toolChain in VisualCpp) {
def javaHome = org.gradle.internal.jvm.Jvm.current().javaHome.absolutePath
cppCompiler.args "-I${javaHome}/include"
cppCompiler.args "-I${javaHome}/include/win32"
}
}
Thanks for reply Christo…
I figured out my mistake in above snippet. It expects \ instead of . after changing \ to \ it worked fine.
But now I am stuck with library include path.
Can you please help me if you have any idea how to specify library include path in windows?
I have tried to add it like below but it doesn’t seem to be working
binaries.all { if (toolChain in VisualCpp) {
linker.args “/LIBPATH:${SYBASE_DIR}\lib” } }