Solved

Sample Make file for Solaris gcc shared library

Posted on 2001-07-10
7
765 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
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:garboua
Comment Utility
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
Comment Utility
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
Comment Utility
NO,
you do this
"gcc -shared -fPIC ExeccuteRequest.c -o libMySTUFF.so"
sorry should have read better.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:MJUNG
Comment Utility
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 200 total points
Comment Utility
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
Comment Utility
Ok thanks for your help
I will do some more reading
but your help is greatly apprciated!
0
 
LVL 5

Expert Comment

by:garboua
Comment Utility
:-)
"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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now