Steps to generate shared library(Native) AIX is 6.1

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.
jgdvishnuSoftware ArchitectAsked:
Who is Participating?
jgdvishnuConnect With a Mentor Software ArchitectAuthor Commented:
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

To build a DLL, you'd use g++ as follows:

g++ -O3 -shared -o 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

jgdvishnuSoftware ArchitectAuthor Commented:
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 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 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 "".
$ g++ -shared -o 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?
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

jkrConnect With a Mentor Commented:
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..
sarabandeConnect With a Mentor Commented:
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

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.

jgdvishnuSoftware ArchitectAuthor Commented:
All steps lead to final solution
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.