Skip to main content

Trying JNI with NetBeans C/C++ Pack on Linux

Posted by iasandcb on December 17, 2006 at 1:04 AM PST

I started to read and soon realized that the article was for Windows while my main development machine is Ubuntu. OK, so it means that I don't need to install cygwin and the rest of the instructions in the article should work fine, right? (Un)fortunately, you need more than the difference in case you're a unixer (including Mac OS X). Here are what I've found during driving the course:

1. First of all, yes! you don't need to install cygwin :-)

2. "Press Ctrl - F11 to clean and build the project" doesn't work for my Linux. Shift - F11 does.

3. /include/win32 -> /include/linux

4. No options for compilation. Simply don't apply -mno-cygwin -Wl,--add-stdcall-alias -shared -m32. FYI, -shared is automatically added as the project is designed for dynamic library.

5. Make sure that your output file ends with not ".dll" but ".so".

These are all except adding -fPIC option for #4 when you work on a 64-bit machine because without the option the compiler complains "/usr/bin/ld: build/Debug/GNU-Linux-x86/HelloWorldNative.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC"

To be honest, this is my first time to create a JNI project. (No wonder I "was" a Java purist ;-) As I began working on Ruby (on Rails) and Python (on Django), I came to get some interest in using other languages than Java. I think that NetBeans C/C++ Pack opens a nice possibility to develop extensions for Java beyond the language itself.

Related Topics >>