How to know linked Files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rayuthar@gmail.com

    How to know linked Files

    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
  • suresh shenoy

    #2
    Re: How to know linked Files

    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

    Comment

    • Eric Sosman

      #3
      Re: How to know linked Files

      rayuthar@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
      esosman@ieee-dot-org.invalid

      Comment

      • rayuthar@gmail.com

        #4
        Re: How to know linked Files

        On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrot e:
        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.

        Comment

        • rayuthar@gmail.com

          #5
          Re: How to know linked Files

          On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrot e:
          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,

          Comment

          • Eric Sosman

            #6
            Re: How to know linked Files

            rayuthar@gmail. com wrote:
            On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrot e:
            >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.

            --
            Eric.Sosman@sun .com

            Comment

            • lithiumcat@gmail.com

              #7
              Re: How to know linked Files

              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).

              Comment

              • Kenneth Brody

                #8
                Re: How to know linked Files

                rayuthar@gmail. com wrote:
                >
                On Apr 23, 5:50 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrot e:
                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:ThisIsA SpamTrap@gmail. com>


                Comment

                • Ben Bacarisse

                  #9
                  Re: How to know linked Files

                  Kenneth Brody <kenbrody@spamc op.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.

                  Comment

                  • soscpd

                    #10
                    Re: How to know linked Files

                    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

                    Comment

                    • Gordon Burditt

                      #11
                      Re: How to know linked Files

                      >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).


                      Comment

                      Working...