export-dynamic


 
Thread Tools Search this Thread
Top Forums Programming export-dynamic
# 1  
Old 06-29-2006
export-dynamic

I load some dynamic libraries from main module (with dlopen). These libraries use 1 function from main module, therefore in Makefile I must use

gcc -g -Wl,--export-dynamic,-rpath,./lib -o not not.o db.o -ldl -ldb -lpcap

Note option --export-dynamic that is passed to the ELF linker.

The question is how can I determine which symbols must be put to the dynamic symbol table. I do not want to put all symbols, but putting only used once the function called by dynamically loaded libraries is not visible for these libraries.
# 2  
Old 06-29-2006
If I understand your question:
dynamic loading means you know the symbol names and the libraries names ahead of time - for the all the entrypoints you are going to map dynamically by calling dlopen yourself...

Right?

Code:
nm myexcutablefile

will list all of the external symbols your program uses. There will be a lot of them that are part of __start and the general C support runtime. Your special symbols need to be mapped by a call to dlopen.

Am I on track so far?
# 3  
Old 06-30-2006
This is not what I meant
Suppose I have 2 files: main.c, lib.c
Function func1() is defined in main.c, and lib.so is loaded from main.c: dlopen("lib.so", RTLD_LAZY)
Then func1() is called from lib.c. Becouse of this I need to put all symbols to the dynamic symbol table:
gcc -g -Wl,--export-dynamic,-rpath,. -o main main.o -ldl
How can put only func1() to the dynamic symbol table (omitting other symbols)?
# 4  
Old 06-30-2006
Sorry. I did not understand.

Since you are in a GNU development environment do you know about libltdl?
This allows you to handle what you are doing. See:
http://www.gnu.org/software/libtool/...#Using-libltdl

If you don't like that - what you have to do in code: do not directly reference the module you want by name, this is how you "hide" it from ld.

Example:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv) {
    void *libhandle=NULL;
    double (*myfunc)(double);
    char *errormsg=NULL;

    libhandle = dlopen ("/lib/libwhatever.so.1", RTLD_LAZY);
    if (!libhandle) {
        fputs (dlerror(), stderr);
        exit(EXIT_FAILURE);
    }

    myfunc = dlsym(libhandle, "myfunction");
    if ((errormsg = dlerror()) != NULL)  {
        fputs(errormsg, stderr);
        exit(EXIT_FAILURE);
    }

    printf ("%f\n", (*myfunc)(1.0));
    dlclose(libhandle);
    return 0;
}

You cannot hide fully qualified symbols from ld - it will try to link against each one, or generate an error.

Again, this is what I think you are saying: you have not "hidden" all the symbols. Correct me if I'm wrong. You can't play mix-n-match, some hidden, some not.
# 5  
Old 06-30-2006
Tanks a lot for a reply
I've solve my problem by moving the 'visible' functions (func1() in above example) from main module to another library that is linked at runtime Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

How use export

Hello, I'm trying to use export for non use "./" when I execute a program. I mean "program" in place of "./program" I tried this: export doit=program But doesn't work the answer is: doit command not found Then, I see the variables using export, and I can see: ... (1 Reply)
Discussion started by: NewBe
1 Replies

2. Shell Programming and Scripting

whoami export

how can I use whoami on a script for ordinary user? it always says command not found. pls help #!/bin/ksh W='whoami' DATE=`date "+%Y-%m-%d %H:%M:%S"` echo " $DATE- by $W" result 2011-03-29 09:46:16 - by you wil noticed the by is blank...pls help..but in root, it works (1 Reply)
Discussion started by: lhareigh890
1 Replies

3. Shell Programming and Scripting

export. I know it, but...

Hello, I have the following command at the "Shell": export PATH=${PATH}:${ANT_HOME}/bin I know what "export" does and the ANT_HOME part. But, regarding the following part: ${PATH} What is "PATH" Supposed to be here. In other words, what is the value of "PATH". As far as for... (4 Replies)
Discussion started by: SWEngineer
4 Replies

4. UNIX for Advanced & Expert Users

Sql dynamic table / dynamic inserts

I have a file that reads File (X.txt) Contents of record 1: rdrDESTINATION_ADDRESS (String) "91 971502573813" rdrDESTINATION_IMSI (String) "000000000000000" rdrORIGINATING_ADDRESS (String) "d0 movies" rdrORIGINATING_IMSI (String) "000000000000000" rdrTRAFFIC_EVENT_TIME... (0 Replies)
Discussion started by: magedfawzy
0 Replies

5. Solaris

export DISPLAY

rsh to host2 from host1 and from host2 rsh into host3 Is it possible to display a GUI from host3 through host2 and onto host1? (1 Reply)
Discussion started by: eddiet
1 Replies

6. Shell Programming and Scripting

About export

Hi all, I am calling a script from main script. The called script (second script) have to return some value, i can use exit to pass but in exit i have to pass some other value. i used "export Var", but this command resides in a function of second script. could you please tell me how to... (3 Replies)
Discussion started by: Arunprasad
3 Replies

7. BSD

How to export

Hi I need to export some directpry path like below: var1=/<>/<>/<> export var1 This is my basic idea. I tried export var1=/<>/<>/<> after executing this in a shell i did an echo of the var1. But nothing happened. Can you please help me with this. I need to srite a script to... (4 Replies)
Discussion started by: jisha
4 Replies

8. Shell Programming and Scripting

export???

I am trying to export the variable OBJ2 and set it to done. Can some one please let me how to do this? I have tried editing my .bashrc file with this echo <VARIABLE_NAME>=<"OBJ2"> But that wont seem to work... (1 Reply)
Discussion started by: Justinkase
1 Replies

9. UNIX for Dummies Questions & Answers

Mount Export

Apologies first -- I am a complete AIX moron but I have to figure this out to get our new system online. I am a programmer, not a sysad, but our AIX/UNIX admin is in the hospital. Apologies first -- I am a complete AIX moron but I have to figure this out to get our new system online. I am a... (1 Reply)
Discussion started by: AIXdumb455
1 Replies

10. Shell Programming and Scripting

confusion with export

Hi, I have written the following two scripts. a.ksh ---> FPATH=/users/kushard autoload b b echo "From a.ksh::" $aa b ---> function b { typeset aa aa="TRUE." echo "From b::" $aa export aa } (1 Reply)
Discussion started by: kdipankar
1 Replies
Login or Register to Ask a Question