?
Solved

Compiling C applications

Posted on 2006-05-19
35
Medium Priority
?
265 Views
Last Modified: 2012-05-05
I want to clarify some details for compiling an executables, for win32 platform, written in "C" (for project specification)
The application will have few parameters configurable(URL specified inside apps, etc). Application have no GUI, it run as service, and have all parameters precompiled inside. Since I need change URL, I need each time recompile program from scratch. Since i am not a programmer, it will cause difficulties, etc.
What is possible ways to change parameters inside a source code and then compile application? Does it possible do an exe compilation use some custom configurator application, which will have GUI input to change URL, etc inside a source code, then from this GUI compile code to exe?(i.e. generate executables with required parameters). Or compilation can be done only via full developer library- standard C compiler application, from scratch?
0
Comment
Question by:Sirocco
  • 16
  • 8
  • 5
  • +3
35 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 16718535
You will need a full compiler yes. The best solution would be to modify the code to take the URL as an external parameter (passed as command line argument, or from a config file eg.) ... you'll never have to re-compile the application when the URL needs to be changed.

Regarding the GUI program you mentioned to make the change and re-compile it for you ... it would take more work to create that than to follow the advice in the previous paragraph.

Some questions for you :

1) do you have any programming experience ? If so : in C ?

2) do you have a C compiler installed on your system ?

3) who created this application ? Can he/she change the code for your to treat the URL as a configurable parameter ?
0
 

Author Comment

by:Sirocco
ID: 16719344
And if necessary to change some other parameters?
However, GUI based configurator(exe generator) would be the best, if code is stable and necessary change some parameters only.

As I said i am not a programmer and have no programming experience (except html and javascript a little). And I have no C compiler installed. Application is't created yet, but it will be created for me, based on my specs. However, I can specify him to apply URL as a configurable parameter.  it's really difficult to find good С coder among them, most of these folks has no abilities, nor a clever.
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16720131
It is difficult if you need to recompile if your parameters change. It is better to have some defaults, but with the possibility to change it using a configuration file or on the commandline.

If you really want to recompile if something changes, it would be the best to create a completely configured vmware image and use that only for this purpose.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Sirocco
ID: 16720214
Two parameters need be changeable: url and email address.
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16720278
then why not use the commandline for that?

c:\path\to\yourprogram.exe http://new.url.com my@email.com

The program can read that from the commandline, the same way like you can start internet explorer with a particular page:
    iexplore http://www.experts-exchange.com/
or notepad to edit a particular file: notepad c:\boot.ini
0
 

Author Comment

by:Sirocco
ID: 16720770
No. Absolutely another thing. As i said, all parameters is preconfigered inside a source code. Need be compiled ready exe with desired url or email inside. Possibly, if use assembly, compiling will be more easy?
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16720795
> all parameters is preconfigered inside a source code.

then create a file called settings.h with just

#define CONFIG_URL "http://url.com/"
#define CONFIG_EMAIL "my@email.com"

This can be included from other parts of the sourcecode. So you only have to change this file, and recompile the program.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16723711
>> Need be compiled ready exe with desired url or email inside.
Any chance you can tell us the reason for that ? Do you want to hide the URL and e-mail address ? If so, then they can be easily extracted from the EXE anyway, unless you apply some kind of encryption. And even then ... information like that is difficult to hide, because it needs to be sent over the internet, which will in general not be encrypted, so any packet sniffer can just find them out.
btw, note that the configuration file can also be encrypted !!

If there's another reason for this ... which is it ?

In any case ... I've got nothing to add to the three already suggested solutions :

1) make them command-line parameters with defaults in the EXE
2) read them from a configuration file with defaults in the EXE
3) compile them into the EXE each time they change (using a header file as suggested by cwwkie eg.)

The last option should only be used if you really need to, as it's a quite cumbersome way of doing things.

In any case ... if you really want this solution, then you can ask the person that is gonna code it for you to also create a configurator gui for you ... Although you will have to have a C compiler installed for it to be practical.
0
 

Author Comment

by:Sirocco
ID: 16725362
>> Need be compiled ready exe with desired url or email inside.
Because it by design. Just design approach. No necessary of any encryption, because no needs to hide the URL/e-mail address, it just need to be inside exe. That's all.

What is free (GPL) C compiler? Does it possible to use custom GUI application which will manage compiler itself? (i.e. this simplified GUI will manage large compiler itself, to make compiling more easy)
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16725648
For the compiler, you can look at http://www.thefreecountry.com/compilers/cpp.shtml.
a GUI application which compiles itself is possible (with some limitations), but it does not make sense.
It is very easy to create a script which will compile the application automatically (for example with a makefile or nant). You can start that with a single click.
0
 

Author Comment

by:Sirocco
ID: 16725775
There are plenty of compilers. Is there some approved C compiler that can be recommended?
I would like know more details about the script to compile the application automatically(and use config file for url with this).
0
 

Author Comment

by:Sirocco
ID: 16733037
No, I meant completely another thing.

I saw some applications(win32, end user application) which allowed to set desired options, user just  consistently select required options for final exe program, then click "create" button and program generate ready application, exe file. And all this does not required installation of any developer environment or compilers. In fact, configuration was done inside a source code.

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16733462
To convert source code to object code (an executable), you need a compiler ... that compiler can be incorporated into the GUI application you are talking about or can be an external compiler. But you DO need one. As I said, let the person that develops the application for you also develop the GUI application you want, and you should be fine.
0
 

Author Comment

by:Sirocco
ID: 16735459
I confirm, that no external compiler used there. Set up was just 300-400KB.
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16736057
It is possible to modify data inside a compiled executable (like a hex editor does). But I think it is a bit too complicated to explain it here.
0
 

Expert Comment

by:vashukumar
ID: 16748428
Move all the configurable parameters into one configurable file and in the program ask them to read the values from that file. This is how configurable parameters are handled

Your configuration file will have enteries like

HOSTNAME=www.abc.com
USERNAME=anon

The program should read the values from that file. This way you need to change and compile your code only once.
Thereafter only the values in the configuration file needs to be changed
0
 
LVL 6

Expert Comment

by:billtouch
ID: 16749702
This is the final version of the Borland C++ compiler released into the public domain. It has been the best compiler for intel based machines bar none. The URL is:

ftp://ftpd.borland.com/download/bcppbuilder/freecommandLinetools.exe

You will like it. You have to supply your own editor. There is no gui IDE attached.

Bill
0
 

Author Comment

by:Sirocco
ID: 16750136
What size is this tool? I preffer small ones, which does not require huge system resources and single executable is preffered.
From other hand, I can edit executanle with HEX editor, its not problem for me,if this will no damage exe; but I need this url be visible in HEX editor.
0
 

Expert Comment

by:lwulfers
ID: 16751280
recompileing based on a gui configurator.  I think you are asking for trouble.  Are you planing on sendi each custom configured EXE out to different locations/users and expect them to just run the exe or install it as a service?  Since installing a progeam as a service under windows would require a short setup program anyway, why don't you just have the server exe get the two paramaters from the registry and have the setup program insert the customized registry entries for each configured installation package.
0
 

Author Comment

by:Sirocco
ID: 16751463
no, its not a service, and it does not require installation, just single exe.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16751509
Sirocco, I suggest that you only start editing the EXE file if you have a very good reason to do so ... It's not just simply replacing some text, and you have to know what your doing and where.

What does the person that is gonna create this application for you have to say about this ? Will he also make the GUI configurator for you ?
0
 

Expert Comment

by:lwulfers
ID: 16751660
So it sounds like you intend to send out the exe alone and expect it to have some information encoded into it so that when it is run it can use the two unique parameters.  I see two options.

1. Have the solution comprised of two files an exe and an encrypted config file.  (GUI generates the custom config, and f the exe can't find a config filem, then it doesn't run).

2. Have GUI program capture the parameters, generate an include file "custom_paramaters.h" to keep things simple, and then execute a command file that you embed your compiler command line text into. That would allow you to have your programmer give you a system where you could specify the parameters in the gui and trigger the build of the exe.
0
 

Author Comment

by:Sirocco
ID: 16751828
Your first option provides to have two exe files? No, its inconvenient. I am interesting to keep exe small, 5- 10KB only.
Second option looks more handy, just specify the parameters in the GUI and click the build of the exe. Not clear, what application will build exe - some ready compiler or custom exe builder. I am intersted keep exe clear and small size, without adding various parameters reuired for configurator.
0
 

Author Comment

by:Sirocco
ID: 16751985
Person gonna create this application have no normal ideas, i asked him, and he created demo 20KB(!)size, whereas my VBScript is 663bytes only..
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16752197
lwulfers, can you please read the suggestions that have already been made in this thread ... just to make sure not to post the same things again :)

>> he created demo 20KB(!)size, whereas my VBScript is 663bytes only
for a small to medium-sized application, 20 kB is not that big at all ...especially if no optimisation flags were used. And the VBScript you're talking about ... It's a script language, so it's not compiled, but it DOES need an extra application to run the script, so you can't really compare those sizes.

I'm really starting to wonder what this application is gonna do, because the requirements you give (very small size, only 1 file, configurable, ...) are weird to say the least. Any chance you can tell us what the application does ? Just to satisfy my curiosity ?
0
 

Author Comment

by:Sirocco
ID: 16752330
Its admin's script, it set up the required settings in IE, and set some policy settings.
0
 
LVL 6

Expert Comment

by:billtouch
ID: 16752600
The biggest problem in altering an exe is if the new text exceeds the length of the previous text.

Also automatically recompiling from source introduces a MAJOR secruity risk. You really should consider that part of the issue. Especially since you are changing things in your browser and your computer is obviously online.

An unscrupulous person could put the source code to a virus in there and you run it and corrupt your whole system. Virus programs cannot protect against viruses in source code. Whoever thought of this scheme doesn't have a lot of experience in developing in today's dangerous environment.

0
 

Author Comment

by:Sirocco
ID: 16752768
What you mean by automatically recompiling from source? You meant using script which will compile the application automatically?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16851104
Sirocco, it has been a while now ... was your question answered ? Or do you still have problems ?
0
 

Author Comment

by:Sirocco
ID: 16895216
No, still have no clear idea what software to use.  In the past, I saw standalone applications(for end user) which made configuration of parameters for an output exe file(as process of configuration exe), finally we just click OK button and we got the ready exe with required parameters. Probably(i am not sure) configuration was stored there in resource section of executable file. This will not require full toolchain to compile the server, only resource compiler is needed.


0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 400 total points
ID: 16895367
There's several ways to approach this problem (all have been mentioned in this thread) :

1) use a configuration file
       pro : very flexible, and easy to change the configuration (even the end user can do it)
       con : requires two files
2) create a configurator application that calls an installed compiler to generate the EXE
       pro : very easy to do
       con : requires a compiler to be installed
3) integrate a compiler (or a limited version of a compiler) into the configurator application
       pro : harder to do (and will take time to get it working correctly)
       con : exactly what you want
4) don't re-compile the EXE, but rather modify the EXE file
       pro : very fast, and doesn't require re-compilation
       con : you have to know what you're doing before starting with this

So, all depends on what you prefer ... personally I prefer solution 1, as it's very simple, and it's the standard way to do this. It does require a configuration file, but I don't see the harm in that ...
0
 

Author Comment

by:Sirocco
ID: 16895543
Problem is that with exe need be supplied this config file. Its unacceptable, unfortunately. Application need be standalone exe.
Way  No 4) look most simple, use exe to modify exe. If this can be done harmless for source code, it looks preferable. Exe (configurator) can have simple and handy GUI to modify parameters in main EXE.
0
 
LVL 6

Expert Comment

by:billtouch
ID: 16896137
You are presenting a paradox. You cannot distribute two files together, but you can distribute the source code, a compiler, a linker, hundreds of header files and libraries so the compiler will work.

Why is that better than two files?

Bill
0
 

Author Comment

by:Sirocco
ID: 16896353
Who tells I am going to distribute  the source code, a compiler, linker(!) ?? I need distribute exe only . One standalone exe.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16900208
Well, just pick your preferred solution from the list I mentioned, and implement that ... If you have specific implementation questions, feel free to ask those !
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question