CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    68

    Compiling from source

    Hello,

    I have a fairly basic question about compiling libraries. Suppose that I want to use an open-source library that has been written by somebody else. Typically, when I go to the website to download it, then instead of being provided with the library files themselves, I am provided with the source files, with instructions on how to compile it myself.

    Why is this? Why can't the author just provide me with the library files and header files, so I can just plug them straight into my project? I understand that having a look at the source files themselves is nice, but is this the only reason?

    If I am building a project in Visual Studio, then why am I told to compile the code using that compiler, rather than another one? Surely the executable at the end will be the same as on another compiler, because the code is the same?

    Also, typically, there are different source files for Windows and Linux. I understand that some functions may use the operating system API, but for a lot of projects, only the standard C++ library is used. Hence, can't the same source files be used for both operating systems?

    I know this is probably basic stuff, but I could do with getting it straight before I move on!

    Thanks.

  2. #2
    Join Date
    Aug 2008
    Posts
    902

    Re: Compiling from source

    It's partially the open source mentality (distribute source, not binaries) and partially due to the fact that they would prefer not to have to go through the trouble of maintaining binaries. Not everyone uses Windows and Visual Studio. There are dozens of common operating systems and compilers, each combination of which may require a binary compiled specifically for it. That's a huge and unnecessary burden on them.

    Also, typically, there are different source files for Windows and Linux. I understand that some functions may use the operating system API, but for a lot of projects, only the standard C++ library is used. Hence, can't the same source files be used for both operating systems?
    No, there are lots of things that the C++ Standard Library can't do. Lots. Even then, say you are using an fstream. That's part of the library, but Windows and Linux have different file structures, so your code is going to be different anyway.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Compiling from source

    Yeah, it's a heck of a lot easier to push a source folder onto sourceforge than to provide binaries for Windows gcc, Windown VC++, Redhat, Debian, Solaris, MacOSX...

    Besides, lots of libraries have compiler or environment specific code in them to make them run smoother for you. Also, most of the time, you want to be able to debug the library if something goes wrong and a production binary will not include debugging symbols.

  4. #4
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Compiling from source

    Quote Originally Posted by karnavor View Post
    ...Surely the executable at the end will be the same as on another compiler, because the code is the same?
    I don't know if that is true (doubt it), but it obviously isn't "surely".
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

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