Solved

Steps to generate shared library(Native) AIX is 6.1

Posted on 2014-02-19
6
399 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
  • 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 32

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now