Solved

Exporting Symbols on AIX using gcc

Posted on 2006-11-27
5
901 Views
Last Modified: 2013-11-17
I am facing problem exporting symbols on AIX with gcc, while trying to load shared library.

For example I have two share files to be converted to shared library.

share1.c

****************************************************
#include <stdio.h>

int gval;

void func1 (){
printf("func1 called\n");
}

****************************************************

share2.c

****************************************************

#include <stdio.h>

int share2val;

void func2 (){
printf("func2 called\n");
}

***************************************************

Using following commands to build object files for the above two files,

gcc -c share1.c
gcc -c share2.c

Putting the obj files into an archive file using,

ar qv libsub.a share1.o share2.o


My main program contains the lines

main.c
***************************************************
#include <stdio.h>

extern void func1 ();

extern void func1 ();

extern int gval;

extern int share2val;

main() {
          func1 ();
          func2 ();
          gval = 6;
          share2val = 7;
          printf("gval <%d> share2val <%d>\n", gval, share2val);
}
****************************************************

to build main.c, when I use,

gcc -o main main.c -L/home/test/libsun.so

I get the following errors, (rightly so though it does not happen with Sun!)

*************************************************
ld: 0711-317 ERROR: Undefined symbol: gval
ld: 0711-317 ERROR: Undefined symbol: share2val
ld: 0711-317 ERROR: Undefined symbol: func1
ld: 0711-317 ERROR: Undefined symbol: func2
*************************************************

To Create the exports file necessary to explicitly export the symbols in the shared library that are referenced by other object modules

I have also created a export file as,

shrsub.exp

***********************************************************
#! /home/sharelib/shrsub.o

*
* Above, we have the full pathname to the shared library object file
* Below, we have the list of symbols to be exported:
*
gval
share2val
func1 ()
func2 ()

************************************************************

But I am unable to proceed further after this ... I mean creating a "shrsub.o" file from "shrsub.exp" file.

later using this "shrsub.o" file to get a executable of main.c.

Any help would be appreciated.
0
Comment
Question by:ch_kaushik
[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
  • 2
5 Comments
 

Author Comment

by:ch_kaushik
ID: 18019329
That would be,

ar qv libsub.so share1.o share2.o

instead of,

ar qv libsub.a share1.o share2.o


sorry!
0
 
LVL 14

Accepted Solution

by:
sjm_ee earned 300 total points
ID: 18063668
gcc -c share1.c
gcc -c share2.c
ld -G -bexpall -bnoentry -lc -o share1.so share1.o
ld -G -bexpall -bnoentry -lc -o share2.so share2.o
mv share1.so share1.o
mv share2.so share2.o
ar qv libsub.a share1.o share2.o
gcc -L. -lsub -o main-ar.exe main.c

For details see this URL:

http://www.redbooks.ibm.com/abstracts/sg245674.html?Open
0
 

Author Comment

by:ch_kaushik
ID: 18067587
If you could tell me why do we need following statements ... (as you mentioned)

mv share1.so share1.o
mv share2.so share2.o

Does AIX need to have object files only with .o extension?

I am very specific to this question as because I could find that in some other place within the same problem, object files having ext as ".so_obj" never worked. Strange it never worked ... untill I renamed the extensions as ".o"!!

Weird ... SunOS seems to work perfectly ok with any file extensions. And especially when unix does not have extension probs as windows!

ch_kaushik
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

734 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