Menu

very new to Dev-C++, can't change program

maryS
2009-09-16
2012-09-26
  • maryS

    maryS - 2009-09-16

    Hi,
    I am having trouble which is not described in the FAQ: when I write a new
    program, or add it to a project, it goes onto the screen but when I try to
    compile the new one, it instead compiles the old one that is not on the
    screen. I'm not exactly sure what a project is anyway, but I have managed to
    create 4 of them. If one of them is on the screen, and I want to change to
    another, how do I do it? I have tried to click on the new one but it doesn't
    do it; I have to close down Dev-C++ entirely and try to load in the file I
    want to compile+run. Thank you in advance.

     
  • cpns

    cpns - 2009-09-16

    Dev-C++ allows you to compile and run a single file without creating a
    project. It is just a bad idea - always create a project.

    You can only have one project open at a time, so your problem is probably one
    of understanding. Opening a sourcefile when a project is open will not switch
    to building that sourcefile, you have to open the project.
    File->New->New Project

     
  • maryS

    maryS - 2009-09-16

    So even if I have a project that has more than one tab, I can't switch from
    one tab to another and compile/run this new tab? There's an icon on the top
    that allows me to add or subtract source files to the project,
    but even if I (1) add a different (already stored) file to the project, (2)
    click on the newly added file which puts it onto the main window, (3) subtract
    the file that was previously in the main window, and (4) press F9, the
    original file that I just removed and replaced is run!

     
  • maryS

    maryS - 2009-09-16

    It gets worse. I closed down Dev-C++ and then re-opened it and loaded a
    totally different project, selected its file, and pressed F9, and it ran and
    compiled the file that was there before I shut the program down!

     
  • cpns

    cpns - 2009-09-16

    > So even if I have a project that has more than one tab
    Multiple tabs and projects are not the same thing. That merely means you have
    more than one file open. Are they part of the same project?

    When you create a project, you can add one or more source files to it and each
    is separately compiled and then linked. They must form a whole program
    however. You cannot for example have main() defined in more than one source.

    If you create two separate source files that are independent and both contain
    main(), you can compile than separately into separate executables while they
    are open simultaneously, but you must not have a project loaded in order to do
    that, because when you have a project loaded, the open files are irrelevant,
    it is only the files that are members of your project that are compiled and
    linked.

    I don't recommend using that method, because you have no control over how the
    program is built. It will be built with whatever steering are set in the
    Tools->Compiler options dialog at the time. A project keeps the settings as
    well as the source so that it is always built with the same way, regardless of
    subsequent changes to the IDE configuration.

    It is a deficiency of Dev-C++ that it does not support multiple projects open
    simultaneously (although you can probably open more than one instance of
    Dev-C++). If you want that capability, try MSVC++ 2008 Express Edition. It
    will not allow the 'project-less' quick-and-dirty build method of Dev-C++, but
    you can have multiple projects in on 'solution'. It also has a more powerful
    IDE and excellent debugger.

    I think the behaviour you describe is normal and correct, but that you
    misunderstand the project and separate-compilation concept. If you open a
    project, what will be built is the project, not merely the sourcefile you
    happen to have open. Most non-trivial projects have multiple source files,
    often hundreds or even thousands.

    Clifford

     
  • cpns

    cpns - 2009-09-16

    Brilliant - Sourceforge still not fixed the quote mark-up I see! And still no
    edit feature.

    Above "steering" should be "settings"

     
  • maryS

    maryS - 2009-09-17

    Clifford:
    Thank you very much for the enlightening explanation. What I didn't realize is
    that it is irrelevant what's in the window, but it's the project that gets
    built. Plus at my very novice level, all the C++ files I have written have the
    main() function in them, and this means I can't have more than one file in
    that project. Thanks again.

     
  • maryS

    maryS - 2009-09-27

    This is very difficult for me to understand for some reason. If I have a
    project open with only one program (it's listed in the big window on the
    right, and the narrow window on the left shows it hanging, by itself, off the
    project), I can compile and run it fine. If I subtract the file and try to
    compile, DevC++ objects because the project is empty. I thought that made
    sense. I then added a completely different file to that project, and when I
    tried to compile/run it, it used the original file I had thought i subtracted!
    But, if I edit the 'new' file, in the most unsubstantial way,
    this new file will compile and run.
    It seems to me that when I emptied the project and it wouldn't compile, it was
    because DevC++ was looking for something contained in the project and found
    nothing. But when I added the new file, it all of a sudden remembers the one I
    discarded! This is very confusing. Thank you in advance.
    Mary Spellman

     
  • cpns

    cpns - 2009-09-27

    What the IDE does for you (and one of the magor reasons for using one over
    comman line builds) is generate a makefile. The makefile contains rules for
    building your project, and the rules have dependencies - a list of files that
    if changed will result in the target of the dependency being rebuilt. The
    highest level target is the executable file, which is dependent on one or more
    object files, which is dependent in a single C or C++ sourcefile, which may be
    dependent on a number of header files. It is possible to have more complex
    dependencies, but that is the general case and more or less all Dev-C++ will
    handle automatically.

    When you added your source file, Dev-C++ may not have correctly regenerated
    teh dependencies, it will have seen that all the object files were no older
    than the executable file, and will have built nothing. If you took a look at
    the Compile Log tab, you will have seen that nothing was compiled. When you
    changed the sourcefile, It must have forced a dependency regeneration which
    got teh project back into synch.

    It is an artefact of Dev-C++'s imperfect dependency tracking when 'unusual'
    events occur. If you make significant changes to your project such as adding
    or removing files, or changing build options, I suggest that you perform a
    "Rebuild All" rather than "Build" operation from the
    project menu. This will ensure proper dependency regeneration. At other times,
    if you suspect the build is inconsistent, try a "Rebuild All" then
    also. If the project is small, performing a "Rebuild All" is
    insignificant in any case, on large projects it can take considerable time,
    and you would wish to avoid this.

    Clifford

     
  • maryS

    maryS - 2009-09-28

    Clifford: Thank you again for a very lucid explanation. It's clear that I must
    learn about makefiles and building them. I have never yet used 'build', only
    compiled and run for single files in projects, using F9.

    For my simple projects, which contain only one file, it is very fast to do a
    'rebuild all' or to add an empty line which puts the file onto the list making
    up the dependencies. If I had a lot of files in the project and wanted to add
    one or more others, there's probably a way to speed things up by getting it
    into the dependencies list and changing it by adding the new filenames so that
    I must only compile the new files. But at my level, 'Rebuild All' does the job
    for sure.
    M.S.

    I wish there were a manual, but all I can find so far are the FAQ's.

     
  • cpns

    cpns - 2009-09-29

    I always thing that "Compile and Run" is a bit optimistic. More
    often than not, code does not compile first time. Actually I may be
    misremembering the menu names. I recall that what Dev-C++ refers to as
    "Compiling" is in fact "Compile and link" i.e.
    "Building". There is a separate item for "compile this
    file", which does compilation only for a single file (rather than a whole
    project), and only generates the object file (not the executable).

    Reading may help. I wrote it a while back.

    : https://sourceforge.net/projects/dev-cpp/forums/forum/48211/topic/1111298?m
    essage=2670009

     
  • maryS

    maryS - 2009-09-29

    Clifford:
    I read your mini-article about compiling and linking and libraries. It was
    very interesting. I am wondering if there is somewhere in Dev-C++ that one can
    hold previously-compiled code or even libraries made up of .o files written by
    theirselves and maybe want to use again.

    But I'm still trying to master Classes and Inheritance, anyway. Thank you for
    the advice.

    MS

     
  • cpns

    cpns - 2009-09-30

    File->New->New Project

    You will see that there is a template for "Static Library". That is
    what you are looking for. It will compile your project files and then instead
    of linking an executable with the linker (ld.exe) it will invoke the librarian
    (ar.exe) to create a library archive file.

    When doing this I suggest you prefix your project name "lib" to
    conform with the GNU naming convention. If your project is called libXXX, then
    the resulting library will be called libXXX.a, and can be linked to another
    project with the -lXXX linker option. The library directories box in the
    project settings dialog determine where the linker looks for libraries (it
    adds -L<path> options to the build). You need to add the path to your
    library repository here. Alternatively you can specify the path and filename
    of the library in full - there is a browse button for that in the project
    dialog, you can use it for individual object files too.

    So to answer your question directly, you can put your libraries and object
    files where you please; you just then need to tell the linker where they are.
    I strongly suggest that you don't take the 'short-cut' of just dumping your
    libraries in the default library path. These are for the standard libraries
    and libraries provided with Dev-C++. Using that may make moving your work, or
    reinstalling Dev-C++ problematic.

    Clifford

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.