News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

how to make driver program?

Started by questions2go, October 02, 2011, 08:43:25 AM

Previous topic - Next topic

questions2go

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?

Alpha

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).

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 example.

stahta01

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

questions2go

#3
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 ===|

oBFusCATed

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);
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Alpha

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...

/*
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.)