Solved

Exporting Symbols on AIX using gcc

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

Industry Leaders: 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

Title # Comments Views Activity
llcommand 6 100
AIX    Volume group Auto ON/OFF question 2 126
auto mounter on hp-ux 2 34
Python Assistance 7 93
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 …
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

749 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