Author Topic: {newbie} Creating a project from a source file  (Read 5546 times)

pkelecy

  • Guest
{newbie} Creating a project from a source file
« on: June 19, 2008, 06:02:26 pm »
I'm new to both Code::Blocks and C++, so bear with me if this is pretty basic... :)

I have the source code for some DLL's (written in C++) that I need to modify.  These DLL's are used by another application.  The way I've been doing this, using Code::Blocks, is as follows:

1. Select "Create new project" in the Start Window.

2. Select "Dynamic Link Library".  That starts a wizard, where I enter a project name and select the compiler (the default one, usually).

3. With the project now created, I then right-click on the project in the Projects window and select "remove files...".  There I remove main.cpp and main.h.

4. I right click on the project again and select "add files...", where I browse to the DLL source code file I want to modifiy.  After selecting this file, I'm asked to "select the targets this file should belong to:  _ Debug,  _ Release".   I've been checking both (not sure if that's right or not).

5. I then modifing the souce code and build it.

6. Lastly, I copy the compiled dll file (located in Project/Bin/Debug directory)  to another directory where it can be accessed by the application that uses it.


So my questions are:

1.  Is this the best way to do this (i.e. is there a more direct way to create a project from an existing source file)?

2.  With regard to "select the targets this file should belong to...", I assume these (Debug and Release) represent directories where the compiled code goes, depending on what stage of completion it's in.  Is that right?  How should these directories be used?

3.  Is there a way to have the compiled (or "built" - I assume this means the same thing) file automatically saved in the final directory (where the application looks for it) to avoid having to copy it there?


Those are the main questions I have for now.  Thanks for any help with these. :)  I have several good C++ books I've been studying, but none of them talk much about IDEs or the actual mechanics of software development.

Pat





Offline Deschamps

  • Multiple posting newcomer
  • *
  • Posts: 120
Re: {newbie} Creating a project from a source file
« Reply #1 on: June 21, 2008, 06:36:48 pm »
Quote
Is this the best way to do this (i.e. is there a more direct way to create a project from an existing source file)?

Once you've created your project (after all the steps used in the wizard), you could save it as User template project (menu File -> Save project as user template) so you could create another one directly, without repeating those steps (menu File -> New -> From user template). I think that this must be the shortest creating the same project (then you could change the involved files, and so).

Quote
With regard to "select the targets this file should belong to...", I assume these (Debug and Release) represent directories where the compiled code goes, depending on what stage of completion it's in.  Is that right?  How should these directories be used?

Within a project you can define different "build targets", in regards to the output you need for each of them, i.e., if you want to compile your source, for instance, against an static library and another binary linked against a shared version of that library, then you define two different build targets, that will produce different versions of your same code (being essentially the same program). Debug and release are in that sense, the same program but including (in debug) all the symbols that make possible to find bugs, defects, and so. Is the usual way in development environments. The "release" build is intended to productions environments, i.e., when you want to "release" your program (excluding all the debugger symbols and making an smaller executable). Those parameters are defined in the compiler options. If you doubt what build target to use, then use the "release" target.

Quote
Is there a way to have the compiled (or "built" - I assume this means the same thing) file automatically saved in the final directory (where the application looks for it) to avoid having to copy it there?

Open your project properties, go to the build targets tab and use the Output filename option to specify the name and path (that could be absolute or relative) of your compiled library.

Regards.
Those who were seen dancing were thought to be insane by those who could not hear the music

pkelecy

  • Guest
Re: {newbie} Creating a project from a source file
« Reply #2 on: June 27, 2008, 02:33:39 am »
Thanks for the reply.  It was a big help, and I now have some templates set up.  :D

I have a few other questions though.  I find that I'm doing a lot of experimenting with this code development (i.e. adding or changing some code, compiling it, and then loading the resulting dll into the application that uses it to see what it does).  There are a couple of issues I've encountered in doing this though:

1. If I make a change to the code and compile it, keeping the same filename, the new compiled dll won't overwrite the old one while the application is running.  I get some message saying "the file is in use" - eventhough it's not.  If I close the application then I can overwrite the old version .  That's not very convenienent though, as I'd like to be able to just overwrite the old version and then read the new version into to application (which is something I do within the application ) without having to exit and restart it each time (which is rather time comsuming).

2. If, instead, I change the file name (by renaming it in the project window) rather than overwriting, that doesn't change the name of the compiled (target) dll.  To change that, I have to go into properties, which again is a little trouble.

Is there a better way to do either of these?  Managing file versions I expect is a common need in code development, so I'm guessing there's a better way to do this.

Thanks again for the help! :D