0

There is a set with - files with extension.с: avl_tree.c, buf_read.c, db_prep.c, file_process.c, global_header.c, traverser.c. Used include files are in folder/usr/gcc/4.4/bin/include except for jni.h, and libraries are in folder/usr/gcc/4.4/bin/lib. How from them to create.so the file (if it is possible specify all options in this command)? It me interests in communication by creation of native of methods by means of JNI.

user1730626
  • 437
  • 1
  • 8
  • 16

2 Answers2

1

You really should read the documentation of GCC. Notably invoking GCC. The program library howto is also relevant.

Very often, some builder is used to drive the build. GNU make is often used and has a good tutorial documentation. If your Makefile-s are complex, you may also want to use GNU remake to debug them (remake is a debugging variant for make).

You usually want to compile each individual C source file into position independent code because shared objects have PIC code. You can use

 gcc -Wall -fPIC -o foo.pic.o foo.c

to compile a C source foo.c into a position independent object file foo.pic.o and you may need some other compiler options (e.g. -I to add include directories, or -D to define some preprocessor symbols, -g for debugging, and -O for optimizing).

I strongly suggest to enable almost all warnings with -Wall (and to improve your code till no warnings are given; this will improve a little bit your code's quality).

Then you have to link all these *.pic.o files together into a shared object with

 gcc -shared *.pic.o -o foo.so

You can link some shared libraries into a shared object.

You may want to read Levine's book on linkers and loaders

Of course if you use GNU make you'll have rules in your Makefile for all this.

You could use GNU libtool also.

Maybe dlopen(3) could interest you.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

The question should probably give more information.

Most sets of sources have a Makefile, configure script or some other item to set up to make the output (the .so library you want).

gcc -dynamic -o file.so file.c

will create an so file from one of the source files, but you probably want a single so from all of them.

Brian Lloyd
  • 173
  • 7