Is there a way to make a module for an app without it being a .dll or .so file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hero Doug
    New Member
    • Nov 2006
    • 16

    Is there a way to make a module for an app without it being a .dll or .so file?

    I was wondering (besided using PHP ;) what in C++ could provide similar functionality to PHP's include();

    In PHP you canjust type include() almost anywhere and that file will be included dynamically. It's nice because you can check if it needs to be included on a file by file basis, which is nice because it keeps things compact.

    Right now the only similar solution I see in C++ is the #include directive, however that includes the file no matter what, even if it's not needed.

    I want to make a modular application, however I don't want to have to do excessive compiling to develop the said module. My goal is to develop the environment, then develop the modules seperately and toss them in a module folder when done.

    Is there a generic way to do this without going into Dynamic Link Libraries or .so files?

    Thanks.
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    PHP and C++ function differently. They have different approach to compiling code. Both share something called include, but they are very different. PHP’s include puts together code. So does the preprocessor include, but you don’t use the include to put together source files.

    #include directive, however that includes the file no matter what, even if it’s not needed.
    Hence the use of header guards to prevent multiple inclusion.

    I want to make a modular application, however I don’t want to have to do excessive compiling to develop the said module.
    The word “module” doesn’t mean anything specific. You should describe exactly what you envision for your program.

    “Develop the environment” doesn’t mean anything. “develop the modules” doesn’t mean anything either. We need specifics from you.

    Comment

    • Hero Doug
      New Member
      • Nov 2006
      • 16

      #3
      I guess that may have been a bit vague, sorry.

      For an environment I mean that I want one main controller to set up all environment variables and permissions, then handle the actual request being made (maybe it's writing a file). When the environment starts up I want it to scan a list of modules, and if the module is enabled, I want it to be loaded, otherwise, I don't want it (the module) taking up memory.

      For a module, I mean a pre-compiled binary file that I (or anyone) can just toss in a folder and begin to use it's functionality (should it be enabled).

      I suppose you can think it in terms of Firefox. The browser setups everything for the module, and the module extends the functionality.

      I'm just wondering if there's a way to acomplish this without using .dll or .so files.

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        I’m just wondering if there’s a way to acomplish this without using .dll or .so files.
        Sure, you could zip up the module, rename the module extension to something else, and then put that in the folder. Look at Firefox’s module format. The xpi is a zip file.

        I’m not sure why you are objecting to dll files. The module has to be some kind of file. If it turns out that you need a native binary file, that isn’t an executable itself, then a dll may be your best option. Or maybe it’s a more complex file format, like the xpi extension, that can have a dll zipped inside of it.

        If you have a binary that is made in C or C++, it compiles to either an executable or a library. I presume this is what you intend, the module writers create the module with C. Then you must have a DLL as a result. Consider the idea of zipping or renaming the file extension (or even, dropping the extension).

        Comment

        • Hero Doug
          New Member
          • Nov 2006
          • 16

          #5
          The objection to using .dll or .so files is that they have be linked to the application in order to be able to use them? I'm basing this off the fact thta when you want to install a PHP module you have to recompile PHP with -enable <modulename>

          When building this application I obvisouly won't know what other modules developers will make and won't be able to hardcode the inclusion, so it'll have to be dynamic.

          I'll probably have it tested by the time you reply, but what about some procedural code in gloabl scope (or better, within the module controller object) that scans a config file and looks in the module folder and then includes the enabled modules (essentially pre-compiled libraries).

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by Hero Doug
            The objection to using .dll or .so files is that they have be linked to the application in order to be able to use them?
            No they don't, as long as the dll uses a defined interface that the application knows then the dll can be linked at run time calling the WIN32 API function LoadLibrary.

            Comment

            • Hero Doug
              New Member
              • Nov 2006
              • 16

              #7
              Alright, I think I'm on the right path now.

              I should be able to look at the environment variables to tell what operating system it is, then call the approproiate system API to dynamically link the library into the address space.

              I found a resource (here that brings up an interesting point that different compilers and even different compiler versions may not be able to compile compatible libraries becaue their vtable may not match (mentioned on page 2 paragraph 4). Is there any truth to that?

              Comment

              • oler1s
                Recognized Expert Contributor
                • Aug 2007
                • 671

                #8
                I should be able to look at the environment variables to tell what operating system it is,
                You won’t need to though. If you have a windows binary, it won’t be running on a linux or a mac :)

                ...different compilers and even different compiler versions may not be able to compile compatible libraries...Is there any truth to that?
                Very true. On example that annoys me: Python is built with Visual C++ 2003, and any third party extension modules must be built with same compiler version. Or I have to rebuild Python in another version, and then all the modules in that version.

                It’s not so simple as black and white. If you keep reading about dlls, you should find information on compatibility issues, and how to deal with them.

                Comment

                • Hero Doug
                  New Member
                  • Nov 2006
                  • 16

                  #9
                  I was thinking of checking the environment variable so I wouldn't have to do any modification to the code.

                  I think I've gathered enough info to continue looking. I'll definately have to round up multiple compilers to develop a loader class, but I don't think it's going to have me too stressed out, in the end it (being able to load modules on demand without causing developer headaches) should be fairly generic which is what I want.

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Originally posted by Hero Doug
                    I was thinking of checking the environment variable so I wouldn't have to do any modification to the code.
                    Use compiler preprocessor symbols and conditional statements to conditionally compile the correct code for the platform.

                    The platform is set at compile time, to leave platform based decisions until run time is poor practice in my view.

                    Comment

                    • Hero Doug
                      New Member
                      • Nov 2006
                      • 16

                      #11
                      Yeah that's quite logical and makes sence, thanks for the tip.

                      Comment

                      Working...