Menu

How to arrange files in Dev C++?

2003-02-01
2012-09-26
  • Nobody/Anonymous

    I know this sounds like a simple question, but there is no documentation anywhere that explains this.

    HOW do I set up my project so that I can have:

    -- ProgramMain.cpp
    -- ProgramClasses.h
    -- ProgramClasses.cpp

    where ProgramClasses.h contains class declarations and ProgramClasses.cpp contains the implementations of the class methods.

    I have put inclusion guards around ProgramClasses.h.  But no matter what I do, either the compiler tells me that the variables etc in classes.cpp are undefined, OR the linker tells me that there are multiple definitions of everything in classes.h.  Damned if I do and damned if I don't, know what I mean?  What's the simple answer here?

     
    • Curtis Sutter

      Curtis Sutter - 2003-02-01

      do not #include any .cpp files.  If they are in your project they are included already.

      Curtis

       
    • Nobody/Anonymous

      Thanks, but I'm not #including any .cpp files.

      I have three files in my project.

      1: Main.cpp
      2: Classes.h
      3: Classes.cpp

      Classes.h has inclusion guards around it, so I should be able to #include Classes.h in both Classes.cpp and Main.cpp.  That's how I thought I was supposed to do it.

      My question is probably a bit more nuanced.  I can get everything to work fine, provided the classes.h has only class declarations and classes.cpp has only class method definitions.  But as soon as I start putting other things in additional files -- variables, for instance -- then I get errors because I'm declaring variables multiple times.

      So what do the inclusion guards do, exactly?  Obviously they don't stop a .h file from being read twice.

      I wanted to stick my global variables into another .h or .cpp file.  Maybe this is just a stupid thing to want to do.  However, I've had problems getting other multiple-file projects to work under Dev-C++ when they work fine under MSVC++.  In Dev I get the "multiple" errors but in MSVC++ I don't, so I don't understand what the problem is.  Must have something to do with settings but I haven't been able to figure out what.

       
    • Nobody/Anonymous

      Duhhhh ....
      Okay, I solved the problem.  The problem was my stupidity, as usual.

      As for the MSVC++ thing, that all happened too long ago to get into, so never mind.

      Still a bit confused about the inclusion guards, though.
      Hey, I'm still officially a beginner, I can get away with this...

       
    • Nobody/Anonymous

      Could you tell us the solution - please?

      IMHO stupidity isn't the issue. We all make mistakes. I know that the older I get, the more mistakes I make!
      Maybe something isn't explained correctly in the FAQ or the helpfile. Your input could help inprove things.

      /Lars.

       
    • Nobody/Anonymous

      It would be nice if books/tuturials/IDE documentation/FAQs could come right out in the beginning and explain how the compiling and linking process happens.  No book or tutorial I've encountered explains how the preprocessing/linking/compiling of, say, a 5-file project happens.  They skim over it as if it's not really important.  It IS important and it should be explained in detail.  This should be explained in the beginning and every IDE should explain it in the Help -- even free ones like Dev.

      orig

       

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.