0

Example of codes to to illustrate the problem: file liba.c:

 int ajob (void)
 {
     return 19;
 }   

compiled with:

gcc -Wall -c liba.c
ar rcs liba.a liba.o

file so.h:

int ajob (void); 
int sojob (void);

file libso.c

#include "so.h"
int sojob (void)
{
   return 4;   
}
#if defined(WILLWORK)
void afoo(void)
{
    ajob();
}
#endif

compiled with:

gcc -shared  -L ./ -o libso.so -la -fPIC libso.c

this will not include the ajob function in the shared lib. But this will:

gcc -shared  -L ./ -o libso.so -la -fPIC libso.c -DWILLWORK

file to test this (appl.c):

#include <stdio.h>
#include "so.h"
int main(void)
{
    printf ("so + a = %d \n", sojob() + ajob());
    return 0;
}

Compiled with:

gcc -Wall -lso appl.c -L ./  -R ./ 

My question is, is there a more preferred way to include a static lib in a shared lib, avoiding such a dummy function as "afoo" ?

0 Answers0