473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

dynamic linking

I have a main program and an add-on module
that uses some functionality in the main program.
E.g., the main program main.c has function foo().
The add-on module in file addon.c calls foo().
I want to compile addon.c into libaddon.so (aka addon.dll) so that it
can later be loaded into a running main program if necessary.

When I try to do that, I get this error:

$ gcc -fPIC -Wl,-export-dynamic -shared -o addon.dll addon.o
addon.o:addon.c(.text+0x???): undefined reference to `_foo'

what am I doing wrong?

--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.iris.org.il> <http://www.memri.org/>
<http://www.openvotingconsortium.org/> <http://ffii.org/>
Are you smart enough to use Lisp?
Nov 15 '05 #1
5 1675
"Sam Steingold" <sd*@gnu.org> wrote in message news:uw***********@gnu.org...
I have a main program and an add-on module
that uses some functionality in the main program.
E.g., the main program main.c has function foo().
The add-on module in file addon.c calls foo().
I want to compile addon.c into libaddon.so (aka addon.dll) so that it
can later be loaded into a running main program if necessary.

When I try to do that, I get this error:

$ gcc -fPIC -Wl,-export-dynamic -shared -o addon.dll addon.o
addon.o:addon.c(.text+0x???): undefined reference to `_foo'

what am I doing wrong?


Probably the shared library needs all symbols to be resolved. At any rate,
this is implementation specific and therefore is kind of OT in this group,
which is meant to deal with what's prescribed by the ISO/IEC/ANSI/whatever C
standard.

Instead of requiring that foo function to be available externally, you may
use a callback mechanism: main() calls some function of the library with a
parameter -- address of the foo function. The library then uses this
function indirectly, by function pointer.

Alex
Nov 15 '05 #2
Hi...

I am beginner in Programming .
Can any one tell , me.
How to do dynamic linking for following example...

function main(); writing a file i.e a new function ...foo();
this function foo(); needed to link with the main() function itself in
Run time...

Thanks,

W. Ram

Nov 15 '05 #3
> * Alexei A. Frounze <ny*****@pung.eh> [2005-09-16 00:39:16 +0400]:

"Sam Steingold" <sd*@gnu.org> wrote in message news:uw***********@gnu.org...
I have a main program and an add-on module
that uses some functionality in the main program.
E.g., the main program main.c has function foo().
The add-on module in file addon.c calls foo().
I want to compile addon.c into libaddon.so (aka addon.dll) so that it
can later be loaded into a running main program if necessary.

When I try to do that, I get this error:

$ gcc -fPIC -Wl,-export-dynamic -shared -o addon.dll addon.o
addon.o:addon.c(.text+0x???): undefined reference to `_foo'

what am I doing wrong?
Probably the shared library needs all symbols to be resolved.


can this resolution be postponed until dlopen?
At any rate, this is implementation specific and therefore is kind of
OT in this group, which is meant to deal with what's prescribed by the
ISO/IEC/ANSI/whatever C standard.
could you please suggest the right group?
Instead of requiring that foo function to be available externally, you
may use a callback mechanism: main() calls some function of the
library with a parameter -- address of the foo function. The library
then uses this function indirectly, by function pointer.


this is not really an option (foo is not the only such function)

--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.palestinefacts.org/> <http://www.mideasttruth.com/>
<http://www.iris.org.il> <http://www.camera.org>
Do not tell me what to do and I will not tell you where to go.
Nov 15 '05 #4
"Sam Steingold" <sd*@gnu.org> wrote in message news:ui***********@gnu.org...
* Alexei A. Frounze <ny*****@pung.eh> [2005-09-16 00:39:16 +0400]:
"Sam Steingold" <sd*@gnu.org> wrote in message
news:uw***********@gnu.org... [snip]
E.g., the main program main.c has function foo().
The add-on module in file addon.c calls foo().
I want to compile addon.c into libaddon.so (aka addon.dll) so that it
can later be loaded into a running main program if necessary.
[snip] Probably the shared library needs all symbols to be resolved.


can this resolution be postponed until dlopen?


Maybe, but I think it is "going against the grain".
At any rate, this is implementation specific and therefore is kind of
OT in this group, which is meant to deal with what's prescribed by the
ISO/IEC/ANSI/whatever C standard.


could you please suggest the right group?


One with a name containing the name of the OS.
Instead of requiring that foo function to be available externally, you
may use a callback mechanism: main() calls some function of the
library with a parameter -- address of the foo function. The library
then uses this function indirectly, by function pointer.


this is not really an option (foo is not the only such function)


So use an array or struct containing function pointers. Or maybe it would
make sense to put foo() etc into another shared library.

Alex
Nov 15 '05 #5
Sam Steingold wrote:
Probably the shared library needs all symbols to be resolved.

can this resolution be postponed until dlopen?


The dlopen() manual explains this issue. The RTLD_NOW flag is what you
need. Check the manual of your linker, usually the whole codebase needs
special options (see --export-dynamic when using GNU ld).
could you please suggest the right group?


Some group specific to the target OS.


Igmar
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff Hagelberg | last post by:
I'm trying to create a python module which can be used by a python interpreter embedded inside a fortran program I have. To do this, I first created python wrappers for all the functions in my...
0
by: Dibyendu Roy | last post by:
Hi All, I build an object called "dblorcle" to connect to oracle database in Sun solaris box. This is built linking with various oracle ".a" (archived, for static linking) files come with standard...
3
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is...
2
by: Paul E Collins | last post by:
I'm considering using the NetSpell spell checking engine in my application. However, NetSpell is licensed under the Lesser GPL, and I want to withhold my application's source code. The licence...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand...
11
by: Sean M. DonCarlos | last post by:
I have an unmanaged Win32 app that looks up the name of a DLL (unknown at compile time) from an external location, loads it with LoadLibrary, and then uses GetProcAddress on three exported...
1
by: zpinhead | last post by:
I am unable to get my downloaded extension from pecl to link up with php properly. seems like the php.so I could not use pear install http. pear claimed the extension was already installed....
1
by: srikar | last post by:
what is the difference between static linking & dynamic linking, what are the advantages of each? How to perform static linking & Dynamic linking by using gcc -o liniking will be done , but...
7
by: Ajinkya | last post by:
I have writen a program for a game called game.exe Now it includes a player part to which has to be a function to be writen by someone else. Now I want to provide this exe to some tester who...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.