By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

How to know linked Files

P: n/a
Hi,

I have two files A.c and B.c , i can make executable with A.c alone or
addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?

Thanks,
Rayuthar
Jun 27 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Apr 23, 8:23*am, rayut...@gmail.com wrote:
Hi,

I have two files A.c and B.c , i can make executable with A.c alone or
addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?

Thanks,
Rayuthar
You could may be enable trace on when you compile to see if the files
are compiled and linked.

Suresh M. Shenoy
Jun 27 '08 #2

P: n/a
ra******@gmail.com wrote:
Hi,

I have two files A.c and B.c , i can make executable with A.c alone or
addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?
What difference would it make? Since A uses nothing that
is defined in B (if it did, you could not make an executable
from A alone), anything B contributes is inaccessible.

What is the larger problem you are trying to solve?

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jun 27 '08 #3

P: n/a
On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
rayut...@gmail.com wrote:
Hi,
I have two files A.c and B.c , i can make executable with A.c alone or
addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?

What difference would it make? Since A uses nothing that
is defined in B (if it did, you could not make an executable
from A alone), anything B contributes is inaccessible.

What is the larger problem you are trying to solve?

--
Eric Sosman
esos...@ieee-dot-org.invalid
I want to check if A is linked with B or not, if linked i will use the
function from B else i will go for any other way.
Jun 27 '08 #4

P: n/a
On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
rayut...@gmail.com wrote:
Hi,
I have two files A.c and B.c , i can make executable with A.c alone or
addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?

What difference would it make? Since A uses nothing that
is defined in B (if it did, you could not make an executable
from A alone), anything B contributes is inaccessible.

What is the larger problem you are trying to solve?

--
Eric Sosman
esos...@ieee-dot-org.invalid
sorry if posted twice!

If B is linked, then i will use the function from B else i will go for
my own function.

Thanks,
Jun 27 '08 #5

P: n/a
ra******@gmail.com wrote:
On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>rayut...@gmail.com wrote:
>>Hi,
I have two files A.c and B.c , i can make executable with A.c alone or
addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?
What difference would it make? Since A uses nothing that
is defined in B (if it did, you could not make an executable
from A alone), anything B contributes is inaccessible.

What is the larger problem you are trying to solve?

I want to check if A is linked with B or not, if linked i will use the
function from B else i will go for any other way.
The C language cannot do this[*], because "stand-alone A"
cannot refer to anything in B. Therefore if A itself does
not change when B is added, the "partnered A" still has no
reference to anything in B and cannot call anything in B.
Even if something in A manages to discover that B is present,
it still has no way to call functions that are in B.

"C with extensions" is able to do this kind of thing on
some systems, using system-dependent mechanisms that are not
part of the C language itself. Try asking your question on
newsgroups that discuss the systems you're interested in.
[*] Perhaps an interpreted C implementation could do it,
but since the O.P. talks about "linking" files I think we
can ignore the possibility.

--
Er*********@sun.com

Jun 27 '08 #6

P: n/a
On Apr 23, 3:01 pm, rayut...@gmail.com wrote:
If B is linked, then i will use the function from B else i will go for
my own function.
I was in the same situation a while back, and I haven't found anything
better than checking whether a symbol from B is present or not in the
program using dlopen/dlsym with a NULL filename.

It's not standard C (it's POSIX), and it seems to be a very heavy tool
for that purpose, so I would be glad to hear of a better solution (if
such a solution exists).
Jun 27 '08 #7

P: n/a
ra******@gmail.com wrote:
>
On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
rayut...@gmail.com wrote:
Hi,
I have two files A.c and B.c , i can make executable with A.c alone or
addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?
What difference would it make? Since A uses nothing that
is defined in B (if it did, you could not make an executable
from A alone), anything B contributes is inaccessible.

What is the larger problem you are trying to solve?

I want to check if A is linked with B or not, if linked i will use the
function from B else i will go for any other way.
Basically, you want to determine, at runtime, if a function of a
given name existed at link time?

As others have pointed out, you can't do this in anything resembling
portable code. There may be a system-specific way of doing this,
but you would have to check in a system-specific group for such info.

What I would recommend is a slight variation on your request. Rather
than linking with B or nothing, link with B or "alternate B", and
have both include a _pointer_ to the function, with "alternate B"
having a NULL pointer.[*] Have your A code check for a non-NULL
pointer, and call the function indirectly. As an alternative to
this method of explicitly linking with "alternate B", you may be
able to supply a library which is always linked with the code. If
you link with B, the pointer symbol will be resolved, and your
"alternate B" module from the library shouldn't be included. If
you link without B, your library module with the NULL pointer
should be linked it.

[*] Technically, I don't think a code pointer can be NULL, as a
code pointer may not be represented the same as a data pointer.
(Though I have to admit that I use such a construct in my code.)
You could always make your own definition for a null code
pointer, such as:

typedef int (*IntFunc)();
#define NULL_INT_FUNC ((IntFunc)0)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Jun 27 '08 #8

P: n/a
Kenneth Brody <ke******@spamcop.netwrites:
<snip>
[*] Technically, I don't think a code pointer can be NULL, as a
code pointer may not be represented the same as a data pointer.
(Though I have to admit that I use such a construct in my code.)
You are in the clear. Function pointers can be assigned NULL and can
be compared against NULL (specifically against any null pointer
constant).

--
Ben.
Jun 27 '08 #9

P: n/a
Hi List

Can't that work like:

#ifdef whatever_in_b.c

/*call here the function/variable in b.c, set the return value to
local scope variable*/

#elif

/*use a standard value*/

#endif

Still can't see the point in do that (since it's very easy to know, on
compile/link time, if b.c is there or not), but that can work as far
as I can see, anyway. Some headers can be necessary to work with that
"solution".

Regards
Rafael
Jun 27 '08 #10

P: n/a
>I have two files A.c and B.c , i can make executable with A.c alone or
>addition to B.c. If i make executable with two files , how can i know
B.c is linked with A.c?
On some implementations, if A.c needs something in B.c and it's not
linked with B.c or something else that supplies it, the resulting
executable will get an error on the link and won't run (or possibly
the linker won't even create an executable).
Jun 27 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.