Solved

Exporting Symbols on AIX using gcc

Posted on 2006-11-27
5
881 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
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.

744 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