Solved

Exporting Symbols on AIX using gcc

Posted on 2006-11-27
5
886 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unistall fileset without dependecies on AIX 3 60
unix scripting question 1 89
unix solaris snoop command 6 84
Linux hostname change 2 52
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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.
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.

914 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

17 Experts available now in Live!

Get 1:1 Help Now