LNK4221 and LNK4006 warnings!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khumayun
    New Member
    • Jan 2010
    • 11

    LNK4221 and LNK4006 warnings!

    Hi, I basically making a static library of my own. I have taken my code which works and now put it into a static library for another program to use. In my library I am using another static library which I don't want the people who will be using my API to know. Since, I want to hide that information from them I can't tell them to install the other static library. Anyway, I used the command line Lib.exe to extract and create a smaller lib file of just the obj's I used. However, I get a bunch of "LNK4006 :second definition ignored" linker warnings for each obj I use followed by "LNK4221 no public symbols found;archive member will be inaccessible".

    I am doing this work in vs2008 and I am not sure what I am doing wrong. I am using the #pragma comment line in my .cpp file I have also modified the librarian to add my smaller .lib along with its location. my code simply makes calls to a couple functions which it should be able to get from those Obj file in the smaller lib. All my functions are implemented in .cpp file and my header just have the includes of the third party header files and come standard c++ header files. nothing fancy. I have actually no function definitions in there atm. I was going to put the API definition in there and implement that in the .cpp for this static lib that i was going to make. However, I just wanted to build my code before I added more to it. s

    Any help would be appreciated. is this a vs2008 configuration issue? or a program issue I am not sure.

    thanks for the help!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Just put everything on one static library.

    Let's assume this is the header generated by your static library project:

    Code:
    //MyLib.h
    
    int Public( int, int);   
    int Private(int, int);
    When you publish your library for users, just modify the header for the user:

    Code:
    //MyLib.h
    
    int Public( int, int);
    Your users cannot call the Private function. But you can by using the other header (the real one) in your projects.

    Alternatively, you could use a DLL and not export the Private function.

    Comment

    • khumayun
      New Member
      • Jan 2010
      • 11

      #3
      atm this is what i have in vs2008

      My solutions looks like
      mylib.h (containts all function definitions minus the api that I have yet to offer)
      mylib.cpp (contains the imp of everything).
      a static lib of two obj files that my internal functions rely on.

      You are saying:
      mylib.h (just the client api)
      mylib.cpp (have all implementation)
      a static lib that my internal implementation relies on.

      the question is how does the static lib know what is public and what is private.
      FYI i did nto really use classes. just functions and their implementations . So there is no public/private necessarily.

      I mean I have one function that I have implemented which relies on these obj files in the header file and still it complains. does that really make any sense?
      not sure. maybe i am just confused beyond hope here. But i have never worked with static files before and this is my first time.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        I think you are making this too hard.

        Here is a library that contains two books:

        C Made Simple
        Tales by Edgar Allen Poe.

        If you see a catalog listing of what is in the library that says:

        C Made Simple

        then what leads you to believe there are other books in the library? That is, of you are told the library only contains C Made Simple then how can you possibly know to ask for Tales by Edgar Allen Poe?

        So, go ahead and make your static library and put 100 functions in there. Then add that library to the user project and use a header for that library that contains the names of only 3 functions. You will find that only those 3 functions can be called by the user.

        You will also find the code in the library can call all 100 functions. There is no "public/private" concept in a library.

        The functions you present to the user is the library API. There is no requirement to tell the user everything.

        Comment

        Working...