Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: questions2go on October 02, 2011, 08:43:25 am

Title: how to make driver program?
Post by: questions2go on October 02, 2011, 08:43:25 am
Whenever I'm working in a project and create an empty file with a main, when I compile I get an error about there being multiple main functions. How can you make a small driver program?
Title: Re: how to make driver program?
Post by: Alpha on October 02, 2011, 07:14:41 pm
This sounds to me to be more of a programming issue rather than a Code::Blocks issue (which means you should seek a programming forums, not here, for help - see forums usage guide (http://forums.codeblocks.org/index.php/topic,8962.msg64687.html#msg64687)).

You could, of course, check to see if the compiler's warning is valid (which it almost always is), and insure you only have one int main().

If this is your first experience with programming, it would be better with the standard hello world (http://wiki.codeblocks.org/index.php?title=Creating_a_new_project) example.
Title: Re: how to make driver program?
Post by: stahta01 on October 02, 2011, 09:00:21 pm
Do an full rebuild after turning on compiler logging; it might show you are compiling/linking files you did not realize.

http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Tim S.
Title: Re: how to make driver program?
Post by: questions2go on October 02, 2011, 11:11:14 pm
I think this problem is trivial so let me restate it. I'm not saying there's a problem wrong with the compiler.

If I'm writing a large program and want to make a small main file to test out 1 function, how can I do that? Must I create a new project in codeblocks?

C:\Users\Johnk\Image Transformation\main.c||In function 'main':|
C:\Users\Johnk\Image Transformation\main.c|80|warning: unused variable 'IMchr2'|
C:\Users\Johnk\Image Transformation\main.c|79|warning: unused variable 'IMchr1'|
obj\Debug\Desktop\SmallTest.o||In function `main':|
C:\Users\Johnk\Desktop\SmallTest.c|9|multiple definition of `main'|
obj\Debug\main.o:C:\Users\Johnk\Image Transformation\main.c|64|first defined here|
||=== Build finished: 2 errors, 2 warnings ===|
Title: Re: how to make driver program?
Post by: oBFusCATed on October 02, 2011, 11:39:51 pm
You have 2 options:
1. create new project;
2. create new target inside the existing project (you have to include only a subset of the files in the project);
Title: Re: how to make driver program?
Post by: Alpha on October 03, 2011, 02:47:37 am
There is a third option:
You could comment out the "main" main() function to write a small "test" main() by putting block comments arround one of the functions...
Code
/*
int main()
{
    ... code ...
}
*/
... or by using the Code::Blocks shortcut of highlighting the function and hitting Ctrl-Shift-C (or Ctrl-Shift-X to uncomment).

(Off-topic: oBFusCATed, nice post count :)... I wanted to say right when it turned, but I missed.)