Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sample Make file for Solaris gcc shared library

Posted on 2001-07-10
7
Medium Priority
?
793 Views
Last Modified: 2013-12-05
I am looking for simple working example of a sample makefile which will compile a simple c file into a shared library using the gcc compiler on solaris. using ELF format


// sample program to create a libary

#include <stdio.h>

void ExecuteRequest(void)
{
    printf("Invoked application exported function\n");
}

thanks
Matthew
0
Comment
Question by:MJUNG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:garboua
ID: 6270447
all:
<tab> gcc -c ExeccuteRequest.c
<tab> ar -cr libYourLibName.a ExeccuteRequest.o

this is a very simple makefile to create LibYourLibName.a
the first "lib" in library name is a Must.
you can use the following if you have more than one file to populate the library.

FILES = one.c \
         two.c \
         three.c \
         another.c
OBJS = (FILES.c=.o)

.c.o:
<tab> gcc -c $< -o $@
then you can
ar -cr libYourLibName.a $(OBJS)
which will take all you object files and stick em into the library.  now OBJS is build depending on FILES. and the .c.o: will know how to produce each obj.  
0
 

Author Comment

by:MJUNG
ID: 6270462
Hello Garboua

I am look ing for one that produces a shared library
using the -fPIC ELF format ? Do I still need to use the ar ?
Matthew

0
 
LVL 5

Expert Comment

by:garboua
ID: 6270537
NO,
you do this
"gcc -shared -fPIC ExeccuteRequest.c -o libMySTUFF.so"
sorry should have read better.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MJUNG
ID: 6270557
Another Question

You stated that the name of the library must begin with the literal lib. Why is this ?
0
 
LVL 5

Accepted Solution

by:
garboua earned 800 total points
ID: 6270627
when you link you will do something like this
"gcc mainDriver.o -lMySTUFF -o OUTPUT"
and the linker knows to look for something that begins with lib-MySTUFF-.extension ".a .so"
so there is no Way around that, it is just the way of the Penguins :-)
Take a look under /lib and /usr/lib and you will see all libraries begin with "lib" and then the extension.
CIAO
0
 

Author Comment

by:MJUNG
ID: 6270636
Ok thanks for your help
I will do some more reading
but your help is greatly apprciated!
0
 
LVL 5

Expert Comment

by:garboua
ID: 6270706
:-)
"man ld" will give you libraries option and how to include them, the difference between "-L" and "-l" etc etc
the Most single Important Document that you can have is
http://www.linuxguru.com/docs/howto/GCC-HOWTO
search for ELF and you will find TONS of info, more than you might need. it also include info about other stuff. a very good document.  short sweet to the points.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question