简体   繁体   中英

Obtaining compiler include (and linker library) search paths for C code with JNI portably

I have a shared C library, libfoo.so , for which I'm creating a JNI interface. In order to compile the JNI interface library, libfoojni.so , compiler include search paths must be specified. For example, on Linux (using GCC) the following compiler flags are required: -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux .

Unfortunately, the latter path includes the platform. On SunOS the latter path is -I${JAVA_HOME}/include/solaris , on AIX it is -I${JAVA_HOME}/include/aix , and on HP-UX it's -I${JAVA_HOME}/include/hp-ux . This is a nuisance in the build files.

Is there a way to obtain the include paths portably? For example, with perl, you can use perl -MExtUtils::Embed -e ccopts to obtain the compiler flags and -e ldopts the linker flags, respectively. I'm looking for something similar to this, but haven't found anything.

This is really not a Java or JNI question at all.

The normal way to address this is to use something like the autoconf / automake tool chain which create Make files and 'configure' scripts that run on a wide range of platforms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM