Solved

Steps to generate shared library(Native) AIX is 6.1

Posted on 2014-02-19
6
421 Views
Last Modified: 2014-02-25
I created Java native method written in C++ on windows as suggested in:
 
Java programming with JNI

I creatde dll and it works on windows.
However how do we create and deploy the same shared lib on AIX 6.1 environment.  and how we set path to make the shared library accessible to web applications.
0
Comment
Question by:jgdvishnu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39871487
To build a DLL, you'd use g++ as follows:

g++ -O3 -shared -o libmyJNI.so myjni.cpp otherfile.cpp [other options]

Open in new window


The you'll need to set _LD_LIBRARY_PATH to point to the directory where your DLL resides, e.g.

declare -x _LD_LIBRARY_PATH=$_LD_LIBRARY_PATH:/path/myJNIdir

Open in new window

0
 

Author Comment

by:jgdvishnu
ID: 39872064
JKR, I like your indepth knowledge.

Q1. what is "-O3" in build statement?
Q2 I need to add *.def and *.h files

I tried this command :-
$ g++ -AIX -shared -o TestJNI.so Test.cpp Test.def Test.h

Open in new window


I got:-
<command-line>:0:1: error: missing '(' after predicate

Open in new window


I dropped AIX from command
$ g++ -shared -o TestJNI.so Test.cpp Test.def Test.h

Open in new window

// and I got compilation error as shown below which is method defined in Test.def
Cannot export Java_Test_booleanMethod: symbol not defined

Open in new window


Later I dropped Test.def and it compiled to generate the "TestJNI.so".
$ g++ -shared -o TestJNI.so Test.cpp Test.h

Open in new window


could you please share what each of these file parameters impact or not. I need little help document.

Q3 Are all this approach correct?
Q4 I donot have access to AIX server so I try on Cygwin prompt. Is this ok.
Q5 Is there a cloud AIX server that is cheaply available to test this out?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 39872257
Q1: '-O3' is just an optimization switch for g++, you can safely omit that and add that later on if needed. Yet I am puzzled about the error messages.

Q2: You can't use Windows .def files on UN*X OSs, they simply don't make sense there and aren't required. Or are you referring to other files than these

Q3: See Q2, there is no such thing as module definition files on platforms other than Windows. Just skip that step.

Q4: I can be OK to start out with, yet you might encounter AIX specific things later on. Yet I have to say that the amount of work reusing Cygwin compatible code on OS X/Linux/FreeBSD is/was minimal, I mostly exprienced having to adapt certain compiler options in Makefiles or naming conventions (e.g. on OS X you would have to use 'myJNI.dylib' as a file extension)

Q5: Sorry, I I have no idea - last time I dealt with AIX I had a machine, and that was like over a decade ago..
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 34

Assisted Solution

by:sarabande
sarabande earned 200 total points
ID: 39873065
the standard c/c++ compiler for AIX is xlC. I never experienced an AIX environment where gcc was used (or allowed to be used). and it makes some troubles to port the one to the other, see

http://www.ibm.com/developerworks/aix/library/au-gnu.html

I had a few projects (not recently) where I had to write portable software for windows, linux, aix and solaris. you can do this for the source code only. all build issues need to have a platform-specific handling which could not be done without having access to this platform even for experienced developers. if using a makefile for each platform, the differences are less as they would be if using project files in an ide. so using mingw makefiles could make it simpler but it is still a lot of work.

the xlC documentation is very good. you should try to get access to an aix server and then port makefiles from mingw to those for xlC. I used my visual c++ ide for source code (and building the windows variant) and then passed the changed sources using an svn tool (for example tortoise svn).

unfortunately I never worked with java on neither platform.

Sara
0
 

Accepted Solution

by:
jgdvishnu earned 0 total points
ID: 39874880
Thanks Sara I got access and along that line The below link worked with some command issues -

Example of using AIX shared libraries

The command that actually worked were -
//From C files to output file 
gcc -shared -I /usr/java5/include Sample.c -o libSample.o

//to create shared archive
ar -Xany -v -q libShared.a libSample.o

//To Run -
LIBPATH=. java Sample

Open in new window

0
 

Author Closing Comment

by:jgdvishnu
ID: 39885117
All steps lead to final solution
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question