LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to create .so file on fedora 7? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-so-file-on-fedora-7-a-798055/)

shrivaths 03-26-2010 09:25 AM

How to create .so file on fedora 7?
 
Hello friends,

I am working on JNI(Java Native Interface) on fedora 7 where i need to create a .so file of .c.(For example Hello.c to Hello.so).
But i am not getting options to be used with the "cc" command.
So please tell me the option or the command.

schneidz 03-26-2010 09:49 AM

this probably should go in the programming forum.
i know with c you can use gcc -c to create a shared object. keep in mind that object code simply doesnt have an enfty point.

John VV 03-26-2010 02:00 PM

First fedora 7 is OLD and unsupported . Please install the current fedora 12
"example Hello.c to Hello.so)."
read the gcc docs
so you want to make an executable lib ( .o) and not a normal executable file

johnsfine 03-26-2010 02:12 PM

Quote:

Originally Posted by shrivaths (Post 3913305)
I am working on JNI(Java Native Interface) on fedora 7 where i need to create a .so file of .c

The main thing you need is -shared on the gcc command line.
I'm not sure what else you might need: Switches specific to JNI? Specific the version of gcc you're using (what version is that?) Specific to your architecture (I expect X86, but if it is X86_64, that requires some extra switches).

Quote:

Originally Posted by schneidz (Post 3913333)
you can use gcc -c to create a shared object.

No. that is to create a .o file (an object file) not a .so file (shared object file).

Quote:

Originally Posted by John VV (Post 3913587)
First fedora 7 is OLD and unsupported . Please install the current fedora 12

Interesting point. But I don't know how important that is. The version of GCC may be a more relevent question.

Quote:

read the gcc docs
That is harder than you might expect. The man page for gcc is so disorganised, incomplete and misleading to be basically worthless. The info documentation for GCC is terribly hard to navigate.

If you must read GCC documentation, I find the online HTML version to be at least practical to navigate, which compensates some for the poor organization. I don't know if that is even available for whatever old version of GCC the OP is using. I'm using 4.3.2, documented at:
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/index.html

If you knew a moderate amount about GCC, but not much about how it is documented, you would click from there into GCC Command Options and from there into Options Controlling the Kind of Output and try to find where it tells you how to chose .so as the kind of output. No such luck.

The -shared switch is documented (sort of) in the section on Options for Linking

shrivaths 03-27-2010 01:57 AM

Thank you guys for your support

I got the so file using cc with -c option, and now i want to set the "library path".
But with some reference i got the information about the "ld.so.conf" where i need to edit the new path and have to update the ld.so.cache file.
I did the same thing but i am not able to execute that "ld.so.cache".

johnsfine 03-27-2010 06:49 AM

I think you are way off track at the moment:

Quote:

Originally Posted by shrivaths (Post 3913305)
I am working on JNI

It has been a while since I did JNI programming, so I forget some details. But I do recall some basic info.

A .so for JNI is not loaded when the executable (java) is loaded. It is loaded later by that executable. So the search rules that apply to .so files loaded with an executable don't apply. Java has its own, different, search rules for the .so files it loads later for JNI.

Quote:

Originally Posted by shrivaths (Post 3914113)
with some reference i got the information about the "ld.so.conf" where i need to edit the new path and have to update the ld.so.cache file.

I'm pretty sure you don't want to edit ld.so.conf
First, because the .so for JNI is found by different rules.
Second, because you usually don't want to edit ld.so.conf even for .so files found the common way: You either want to put the .so where it would be found normally or change the LD_LIBRARY_PATH environment variable.

Quote:

I did the same thing but i am not able to execute that "ld.so.cache".
That's so far off track I can't even guess what you're trying to do.

Quote:

Originally Posted by shrivaths (Post 3914113)
I got the so file using cc with -c option

As I explained earlier, that is also wrong.

schneidz 03-27-2010 08:58 AM

Quote:

Originally Posted by johnsfine (Post 3913603)
...
No. that is to create a .o file (an object file) not a .so file (shared object file)...

hi i never knew the difference between a *.o and a *.so -- i thought they were the same. thanks for the correction.


All times are GMT -5. The time now is 09:12 PM.