Linking bug (?) and linking questions

Jeff Sturm jsturm@sigma6.com
Sat Apr 1 00:00:00 GMT 2000


Korbinian Strimmer wrote:
> 1) Linking is not possible when object with main function is
> part of a package (THIS MIGHT BE A BUG):

[snip]
> Compiles perfectly to Sample.class (given a proper location)
> and to Compile.o but does not link:
>> cj -o sample --main=Sample Sample.o

Use the fully-qualified class name:
 gcj -o sample --main=test.Sample Sample.o
> 2) Easier linking:
>> How can I avoid to specify the objects to be linked manually?
> After all, the compiler does know by itself where the compiled
> classes are (through CLASSPATH) and even gives me a list of
> dependencies if I want?
>> Any tricks for that? (This would make life much easier because
> bascially all objects in my library are to some degree related with
> each other. Apart from that, the precise path where the objects
> actually reside changes from system to system).

You'll probably want to use a Makefile, as you would in any non-trival C
program.
You might try adding each object to a library, e.g.:
 gcj -c Class1.java -o Class1.o
 gcj -c Class2.java -o Class2.o
 ar rv myclasses.a Class1.o Class2.o
 ranlib myclasses.a
then:
 gcj myprog.java --main=myprog myclasses.a -o myprog
> 3) Maybe I can link versus the whole library? If so, how do I
> link with gcj all my libary objects (that do not contain a
> main function) together to one single file? Can this file be
> used a shared library?

It can be a shared library, or normal (.a) library archive. See above. 
The command syntax is basically the same as for gcc.
> 4) If I link objects files produced with gcj together gcj also seems
> to include all the unnecessary code (e.g., if I add an object that
> is not used anywhere). Is is a property of the linker in gcj, or
> a general property of ld?

That's how ld works. Any .o files you include get linked no matter
what. If you want them to be conditionally linked, use an object
library.
-- 
Jeff Sturm
jsturm@sigma6.com


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /