This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Problem with linking to shared native library
- From: Andreas BÃrgel <Andreas dot Buergel at web dot de>
- To: java at gcc dot gnu dot org
- Date: Sun, 04 Mar 2007 22:30:12 +0100
- Subject: Problem with linking to shared native library
- Reply-to: mail at andreas-buergel dot de
Hi folks,
I'm trying to link a gcj compiled simple application to native library,
but get following linker error:
gcj -O0 -g "--classpath=./:" -c
de/dbt/simplelibclient/SimpleCPPLib.java -o
de/dbt/simplelibclient/SimpleCPPLib.o
gcj -O0 -g --main=de.dbt.simplelibclient.SimpleCPPLib
de/dbt/simplelibclient/SimpleCPPLib.o -oDebug/SimpleLibClient -LDebug
-L/home/andreas/develop/projects/SimpleCPPLib/Debug -lSimpleCPPLib -lgcj
de/dbt/simplelibclient/SimpleCPPLib.o:(.data+0xc): undefined reference
to `hidden alias for de::dbt::simplelibclient::SimpleCPPLib::square(int)'
de/dbt/simplelibclient/SimpleCPPLib.o:(.data+0x88): undefined reference
to `hidden alias for de::dbt::simplelibclient::SimpleCPPLib::square(int)'
collect2: ld returned 1 exit status
The "library" has only one method and following by gcjh generated files:
"SimpleCPPLib.h":
-----------------
// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-
#ifndef __de_dbt_simplelibclient_SimpleCPPLib__
#define __de_dbt_simplelibclient_SimpleCPPLib__
#pragma interface
#include <java/lang/Object.h>
#include <gcj/array.h>
extern "Java"
{
namespace de
{
namespace dbt
{
namespace simplelibclient
{
class SimpleCPPLib;
}
}
}
}
class de::dbt::simplelibclient::SimpleCPPLib : public ::java::lang::Object
{
public:
SimpleCPPLib ();
virtual jint square ( jint pNumber);
static void main (JArray< ::java::lang::String *> *);
static ::java::lang::Class class$;
};
#endif /* __de_dbt_simplelibclient_SimpleCPPLib__ */
"SimpleCPPLib.cc":
------------------
// This file was created by `gcjh -stubs'. -*- c++ -*-
//
// This file is intended to give you a head start on implementing native
// methods using CNI.
// Be aware: running `gcjh -stubs ' once more for this class may
// overwrite any edits you have made to this file.
#include "SimpleCPPLib.h"
#include <gcj/cni.h>
#include <java/lang/UnsupportedOperationException.h>
//#pragma implementation
jint
de::dbt::simplelibclient::SimpleCPPLib::square (jint)
{
throw new ::java::lang::UnsupportedOperationException
(JvNewStringLatin1 ("de::dbt::simplelibclient::SimpleCPPLib::square
(jint) not implemented"));
}
My Java Class looks as follows:
"SimpleCPPLib.java":
--------------------
package de.dbt.simplelibclient;
import de.dbt.simplelibclient.*;
public class SimpleCPPLib {
public native int square ( int pNumber);
//public native int mult ( int pNumber);
/**
* @param args
*/
public static void main ( String[] args) {
SimpleCPPLib lLib = new SimpleCPPLib ();
System.out.println ( " square of 5 is " + lLib.square( 5));
//System.out.println ( " mult of 5 is " + lLib.mult ( 5));
}
}
The C++ library was built with these command-output:
Building file: ../SimpleCPPLib.cc
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -MMD -MP -MF"SimpleCPPLib.d" -MT"SimpleCPPLib.d"
-o"SimpleCPPLib.o" "../SimpleCPPLib.cc"
Finished building: ../SimpleCPPLib.cc
Building target: libSimpleCPPLib.so
Invoking: GCC C++ Linker
gcj -L/usr/lib/gcc/i586-suse-linux/4.1.2 -L/lib -shared
-o"libSimpleCPPLib.so" ./SimpleCPPLib.o
Finished building target: libSimpleCPPLib.so
libSimpleCPPLib.so exists and seems to contain the required symbols when
looking into it with "nm".
When I link the application - the main program - with the Object
"SimpleCPPLib.o" (from library project), it works fine and all
references are fulfilled.
I'm working on this for a couple of days in lots of permutations. Is it
a fundamental problem or feature?
By the way, what are "hidden aliases"?
Platform info:
- gcj version: 4.1.2 20061115
- binutils version: 2.17.50.0.5 20060927
- OS: openSUSE 10.2, kernel 2.6.18.2-34-default
- glibc version: 2.5 (20061011)
Thanks in advance for any help.
--
Mit freundlichen Grueszen, / With kind regards,
Andreas BÃrgel
Diplom-Informatiker (Ingenieur-Informatik)
Software-Engineer/-Architect
http://www.andreas-buergel.de/profile.html
Unbedingt lesenswerte Site:
http://www.nachdenkseiten.de
Entia non sunt multiplicanda sine necessitate.
-- William of Ockham