Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, I have a problem with the linking as explained below. I created a new library mylib.a which uses a function func() present in the already existing library libpcap.a. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    2

    problem with static library linking


    Hi All,

    I have a problem with the linking as explained below.


    I created a new library mylib.a which uses a function func() present in the already existing library libpcap.a.

    When I build mylib.a I did not see any error.

    But when I build mylib.a with an executable I got a linking error of undefined reference to the function func(). Thi error was shown in a file which is present in mylib.a

    On my link line I have tried the following order of linking.

    1. libpcap.a mylib.a
    2. mylib.a libpcap.a

    But I am still having this error.

    Could you please help me out.

    Regards
    -Harish

  2. #2
    Just Joined!
    Join Date
    Mar 2008
    Posts
    2

    Smile Re:problem with static library linking

    I have resolved the error.

    The reason is the way I was including the header file.

    The function func() present in the file ipv6hdrs.h( definition in ipv6hdrs.c) and in the library libpcap.a

    In the library mylib.a and in the file test.cc I included ipv6hdrs.h as below

    #include "ipv6hdrs.h"


    Later I noticed that the definition of func() is present in the .c file rather than .cc file.

    So I changed the header file inclusion to

    extern C
    {
    #include "ipv6hdrs.h"
    }

    and it worked. I could build my executable properly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •