Call Java functions in a C DLL

Discussion in 'C Programming' started by Ahmad Jalil Qarshi, Oct 20, 2008.

  1. Hi,

    I am develop a dynamic link library in C on AIX that will internally
    call java functions using JNI. This libaray will be finally used by
    other C Executable.

    There is only one function in C code i.e. Connect. This function
    internally use JNI and call java functions. Now while compiling I am
    facing problems. I think that there is some problem with my makefile.

    The make file is given hereunder:

    JAVA_HOME = /usr/java14
    JAVA_INC = $(JAVA_HOME)/include

    CC = cc
    LD = cc

    # Flags to create a dynamic library.
    DYNLINKFLAGS = -G -ostdlib -bnoentry -bM:SRE -brtl -bE:Interface.exp

    # files removal
    RM = rm -f

    #------------------------------------- Libs
    -----------------------------------#
    JAVALIBS = -L$(JAVA_HOME)/jre/bin/classic/
    LIBS = -ljvm -lpthread -lxnet -lnsl -lm -ldl
    #-------------------------------- Dependency
    rules---------------------------#
    # shared library files
    LIB_FILES = Interface.a
    #-------------------------------------
    OBJs-------------------------------------#
    # shared libraries object files
    LIB_OBJS = Interface.o

    all: $(LIB_FILES)
    # create our librarys
    Interface.a: Interface.o
    $(LD) $(DYNLINKFLAGS) $(JAVALIBS) $(LIBS) $(LIB_OBJS) -o $@

    # compile C source files into object files.
    %.o: %.c
    $(CC) $(DYNLINKFLAGS) -L$(JAVA_INC) -c $<

    # clean everything
    clean:
    $(RM) $(LIB_OBJS) $(LIB_FILES)

    # clean the library's object files only
    cleanlibobjs:
    $(RM) $(LIB_OBJS)



    Now the problem is that library is not properly created because the
    size of the Interface.a file is very small only 552 bytes. whereas the
    size of Interface.o file is 34428. Which clearly indicates that the
    problem is with the Interface.a file i.e during linking.

    Can any body help me to figure out the problem.

    Regards,

    Ahmad Jalil Qarshi
     
    Ahmad Jalil Qarshi, Oct 20, 2008
    #1
    1. Advertising

  2. Ahmad Jalil Qarshi

    Flash Gordon Guest

    Ahmad Jalil Qarshi wrote, On 20/10/08 23:33:

    <snip>

    > There is only one function in C code i.e. Connect. This function
    > internally use JNI and call java functions. Now while compiling I am
    > facing problems. I think that there is some problem with my makefile.


    <snip>

    Make files are not topical on comp.lang.c nor is how to interface to
    Java (because it is JAva that specifies this not C). Please keep the
    discussion of this on groups where it is topical, and I'm guessing that
    comp.unix.programmer and/or comp.unix.aix might be appropriate.
    --
    Flash Gordon
    If spamming me sent it to
    If emailing me use my reply-to address
    See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
     
    Flash Gordon, Oct 20, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anushi
    Replies:
    5
    Views:
    8,787
  2. Timothy Wong
    Replies:
    3
    Views:
    418
    Timothy Wong
    May 20, 2004
  3. Tony Johansson
    Replies:
    3
    Views:
    2,172
    Jack Klein
    Dec 16, 2004
  4. H. Simpson
    Replies:
    4
    Views:
    289
    H. Simpson
    Aug 3, 2004
  5. Replies:
    0
    Views:
    192
Loading...

Share This Page