Author Topic: how to make driver program?  (Read 5071 times)

Offline questions2go

  • Single posting newcomer
  • *
  • Posts: 2
how to make driver program?
« 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?

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: how to make driver program?
« Reply #1 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).

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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6671
    • My Best Post
Re: how to make driver program?
« Reply #2 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline questions2go

  • Single posting newcomer
  • *
  • Posts: 2
Re: how to make driver program?
« Reply #3 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 ===|
« Last Edit: October 02, 2011, 11:17:52 pm by questions2go »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12121
    • Travis build status
Re: how to make driver program?
« Reply #4 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);
(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!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: how to make driver program?
« Reply #5 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: [Select]
/*
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.)