0

I'm trying to create a shared library out of my C program. How do I do that? I think you need the program, so here it is:

#include "defs.h"
#include "externs.h"


int CheckPrime(int K){

int J;

J = 2;
while (1)  {
  if (Prime[J] == 1)
     if (K % J == 0)  {
        Prime[K] = 0;
        return 0;
     }
  J++; 
break;
}


Prime[K] = 1; 
}

I've also made a Makefile, can I do it in it?:

# -----------------------------------
# ------ executable rule  -----------
# -----------------------------------
app : app.o
    -gcc -g  app.o -o app

# ---------------------------------------------------
# ------ intermeditate object files rule (.o) -------
# ---------------------------------------------------
app.o : main.c
     -gcc -g -c main.c -o app.o
Hudhud
  • 7
  • 4

1 Answers1

1

Yes, simply add the -shared flag to gcc.

gcc -g -shared app.o -o libapp.so

you can also use the soname option to control versioning, example

gcc -g -shared -Wl,-soname,libapp.1.0.0.so app.o -o libapp.so

to indicate it's version 1.0.0 API.

Community
  • 1
  • 1
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97