Steps to generate shared library(Native) AIX is 6.1

Posted on 2014-02-19
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.
Question by:jgdvishnu
  • 3
  • 2
LVL 86

Expert Comment

ID: 39871487
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


Author Comment

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 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?
LVL 86

Assisted Solution

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..
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

LVL 33

Assisted Solution

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

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.


Accepted Solution

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


Author Closing Comment

ID: 39885117
All steps lead to final solution

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ipconfig not working on windows 10 bash shell; what other commands are missing. 17 180
aix unix tar error 3 66
Beginner to Unreal Engine 4 5 80
more than one jdk and one jre 1 41
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

777 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