?
Solved

Exporting Symbols on AIX using gcc

Posted on 2006-11-27
5
Medium Priority
?
911 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 900 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

719 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