Add "compile" option into an application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AlienAdy
    New Member
    • Aug 2010
    • 3

    Add "compile" option into an application

    Hi guys!

    I am coding a free software that will have 2 parts. Part 1. is an admin panel where a user will be able to select some options. Part 2. is a finished new application which a user can send to some other user, so a standalone application that has nothing to do with the admin panel. Now, the problem is, I don't know how to connect those two parts. I want to add an option in the admin panel that says "build" which will create a file with the native c/c++ code and then compile it into an .exe as a final product. Something like a chicken that lays an egg, if you know what I mean. Well, the egg will be the .exe file in my case. The problem is, how can I make the chicken to lay an egg an not a smelly, black thing that he lays every few hours? :)

    The admin panel will be in .NET technology (C# or C++) and the .exe file will be in native c/c++ an win32 api code. I know how to write text into a file, so that's not a problem. The problem is, how to implement an auto compiler that will be able to compile that newly written file without any problems and without a user intervention? The newly generated code is 100% correct, because it compiles clean in Visual Studio, so no problem there. And I would like that the compiling of that file would be independent from the users configuration. I mean, they will still have to have windows and .net installed, but I don't want to make them to install platform sdk and .net sdk.


    I AM NOT LOOKING FOR A CODE ABOUT THIS. - This is for those who skim the text so they can see that I am not looking for a code solution. What I need is some guidelines to how to do it.
    First, I was thinking about packing the whole VC++ compiler into my application and then to start it in the background with console commands to the cl.exe so it can make an .exe. While this idea is accepted in some way, the problem is with packing all the libraries for the win32 api dll's and then all the files cl.exe is dependent from. I am affraid that it will take away a lot of MB's, since the win32 api dll's are a few MB's already, and I don't know if I can redistribute cl.exe and all the other libraries for free.
    The second option was the C++ redistributable package. The problem is, I never worked with it, and I don't know if it supports compiling and how. Though, I have a few versions of the c++ redistributable package already installed on my system from different games and applications. If you worked with this package and if you think that that's the right solution, speak up and save me from my misery. :)
    I was also looking at some free compilers, namely, borland c++, but it is ~7MB, and I don't know if I need to pack all the 7MB into my application or not, and if I do, then how should I use it?

    So, as you see, I am on a road toward something, but I think I am lost and I need somebody to give me a clue which way to go now.


    Can anybody help me??? :)
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    I think I need some clarification on exactly what the logical relationship between your control panel and your application is.

    Does the control panel write the configuration used by the executable? Or does the control panel generate the executable based on some kind of configuration?

    In the case of the latter, I would imagine that the control panel would be in the first sense modifying some cs or cpp files (depending on the project type) and modifying an app.config for values that can be modified by the customer. It could then push the generated project through the compiler to produce the executable which could then be shipped along with the modified app.config.

    In the case of the former, you're just generating an app.config which can be shipped with a prebuilt executable.

    Or am I missing your point?

    Comment

    • AlienAdy
      New Member
      • Aug 2010
      • 3

      #3
      Actually, the idea was that a control panel writes a custom cpp or cs file from beginning to end, and then pushes that file through a compiler to produce an .exe file which a user can ship to whoever he wants. Just the way as the code editors works ... I think. :)

      With app.config, you have to ship two files, the app.config and the .exe ... or am I wrong about this, because I didn't used app.config yet, but I saw that it's an xml page which holds properties of different things. And with an app.config file, won't a user be able to manually edit it and get new things without even starting up the admin panel? Or can I include that file in my executable without any compilation from a user side and take it out if I need to change it? Because if that's possible, than my problem is solved :) But I think it's not that ease. :)

      By the way, thank you for replying, balabaster! And what are you doing in the coding community? You should be working as a fortune teller, because your guessing skills are very good! I mean, you guessed right away what my problem is even though you were not sure. :)

      Comment

      • Joseph Martell
        Recognized Expert New Member
        • Jan 2010
        • 198

        #4
        You can use a CSharpCodeProvi der class to give you the facilities to compile a source file a runtime. MSDN has a pretty good example of how to use it here.

        I'm not sure on the legality of distributing what is essentially the VS C# compiler though. I would heavily investigate that if I were you.

        Comment

        • balabaster
          Recognized Expert Contributor
          • Mar 2007
          • 798

          #5
          Okay, I have two thoughts about this:

          1). If features of your application are going to be enabled/disabled via the app.config then you should look at encryption routines for the app.config. I've not used them, but there's plenty of documentation regarding this. You can encrypt sections of your app.config and your executable can still read the section without anyone else being able to.

          2). You could only write the features the user should be able to access to the cs/cpp files pre compile. Your control panel could fire up a background process which uses csc.exe (The csharp compiler) to compile the code that was generated. The app.config can then be reserved strictly for user modifyable settings and you don't even have to include non-configurable application settings in the app.config but generate them as part of the control panel process into the cs/cpp files directly prior to execution.

          My initial instinct might be to go with option 1, your user won't be able to modify these settings, but there's more potential they could completely break your application causing unnecessary support calls which could cost you in other ways. Consequently, I think you'd be safer to go with option 2.

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            @jbm1313

            I'm not sure he's suggesting distributing the csharp compiler. He implied the control panel that generates the executable for each of the clients is something that only he uses, only the resulting executable and configuration file would be distributed. Unless I misinterpreted.

            Comment

            • Joseph Martell
              Recognized Expert New Member
              • Jan 2010
              • 198

              #7
              There are a few lines in the question that suggest that the users are to compile programs for themselves:

              "Part 1. is an admin panel where a user will be able to select some options. "

              "...and I don't know if I can redistribute cl.exe and all the other libraries for free."

              I may be drawing the wrong conclusion though.

              What about it AlienAdy? Are you trying to create a distributable program that compiles new programs in the field, or is Part 1 going to reside on your machine alone? To extend your analogy, are you going to sell the chicken, or just the eggs?

              Comment

              • AlienAdy
                New Member
                • Aug 2010
                • 3

                #8
                jbm1313, I am going to sell the chicken which will lay eggs to the user who has the chicken, and he can then give the eggs to somebody else :) - just to follow up my analogy

                jbm1313, if that CSharpCodeProvi der really compiles a pure .cs file and the only thing he needs is a System.dll which is available on every windows computer or I think that .dll is already packed with the compiled application ... in that case, my problem is solved the way I imagined. :) Well, according to MSDN article, it does looks like a magic stick that turns every .cs file into an .exe file. I don't know if it can actually put other files in that .exe as a VS compiler would do, but that would only be a flavor on a cake, because I already have what I need.

                Well ... not exactly ... because I need to compile a .cpp code to .exe. I am sorry for not telling you this before. Is there something out there that can do the job? Honestly, I am killing myself coding in c++.net because the VS support for that language is very bad. Not to mention the code page it generates ... I would rather code in c#, but I can't do it now, because I need to do a project in c++. And the cpp file that a compiler will need to turn to .exe is not c++.net but native c++ windows application.

                About cl.exe: Yes, I wanted to distribute the whole package with all the libraries. I thought that it would be a bad idea because it's not free, but my next candidate is a 7MB big Borland c++ compiler, if somebody won't help me and suggest a lot smaller thing that can solve my problem.

                balabaster, thank you for the good tips about the app.config! It is one of my options, if nothing else works out. I don't know if c++ native code have a support for config files, but even without that, I can create a "config" file with the basic i/o stuff, and I can even encrypt it and then uncrypt it in the application and use the data. And of course, a separate fresh copy of the config file will be in the .exe in case a user "accidental ly" deletes the config file and can't start a software.
                BUT ... the above option is the last solution in the solution tree. For now, I will wait and maybe some easier solution comes up.

                THANK YOU ALL FOR HELPING ME!!! Since all of you guys are giving me so much new and good information, I am afraid that I can't choose the best answer, because all the answers so far are good in one way or another. I hope this won't stop you from helping me.

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  I am pretty sure if you have the .NET framework you have the "compiler" you need.
                  The WMICodeCreater software works in this way. You pick a bunch of options and it shows you all the code that it is going to compile and run

                  Comment

                  Working...