Author Topic: Parallel project and test field problems  (Read 7236 times)

Offline j0k3r

  • Single posting newcomer
  • *
  • Posts: 4
Parallel project and test field problems
« on: September 22, 2009, 05:52:03 pm »
Hi to everyone.

I'm using C::B 8.02 and i'm sure what i'm asking is pretty trivial, however there are some interrelated issues.

I always write in C++, and i want to be able to debug my programs. First, i discovered (i'm probably wrong here though) i can only debug my code when working in "projects" because i have to set the debug flag, not in single files as i was used to (File -> New -> Empty File). So... it gives me some pain in the ass because my programs are pretty small and i'm doing a bunch of small programs so i have to create a new huge project everytime.

But that's okay, i started doing it that way (although i hope you guys can give me some light here). But now, i'd want to test some portions of codes separately, so i create a new empty file (opens up a new tab) and write a few lines, build...and oops, i realized this new file is saved as *.c whatever i do so it doesn't recognize iostream nor cout obviously etc.

So, to sum up! What's the best methodology to do what i want? Writing small-medium programs without having to create a whole new project and having the option to debug it.

Thank you!

Offline Seronis

  • Almost regular
  • **
  • Posts: 197
Re: Parallel project and test field problems
« Reply #1 on: September 22, 2009, 11:40:50 pm »
In order to debug you have to use a project / workspace, not just single files.  For situations like this i just have one project named 'quick tests' that i use and paste my code into that projects main.cpp.  As far as your problem with *.c files you must be saving it that way when you create the file, so just name your files extensions properly and problem solved?

Offline j0k3r

  • Single posting newcomer
  • *
  • Posts: 4
Re: Parallel project and test field problems
« Reply #2 on: September 23, 2009, 11:02:45 am »
Actually that is what a i did, create a "quickies" project, although i don't like doing it that way and fighting all the time with new files, replacing the actuals in the project for the new ones and so on. I see it kind of whack, why can't you debug a simple file? I don't get it.

Let's say i have this "quickies" project, only one single file named vector2.cpp... i erase its code in the editor and paste a new code (a different one), i save it as "vector4.cpp" because i want to keep it. I click build...and nothing happens, because C::B is building "vector2.cpp" which is the one that's in the project and already built...
So right click and "add files", select vector4.cpp...double click to make sure i'm editing this one and click build...error, detects multiple int main() definitions, one from vector2.cpp and the other from vector4.cpp, so... right click on vector2.cpp "remove this file from project"... and finally it works! But if i want to test a portion of vector4.cpp sepparately i should have to create a new project and blablabla... :?

So, don't you think this is a long and time-wasting way to do it? I'm spending more time navigating through C::B interface than actually working on my code.
Am I doing something wrong or it's just the way to go?  :(

Thank you.

Offline dje

  • Lives here!
  • ****
  • Posts: 683
Re: Parallel project and test field problems
« Reply #3 on: September 23, 2009, 11:36:46 am »
Why don't you keep a single file in your project with main where you put your code to debug and export the code you want to keep in other files that are not members of the project?
Quite fast I find...

Dje


zabzonk

  • Guest
Re: Parallel project and test field problems
« Reply #4 on: September 23, 2009, 12:45:42 pm »
Another alternative is to give each of your single files its own main, which does whatever you would have done in the real main. Give them distinct names:

int vector4_main( int argv, char **  ) {
   // your stuff
}

Then have a single file called main.cpp which contains a real main() that looks like this:

extern int vector4_main( int, char ** );
int main( int argc, char ** argv ) {
   return vector4_main( argc, argv );
}

Keep all of your small files in a single project and when you want to play with a particular one, change the name of the xxxx_main() that the real main calls.


Offline j0k3r

  • Single posting newcomer
  • *
  • Posts: 4
Re: Parallel project and test field problems
« Reply #5 on: September 23, 2009, 01:43:39 pm »
Thank you for the replies. I think i'll take Dje's option.
However, IMO C::B should take a review on this issue.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Parallel project and test field problems
« Reply #6 on: September 23, 2009, 07:47:30 pm »
Maybe that could be another nice feature to consider for the Debugger refactoring. What's a bit cumbersome is that by default single file compilation does not include debugging symbols, which makes it quite awkward to get it working right if you want to debug it. As usual, suggestions are more than welcomed to get things going.

I had suggested a long time ago to have multiple "sets" where you can define compilation flags, search directories, link libraries and such. That way you can link single file compilation, whole project or single file in a project to a specific set. Then, you could have, for example, a set ready for a library (let's say Allegro), and when you want to try a little program, you just create a new empty file, tell the IDE somehow that you want to use the Allegro set of compiler options and voilà.

Offline j0k3r

  • Single posting newcomer
  • *
  • Posts: 4
Re: Parallel project and test field problems
« Reply #7 on: September 23, 2009, 10:31:56 pm »
I agree with you. C::B is a pretty nice IDE and you can tell there's a lot of work behind it. There's still a bit to go.

I encourage to keep with the good work, keep it up guys!

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Parallel project and test field problems
« Reply #8 on: September 24, 2009, 01:46:42 pm »
tell the IDE somehow that you want to use the Allegro set of compiler options and voilà.
You know that this would be required for all compiler C::B supports then, right? Otherwise the message box appearing "Don't know compiler set t use for allegro for this compiler." et. al. will flood our forum with questions.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Parallel project and test field problems
« Reply #9 on: September 24, 2009, 06:51:26 pm »
tell the IDE somehow that you want to use the Allegro set of compiler options and voilà.
You know that this would be required for all compiler C::B supports then, right? Otherwise the message box appearing "Don't know compiler set t use for allegro for this compiler." et. al. will flood our forum with questions.

Mogggrrrten: the sets would also include the compiler. In other words, a set is compiler + flags + extra options. It would be really difficult to do otherwise without some sort of compiler flags translator in between (which would be another nice project :D).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Parallel project and test field problems
« Reply #10 on: September 24, 2009, 09:55:54 pm »
Ceniza: Why do you need, something that looks like a project, but it is not?
Why would someone need a single file compilation in the real world, not when he is learning C/C++ and copy/pasting some code from a book?

Projects in C::B  are quite easy to setup (when you learn how to do it), so I see no problem here.
(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 Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Parallel project and test field problems
« Reply #11 on: September 25, 2009, 07:22:23 pm »
Ceniza: Why do you need, something that looks like a project, but it is not?
Why would someone need a single file compilation in the real world, not when he is learning C/C++ and copy/pasting some code from a book?

Projects in C::B  are quite easy to setup (when you learn how to do it), so I see no problem here.


I have done that many times. I am working in a decently sized project, but I also like to try some concepts for which a project is too much. The big project is being developed in Visual Studio for convenience, but I like to prototype things with Code::Blocks. It's annoying not being able to debug single files, and creating a project for them is just too much (for a single file). If I want to try something in a single file, but I need to link against some libraries, then I have to create a whole project (modifying the global compiler options is evil).

Of course, if you are learning the language, it is a lot more practical being able to do things that way.

As a matter of fact, something I don't like of Visual C++ is not being able to compile single files (and the fact the IDE is not good enough by itself).