This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCJ and MySQL Connector for Java
On Sun, 2005-11-20 at 20:49 +0200, Spyros Stathopoulos wrote:
> OK, I have something new, however I do not know if this is a "legal" way.
You're almost there.
> I've bundled all the source files for mysql connector found in the
> source rpm in a single jar file and compiled it into a shared library,
> which I've copied in /usr/lib.
>
> gcj -classpath /usr/share/java/log4j.jar -shared -o
> libmysql-connector-java-3.1.8.so mysql-connector-java-3.1.8.jar
>
> After running ldconfig, I compile sucessfully my program with GCJ as following:
>
> gcj -O0 -g "--classpath=/usr/share/java/mysql-connector-java.jar:./src/:"
> -c src/org/testing/TestConnectMySQL.java -o
> src/org/testing/TestConnectMySQL.o
>
> gcj -O0 -g --main=org.testing.TestConnectMySQL
> src/org/testing/Connect.o -odebug/MySQL-Test -Ldebug
> -lmysql-connector-java-3.1.8
Your program has no symbolic reference to the mysql driver, it's just a
textual reference. So linking the driver .so file to the executable
will have no effect.
When I said you need to force the library into you program, I meant by
creating mysql-connector-java-3.1.8.a file and the linking with
-Wl,--whole-archive,-lmysql-connector-java-3.1.8,--no-whole-archive.
Or you can rename the .so file to lib-com-mysql-jdbc.so, which is a
special name recognized by the gcj runtime (run your program with strace
to see how it tries to find libraries at runtime).
Or you can include a symbolic reference to a com.mysql.jdbc class to
force the .so to be loaded into your application.
You can also try running your program like so:
$ LD_PRELOAD=/usr/lib/libmysql-connector-java-3.1.8.so ./debug/MySQL-Test
Although I'm not certain if that last trick will work.
AG