Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Steps to generate shared library(Native) AIX is 6.1

Posted on 2014-02-19
Medium Priority
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
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
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 400 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..
Industry Leaders: 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!

LVL 35

Assisted Solution

sarabande earned 800 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

722 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