I'm trying to cross-compile the JNI Bridge Jlibfprint using buildroot.
This is the source code.
Here is the .mk file:
JLIBFPRINT_VERSION = 775295f08174d11d39da9e327120b128ef270fc4
JLIBFPRINT_SITE = $(call github,eduardobogoni,jlibfprint,$(JLIBFPRINT_VERSION))
JLIBFPRINT_AUTORECONF = YES
JLIBFPRINT_SUBDIR = JlibFprint_jni
#JLIBFPRINT_CONF_OPTS = --enable-debug-log --enable-udev-rules=no --disable-debug-log
JLIBFPRINT_INSTALL_STAGING = YES
define PREPARE_FILES_AND_FIX_DIRECTORY
cd $(#D)/JlibFprint_jni && \
libtoolize
endef
JLIBFPRINT_PRE_CONFIGURE_HOOKS += PREPARE_FILES_AND_FIX_DIRECTORY
$(eval $(autotools-package))
Extract, Patch, Update, Configure, Autoreconfiguring, Patching libtool run without problem.
Then it failed at Building stage with this:
libfprint_jni_la-jlibfprint_JlibFprint.o
In file included from jlibfprint_Device.cpp:1:0:
jlibfprint_Device.h:5:10: fatal error: jni.h: No such file or directory
#include <jni.h>
^~~~~~~
compilation terminated.
Then I added, these includes to the /JlibFprint_jni/src/Makefile.am
ADD_INCLUDES=-I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -I/home/mariano/buildroot/output/build/libfprint-0.7.0 -I/home/mariano/buildroot/output/build/libfprint-0.7.0/libfprint/nbis/include
And now it fails with:
arm-linux-gnueabihf-g++: ERROR: unsafe header/library path used in cross-compilation: '-I/usr/lib/jvm/java-11-openjdk-amd64/include'
arm-linux-gnueabihf-g++: ERROR: unsafe header/library path used in cross-compilation: '-I/usr/lib/jvm/java-11-openjdk-amd64/include'
libtool: compile: /home/mariano/buildroot/output/host/bin/arm-linux-gnueabihf-g++ -DPACKAGE_NAME=\"libfprint_jni\" -DPACKAGE_TARNAME=\"libfprint_jni\" -DPACKAGE_VERSION=\"1.0\" "-DPACKAGE_STRING=\"libfprint_jni 1.0\"" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"libfprint_jni\" -DVERSION=\"1.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STRING=1 -DHAVE_IOSTREAM=1 -DHAVE_LIBFPRINT_FPRINT_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -I/home/mariano/buildroot/output/build/libfprint-0.7.0 -I/home/mariano/buildroot/output/build/libfprint-0.7.0/libfprint/nbis/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -c jlibfprint_JlibFprint.cpp -fPIC -DPIC -o .libs/libfprint_jni_la-jlibfprint_JlibFprint.o
Makefile:496: recipe for target 'libfprint_jni_la-jlibfprint_Device.lo' failed
Jlibfprint requires a JDK, but Buildroot doesn't have a JDK package. Therefore, building Jlibfprint using Buildroot will never work.
I downloaded JDK for ARM 32 bits and addded the includes into that folder.
I removed the BR2_COMPILER_PARANOID_UNSAFE_PATH=n as Arnout said it was wrong. And it cross-compiled without issues.
I ran the Sample Run and it worked with an Upek fingerprint scanner.
I am working on this now. Buildroot includes openjdk, but does not install the jni header files, so when using staging as sysroot for cross compilation, things go wrong.
As far as I can tell the jni headers (jni.h and jni_md.h) serve as type translations only and can be included without problem for the target. I added them to the sysroot and compiling works without issues.
Related
I download the source code of OpenJDK14 and put them in \home\yuanfang\jdk14 and after running bash configure --disable-warnings-as-errors and make images, I build OpenJDK14 successfully, The newly built JDK is in home\yuanfang\jdk14\build\linux-x86_64-server-release\jdk. By the way, I am using Ubuntu 20.04 LTS.
Then I want to debug OpenJDK14 using CLion IDE. I was using CLion 2020.2 and I take the following steps:
After open CLion I choose Create New CMake Project from Sources and choose the directory of \home\yuanfang\jdk14, which is the root directory of the jdk project.
I alter the Run/Debug Configurations to make it look like this:
CLion create a CMakeLists.txt automatically but the file doesn't work, so after googling I find find the correct CMakeLists.txt here at https://github.com/ojdkbuild/ojdkbuild/blob/master/src/java-14-openjdk/CMakeLists.txt. I then rewrite the old CMakeLists.txt using the correct one.
I download the whole repository(that is, github.com/ojdkbuild/ojdkbuild), unzip it and put it into \home\yuanfang\jdk14.
It looks like as follow, the ojdkbuild-master is the newly added folder.
I reload the CMake project, but some CMake error occurs(as follow), why can't CLion find those files? javaI googled but can't find any effective solution. Is there anything I can do or refer to? Thanks in advance.
CMake Error at CMakeLists.txt:19 (include):
include could not find load file:
/home/yuanfang/jdk14/../../resources/cmake/ojdkbuild_common.cmake
CMake Error at CMakeLists.txt:21 (include):
include could not find load file:
/home/yuanfang/jdk14/../../resources/cmake/version.cmake
CMake Error at CMakeLists.txt:93 (add_subdirectory):
add_subdirectory given source
"/home/yuanfang/jdk14/../../deps/rhino/scripting_tasks" which is not an
existing directory.
CMake Error at CMakeLists.txt:98 (ojdkbuild_add_subdirectory):
Unknown CMake command "ojdkbuild_add_subdirectory".
-- Configuring incomplete, errors occurred!
See also "/home/yuanfang/jdk14/cmake-build-debug/CMakeFiles/CMakeOutput.log".
Cannot get compiler information:
Compiler exited with error code 1: /usr/bin/cc -xobjective-c -I/home/yuanfang/jdk14/build/linux-x86_64-server-release/hotspot/variant-server/gensrc/adfiles......./loading/LibraryLoader/jar_src -g -fpch-preprocess -v -dD -E
Using built-in specs.
COLLECT_GCC=/usr/bin/cc
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)
COLLECT_GCC_OPTIONS='-I' '/home/yuanfang/jdk14/build/linux-x86_64-server-release/hotspot/variant-server/gensrc/adfiles' '-I' '......'-g' '-fpch-preprocess' '-v' '-dD' '-E' '-D' '___CIDR_DEFINITIONS_END' '-mtune=generic' '-march=x86-64'
cc1obj -E -quiet -v #/tmp/cci3XM6r -imultiarch x86_64-linux-gnu -D ___CIDR_DEFINITIONS_END /tmp/compiler-file5929385022787926768 -mtune=generic -march=x86-64 -fpch-preprocess -g -fworking-directory -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -dD
cc: fatal error: cannot execute 'cc1obj': execvp: No such file or directory
compilation terminated.
[Failed to reload]
step: check out this projecdt :https://github.com/ojdkbuild/ojdkbuild.git
step: put the source code of OpenJDK14 in ojdkbuild/src/
step: copy reousrces directory and CMakelists.txt to OpenJDK14
step: recomile openjdk and import project to CLin
I created a new Android Studio Project with C++ support and did not add anything to it. The project builds, compiles and runs with CMake. I then added the following two lines of code to CMakeLists.txt at the bottom of the file and I get a CMake build error.
find_package(Java COMPONENTS Development) # Line 47
find_package(JNI REQUIRED) # Line 48
And this is the error I get when building the project
-- Found Java: /usr/lib/jvm/java-10-oracle/bin/java (found version "10.0.1") found components: Development
-- Configuring incomplete, errors occurred!
CMake Error at /home/xxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
See also "/home/xxxxx/AndroidStudioProjects/MyApplication/app/.externalNativeBuild/cmake/release/x86_64/CMakeFiles/CMakeOutput.log".
JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
Call Stack (most recent call first):
/home/xxxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
/home/xxxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindJNI.cmake:314 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:48 (find_package)
External native generate JSON release: JSON generation completed with problems
CMake runs when being called form the command line, but fails inside Android Studio for some reason and I am not sure why.
EDIT 1
Here is the CMakeOutput.log file
EDIT 2
This is all that is in CMakeLists.txt file. It compiles in cmd with the command cmake.
cmake_minimum_required(VERSION 3.4.1)
find_package(Java COMPONENTS Development)
find_package(JNI REQUIRED)
This is the cmd output
E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\build>cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Users/xxxxx/AndroidStudioProjects/MyApplication/app/build
When I try to add it compile it in Android Studio using gradle I get the following error on Windows 10 pro 64 bit
Microsoft Windows [Version 10.0.17134.112]
(c) 2018 Microsoft Corporation. All rights reserved.
E:\Users\xxxxx\AndroidStudioProjects\MyApplication>gradlew build --stacktrace
> Task :app:generateJsonModelDebug
External native generate JSON debug: starting JSON generation
External native generate JSON debug: using platform version 24 for ABI ARMEABI_V7A and min SDK version 24
External native generate JSON debug: noticing that build file 'E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\CMakeLists.txt' is out of date with respect to E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.extern
alNativeBuild\cmake\debug\armeabi-v7a\android_gradle_build.json
External native generate JSON debug: rebuilding JSON E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a\android_gradle_build.json due to:
External native generate JSON debug: - a dependent build file changed
External native generate JSON debug: keeping json folder 'E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a' but regenerating project
External native generate JSON debug: executing cmake Executable : E:\Android\SDK\cmake\3.6.4111459\bin\cmake.exe
arguments :
-HE:\Users\xxxxx\AndroidStudioProjects\MyApplication\app
-BE:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a
-DANDROID_ABI=armeabi-v7a
-DANDROID_PLATFORM=android-24
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\build\intermediates\cmake\debug\obj\armeabi-v7a
-DCMAKE_BUILD_TYPE=Debug
-DANDROID_NDK=E:\Android\SDK\ndk-bundle
-DCMAKE_CXX_FLAGS=
-DCMAKE_TOOLCHAIN_FILE=E:\Android\SDK\ndk-bundle\build\cmake\android.toolchain.cmake
-DCMAKE_MAKE_PROGRAM=E:\Android\SDK\cmake\3.6.4111459\bin\ninja.exe
-GAndroid Gradle - Ninja
jvmArgs :
CMake Error at E:/Android/SDK/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
Call Stack (most recent call first):
E:/Android/SDK/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
E:/Android/SDK/cmake/3.6.4111459/share/cmake-3.6/Modules/FindJNI.cmake:314 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:4 (find_package)
-- Configuring incomplete, errors occurred!
See also "E:/Users/xxxxx/AndroidStudioProjects/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
Solved with
sudo apt-get install -y openjdk-8-jdk
sudo apt-get install -y default-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
As the CMake version bundled with Android tries to tell you, it can't find the JNI package because some parts were missing:
missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH
Checking the documentation for FindJNI (https://cmake.org/cmake/help/latest/module/FindJNI.html) these variables are set to the locations of libraries and headers not shipped with the Android version of JNI (to little surprise, Android does not included the AWT library for instance).
When running find_package(JNI REQUIRED), the FindJNI code checks if these variables are set and if not, issues an error.
A workaround is to set these variables yourself, before calling find_package:
# We are only interested in finding jni.h: we do not care about extended JVM
# functionality or the AWT library.
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
set(JAVA_INCLUDE_PATH2 NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
find_package(JNI REQUIRED)
Be aware though, that your code will only be able to use jni.h and its functionality: if it tries to access any other part of the JNI package it will fail (probably at compile time) because essentially, you have tricked CMake into thinking that the entire package was found, when in reality only a part of it exists in the Android setup.
I found a solution that works for me:
cmake_minimum_required(VERSION 3.10)
project("ktaglib")
set(JAVA_AWT_LIBRARY "$ENV{JAVA_HOME}/lib/libjawt.so")
set(JAVA_JVM_LIBRARY "$ENV{JAVA_HOME}/lib/server/libjvm.so")
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include")
set(JAVA_INCLUDE_PATH2 "$ENV{JAVA_HOME}/include/linux")
set(JAVA_AWT_INCLUDE_PATH "$ENV{JAVA_HOME}/include")
find_package(JNI REQUIRED)
You must set the environment variable JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64" beforehand.
More info: https://github.com/dockcross/dockcross/issues/576
Same on alpine:edge docker image, fixed using:
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
RUN apk add --no-cache openjdk8
ref: https://pkgs.alpinelinux.org/contents?branch=edge&name=openjdk8&arch=x86_64&repo=community
I have searched the entire web throughly for almost two days now and couldn't come up with a solution to my problem. I hope you guys can help me.
This might be a little specific but I am sure sooner or later others will experience the same problems.
I am currently using NetBeans Dev (Build 201803200002) with Java JDK 9.0.4 on a Windows 10, 64-bit system.
I was working through this JNI tutorial:
https://cnd.netbeans.org/docs/jni/beginning-jni-win.html
Almost at the end, below figure 13, you are supposed to build the project HelloWorldNative (in my case it is called JNITestNative).
But I always get the following error message:
cd 'D:\NetBeans\projects\JNITestNative'
C:\Programme\cygwin\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/d/NetBeans/projects/JNITestNative'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/JNITestNative.dll
make[2]: Entering directory '/cygdrive/d/NetBeans/projects/JNITestNative'
mkdir -p build/Debug/Cygwin-Windows
rm -f "build/Debug/Cygwin-Windows/JNITest.o.d"
gcc -mno-cygwin -Wl,--add-stdcall-alias shared -m32 -c -g -I/cygdrive/C/Program\ Files/Java/jdk-9.0.4/include -I/cygdrive/C/Program\ Files/Java/jdk-9.0.4/include/win32 -MMD -MP -MF "build/Debug/Cygwin-Windows/JNITest.o.d" -o build/Debug/Cygwin-Windows/JNITest.o JNITest.c
gcc: error: shared: No such file or directory
gcc: error: unrecognized command line option '-mno-cygwin'; did you mean '-mno-clwb'?
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/Cygwin-Windows/JNITest.o' failed
make[2]: *** [build/Debug/Cygwin-Windows/JNITest.o] Error 1
make[2]: Leaving directory '/cygdrive/d/NetBeans/projects/JNITestNative'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/d/NetBeans/projects/JNITestNative'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
NetBeans seems to be missing a file which I am expecting it to generate in the first place - JNITest.o
I checked the directories ...jdk-9.0.4/include, ...jdk9.0.4/include/win32 and ...Debug/Cygwin-Windows.
All of them exist, but the files JNITest.o.d or JNITest.o do not.
I tried to replace "cygwin" by "clwb" as suggested in the second error message, but the first error still occurs.
According to some sources in the internet I also removed the whole part "-mno-cygwin" from the additional options but the first error still occurs.
According to some other sources in the internet I added my ...cygwin/bin directory to the include directories, but this did not improve anything.
I have absolutely no idea how to solve this or how to search for other potential solutions anymore.
I hope anyone here can help.
The correct answer was stated by Jorn Vernee in his comment.
A '-' was missing before the argument "shared".
Thank you for that.
For anyone else who might be experiencing this problem, let me sum up how I got from here to a successful build.
According to this and this I added three code lines for the definition of data type __int64, so now my JNITest.c looks like this:
#ifdef __CYGWIN__
#define __int64 long long
#endif
#include <jni.h>
#include <stdio.h>
#include "JNITest.h"
JNIEXPORT void JNICALL Java_com_plaettner_jnitest_JNITest_nativePrint
(JNIEnv *env, jobject obj)
{
printf("\nHello World from C\n");
}
Next I added the packages "mingw64-i686-gcc-core: GCC for Win32" and "mingw64-i686-gcc-g++: GCC for Win32" to my Cygwin.
In NetBeans options - C/C++ - Build Tools I then changed the C and C++ Compiler from gcc/g++ to i686-w64-mingw32-gcc/g++ respectively.
In the project properties in the categories Build - C Compiler/C++ Compiler I changed the additional options from "-mno-cygwin -Wl,--add-stdcall-alias -shared -m32" to "-Wl,--add-stdcall-alias -shared" and added my ...cygwin/bin directory to the include directories.
This leads to a successful build already. Anyway I added "-m32" to the additional options again and changed c/c++ Compiler back to gcc/g++ to keep compliance to the tutorial.
Now this leads to a successful build as well, although it didn't before.
Removing the ...cygwin/bin directory from the include directories leads to a failed build again and the whole process has to be repeated.
At least for me it worked this way.
I'm trying to compile a 27KB .c file in Powershell (Windows 10) using java and the TDM-GCC MinGW provided on sourceforge (https://sourceforge.net/projects/tdm-gcc/). The code I am using (from published paper http://journals.plos.org/ploscompbiol/article?id=10.1371%2Fjournal.pcbi.1001059) generates an executable file using the following code:
gcc -O3 -finline-functions -fomit-frame-pointer -DNDEBUG -fno-strict-aliasing --param max-inline-insns-single=1800 -std=c99 -msse2 -DHAVE_SSE2 -DDSFMT_MEXP=521 -o toy_bat toy_bat.c
When I compile a 6KB example file this works fine. However when I compile the 27KB file I get the following error:
C:/TDM-GCC-64/bin/.../lib/crt2.o: In function '__tmainCRTStartup' followed by a load of 'relocation truncated to fit' messages.
From what I've read onling this error normally comes from a file being too large, but I find it hard to believe that A 27KB file is causing this. Does anyone have any suggestions as to what may be causing this?
Thanks!
I'm trying to get a working example of calling Java from C using JNI on ubuntu 64bit.
The code from: calling java function from c using jni I am compiling using:
gcc test.c -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include/linux -c
gcc test.o -L/usr/lib/jvm/java-1.7.0-openjdk/amd64/jre/lib/amd64/server/ -ljvm -o jniTest
This doesnt generate any errors but if I try ldd jniTest I get the following:
linux-vdso.so.1 => (0x00007fffe55d5000)
libjvm.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f85f2928000)
/lib64/ld-linux-x86-64.so.2 (0x00007f85f2d0a000)
And if I try ./jniTest it gives this error:
test.o: In function `create_vm':
test.c:(.text+0x35): undefined reference to `JNI_CreateJavaVM'
collect2: error: ld returned 1 exit status
With the -L/usr/lib/jvm/java-1.7.0-openjdk/amd64/jre/lib/amd64/server/ you tell the linker where to find libjvm.so. At runtime you will need to do the same (http://linux.die.net/man/8/ld.so). And you'll also need the parent directory because other needed libs are in there. One way to do this is by specifying it on the command line: LD_LIBRARY_PATH=/usr/lib/jvm/java-1.7.0-openjdk/amd64/jre/lib/amd64/server:/usr/lib/jvm/java-1.7.0-openjdk/amd64/jre/lib/amd64 ./jniTest.
A way to get around the need to specify the path is to not link to libjvm.so at all but to find it at runtime and then use the functions in dlfcn.h (http://linux.die.net/man/3/dlopen, http://linux.die.net/man/3/dlsym) to use it.