none
warning LNK4221: no public symbols found with VS2005 but not with VS2003 RRS feed

  • Question

  • Hi,

    I get this warning

    yywcsskp.obj : warning LNK4221: no public symbols found; archive member will be inaccessible

    when I compile a static library with VS2005.  But the same project with VS2003 doesn't give this warning.

    So, this warning seem to cause me problem when I want to link an application with this library.  I got some unresolved external symbol like this

    my_lexer.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall yl::yywlexer::yyerror(unsigned short const *)" (?yyerror@yywlexer@yl@@UAEXPBG@Z)

    Can somebody help me ?

    Eric

    Monday, October 23, 2006 3:26 PM

Answers

  • That warning means exactly what it says. No public symbols are found in yywcsskp.obj, so it will not be accessible through the library. You will get this message if your library project has got a translation unit (usually a .c or .cpp file) with no non-static symbols defined at file or namespace scope.

    The linker error you get in the other project means that the sumbol yl:yywlexer::yyerror isn't found in any of the libraries to which you link. Determine which library this resides in, and confirm that it is not declared with static storage type, then link to this library.

    Also be sure to clean and rebuild all parts of the project that has been previously built with VS2003.

    Monday, October 23, 2006 8:50 PM
    Moderator

All replies

  • That warning means exactly what it says. No public symbols are found in yywcsskp.obj, so it will not be accessible through the library. You will get this message if your library project has got a translation unit (usually a .c or .cpp file) with no non-static symbols defined at file or namespace scope.

    The linker error you get in the other project means that the sumbol yl:yywlexer::yyerror isn't found in any of the libraries to which you link. Determine which library this resides in, and confirm that it is not declared with static storage type, then link to this library.

    Also be sure to clean and rebuild all parts of the project that has been previously built with VS2003.

    Monday, October 23, 2006 8:50 PM
    Moderator
  • I found that you need to add at least one public function that is not inline to each class.
    If you have classes with only public inline functions then you also get this warning.

    I did not experience this on C++ 6.0. At the moment I am moving software to VS C++ 2008 and get
    this warning.
    Saturday, July 12, 2008 9:58 AM
  • Inline functions are only emitted in the object file when they are used (in C++ at least).

    If you have:

    // a.cpp
    inline void foo(){}

    // b.cpp
    inline void foo();
    int main() { foo(); }

    You should get a linker error because foo is not defined. Same problem for the .lib. Your object file does not have any public interface. The linker only ever lifts object files from a static library when a reference to a public symbol of that object file is seen and not yet satisified by another object file. If there are no publics, the object file will never be selected. That's what the warning is trying to tell you ...

    -hg
    Visual C++ Libraries Team
    Saturday, July 12, 2008 5:04 PM
  • Hi all,

    I was wondering: how to get rid of this "warning LNK4221" and get the content of an object file added into the library if its associated compilation unit contains no public symbol but contains some static data and/or inline functions ?

    In clear:

    // MyClass.h 
    class MyClass 
      MyClass(){ ... } 
      ~MyClass(){ ... } 
      void SomeFunction(){ ... do something here ... } 
    }; 
     
    // MyClass.cpp 
    #include "MyClass.h" 
    // nothing here because everything is defined inline in the header 

    So, how to get a lib file out of this?

    Thanks in advance
    Tuesday, December 23, 2008 6:19 PM
  • Are you using Flex? Is so, then are you using the latest version? There is also something called Flex++ but I don't know anything about it. I know there are forums and/or mailing lists and your errors seem to be something that others have already encountered and fixed, or perhaps there is a different way for Flex to be used. If you are not using Flex then you are probably using a commercial version of Lex; can the vendor help?
    Sam Hobbs; see my SimpleSamples.Info
    Wednesday, December 24, 2008 10:08 AM
  • Hi,

    No no, I'm neither using Flex nor Lex. I switched from Visual C++ 6 to Visual C++ 2005 Express, and got this warning about some library files that contain no public symbols, only constants and/or inline definitions. (Hence my post in this topic.)

    I removed the "inline" keyword and then everything was fine.

    Then my question: how to create a compilation unit with only inlines in it?

    Thanks anyway for replying.
    Thursday, December 25, 2008 4:39 PM
  • I deleted my previous reply.

    I think however that the code was generated by a lexical code generator such as Flex or Lex. If it was, then it will likely be easier to modify the code and/or convert it if you obtained the latest version of the generator and used it with your application's input to the generator to create a newer version of your appliation's lexical scanner code.

    Sam Hobbs; see my SimpleSamples.Info
    Thursday, December 25, 2008 8:52 PM