CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Jul 2012
    Posts
    13

    Re: Making static library with MinGW

    Paul, that code was made by the creator, not by me. The thing is, that function adds the method to some static list of compression methods elsewere, and that list is used... This static variable, however, is not.
    Does the compiler remove code even without any optimizing option?
    By the way, all works fine on the dll with the same source. Is something different for a dynamic library on this regard?

    Thank you for your help.

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Making static library with MinGW

    Quote Originally Posted by Tex Killer View Post
    Paul, that code was made by the creator, not by me.
    So now it's time for you to fix the code so that it works. I mentioned this to you already -- possibly the code as structured will not work correctly if it's a DLL and you have to go in and fix it.
    The thing is, that function adds the method to some static list of compression methods elsewere, and that list is used...This static variable, however, is not.
    So now in the first line of your main() program, you call these functions, or create your own Init() function that gets called right when main() starts. The fix couldn't be more simpler than that, no? Because of the variable not being used , the linker may have thrown it away. Anyway, that routine should have been written in an Init() method, so that these surprises do not happen.

    You are not to think of this as a static library and your code -- it's all your code now that will be used to create a single program. The static library is just a convenient way to take .o (or .obj) files and place them in a single file. Thinking of the static library as something separate and apart from the code you wrote is the wrong way to go about this.

    A DLL is a different story -- you are working with two separate and completely different modules, one running independent of the other. The only thing holding your executable and the DLL together is that the DLL is loaded in the same address space as your program. So in this case, it is perfectly valid to think of the DLL as separate from your code, because it is separate. A DLL has it's own module handle, global variables, initialization routine and entry point (DllMain() as opposed to main() ), etc.
    Does the compiler remove code even without any optimizing option?
    If the variable is not used, the linker has the option to remove it. It's the linker that is in play here, not the compiler. A static variable declared in a compilation unit will be removed if it isn't used. I don't know if functions with side-effects that are called are considered as reasons to keep the static variable around. So again, remove all doubt and call these functions yourself. The entry point for the program is now main(), and this is where you initialize your data structures if you need to.
    By the way, all works fine on the dll with the same source. Is something different for a dynamic library on this regard?
    Read above.

    Regards,

    Paul McKenzie

  3. #18
    Join Date
    Jul 2012
    Posts
    13

    Re: Making static library with MinGW

    Well, I was now able to add three methods myself (which allowed me to open an .arc file, but only one with uncompressed data), by pasting their signatures into my code and calling the AddCompressionMethod function to register them... But all the others (about 10) gave me "undefined reference", even though their compiled files are inside the .a file.

    If I open the .a file on some text editor I can see the names of the files and functions that are not being found by the linker, so they are there. What could be causing the linker to ignore part of the .a file content?

    Thank you very much.

  4. #19
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Making static library with MinGW

    Quote Originally Posted by Tex Killer View Post
    Well, I was now able to add three methods myself (which allowed me to open an .arc file, but only one with uncompressed data), by pasting their signatures into my code and calling the AddCompressionMethod function to register them... But all the others (about 10) gave me "undefined reference", even though their compiled files are inside the .a file.
    Let's make this simple -- forget about creating a static library. Instead, take the source code, add each source to your project, compile, link, and run.

    Once you get that to work correctly, then and only then should you be thinking about static libraries. At that point, it is just a matter of using the command-line "static library builder" (not sure which executable creates static libraries) and feed it all of the relevant .o files you created.

    Regards,

    Paul McKenzie

Page 2 of 2 FirstFirst 12

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured