• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How to build a shared library for JNI

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying this for over a month. Sun tutorial only tells me how to do it under Solaris or with Visual C++ under windows.
My problems are stated as follows:
1. I have access to a Solaris SunOS 5.8, but it does not have any C/C++ compiler. I downloaded gcc2.95.3 from sunfreeware.com, and tried doing pkgadd, but the pkgadd is unfortunately not available on the system.
2. The unix system of my university, which I also have access to, does have both Java and C/C++ compilers, but the problem is I don't know how to build a shared library on that system. That system is Digital UNIX V4.0F OSF1 1229 alpha.
3. I don't have Visual C++ under my Windows box, but do have the free command line C++ compiler offered free by Borland. But I don't know how to build a shared library with it.
I have been checking with quite a few people, none of them was able to help.
So, dear gurus, can you guys help me out?
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gene Chao:
I have been trying this for over a month. Sun tutorial only tells me how to do it under Solaris or with Visual C++ under windows.
My problems are stated as follows:
1. I have access to a Solaris SunOS 5.8, but it does not have any C/C++ compiler. I downloaded gcc2.95.3 from sunfreeware.com, and tried doing pkgadd, but the pkgadd is unfortunately not available on the system.
2. The unix system of my university, which I also have access to, does have both Java and C/C++ compilers, but the problem is I don't know how to build a shared library on that system. That system is Digital UNIX V4.0F OSF1 1229 alpha.
3. I don't have Visual C++ under my Windows box, but do have the free command line C++ compiler offered free by Borland. But I don't know how to build a shared library with it.


1. pkgadd requires root access to the system. Unless it was removed after the fact, I doubt it's not actually there; pkgadd is used in system installation. Is /usr/sbin in your PATH?
2. Compilers tend not to change their switches from Unix to Unix; that's a lot of extra work put on people who have to maintain programs across several platforms and compiler vendors do try to use conventions to ease the pain. Try the same arguments for the DEC compiler and see what happens.
3. Have you consulted Borland's support pages for their compiler?

------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, no wonder I can't use pkgadd. The guy who manages that system is kinda lazy, I have talked with him for quite a few times, but there is not action from him. That sux.
I did check Borland website, but did not find anything helpful about this problem.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had to do the same some times ago but under Linux.
Here is how I proceeded:
1. I wrote my Java class with native method declarations
2. I compiled the Java class
3. I ran javah to gerenate the C header file
4. I implemented the C file
//up to here exactly as mentioned in the Sun tutorial
//now to build the shared library the command provided in Sun's tutorial did not achieve what I wanted, so here are the command I used:
5. first compile your C file
cc -c -I/usr/include -Ipath_to_java_include -Ipath_to_java_include_linux your_c_file.c
6. then link the file with the libraries they depend on:
ld -o name_of_your_shared_library.so your_c_file.o other_object_files.o -shared
7. finally copy the resulting shared library somewhere to your library path ...
8. Enjoy !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are smart. I don't know if I can handle it under Linux. I have removed the linux box. So I have to reinstall it? That also sux. Thanks a lot for sharing with me your experience.
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should work under Solaris as well... I've not tried it though.
It's not as difficult as it seems... you just have two commands to run...

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic