- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- What is the commad to make a sharable lib?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2000 04:00 PM
тАО07-18-2000 04:00 PM
I do not know if cc can make a sharable lib.
If it is, what is the option I should put in?
Please let me know.
Thanks.
Aijun.
Solved! Go to Solution.
- Tags:
- shlib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2000 09:22 PM
тАО07-18-2000 09:22 PM
SolutionFrom the ld(1) manpage:
"-b Create a shared library rather than a normal executable file. Object files processed with this option must contain position-independent code (PIC). See the discussion of PIC in cc(1), CC(1) (part of the optional C++ compiler documentation), f77(1), pc(1), as(1), and Linker and Libraries Online User Guide."
So, first you have to compile your source without linking it. To do so, use the cc(1) switch 'c. For example:
cc -c mylib.c -o mylib.o +z
ld mylib.o -o mylib.1 -b
The +z switch to cc means:
"Causes the compiler to generate position-independent code (PIC), necessary for building a shared library."
This should do the trick.
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-19-2000 11:07 AM
тАО07-19-2000 11:07 AM
Re: What is the commad to make a sharable lib?
Thank you very much for your help. I made my
shared library as you told me. It is called
testlib.1
Now I have a test.c, which calls the function in the testlib.1, I already made my test.o successfully. But when I try to make an exe, it gives me error as follows:
/home/azhang:cc -o test.o testlib.1
/usr/ccs/bin/ld: Unsatisfied symbols:
main
Please let me know how to make an executable when an sharable lib is used.
All the three files testlib.c testlib.h and test.c are in the same directory.
For your reference, my code is extremely simple.
testlib.h contains one line of code.
----------
int getint();
testlib.c is
-------------
#include "testlib.h"
int getint()
{
return 5;
}
test.c is
-----------
#include
#include
main()
{
int n;
n = getint();
printf("result is %dn", n);
}
Thanks.
Aijun.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-19-2000 11:14 AM
тАО07-19-2000 11:14 AM
Re: What is the commad to make a sharable lib?
My example was not completely accurate. You should name your library libtest.1
What you need to do next is
cc test.c -o test -L
The cc command will add the 'lib' in front of the 'test' to build the name libtest
This takes care of putting the right libraries in the library list for your executable. You can always check the built-in library paths by using the command 'chatr
Good luck,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-19-2000 12:36 PM
тАО07-19-2000 12:36 PM
Re: What is the commad to make a sharable lib?
I made the libtest.1, but when I try to produce my exe as you suggested. It gives me
error as following.
:cc -o test.exe test.o -L. -ltest
/usr/ccs/bin/ld: Can't find library for -ltest
The libtest.1 is there in the local directory. See the following.
/home/azhang:ls libtest.1
libtest.1
As I told you before, all the files are in the local directory.
Can you let me know what can be wrong?
Thanks.
Aijun.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-19-2000 12:55 PM
тАО07-19-2000 12:55 PM
Re: What is the commad to make a sharable lib?
I forgot a little detail. The name of the library must be libtest.sl
To solve the problem, don't rebuild your library with the .sk extension. Instead, create a symbolic link by executing the command:
ln -s libtest.1 libtest.sl
The reason to create libtest.1 is to support shared library versioning. When you build your executable, the linker will look for the .sl lib, but the .1 name will appear in the library list. (check with chatr). This is the way HP manages to run 10.20 executables on 11.00. They provide 2 sets of libraries. I.e libc.1 (for executables built on 10.20) and libc.2 (for executables built on 11).
This should solve your problems (provided I didn't forget anything ;-))
Bye,
Rik