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.
2 Answers
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.

- 223,805
- 18
- 296
- 547
-
Why the option - Wall is necessary? – user1730626 Oct 21 '12 at 10:49
-
The option `-Wall` gives you warnings from the compiler, and the warnings usually catch easy mistakes. You can find on stackoverflow a lot of "stupid" questions which would have been caught with `-Wall` – Basile Starynkevitch Oct 21 '12 at 11:02
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.

- 173
- 7
-
I would suggest `gcc -Wall -shared -fPIC file.c -o file.so` – Basile Starynkevitch Oct 21 '12 at 06:09
-