C compilers doing wierd stuff

This is a discussion on C compilers doing wierd stuff within the C Programming forums, part of the General Programming Boards category; My college computers have Borland installed, and it really sucks. For some reason every time I want to compile an ...

  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Angry C compilers doing wierd stuff

    My college computers have Borland installed, and it really sucks. For some reason every time I want to compile an altered version of my program I have to exit the compiler, delete all the additional files created. Then start it up again and reload the code I was working on. Otherwise it only compiles the last saved version.

    Anyway its really annoying. I use Dev-C++ and I havent had a problem like this... Until recently. I don't know why this has started, but sometimes when I compile a prog it doesnt run the latest version. Thankfully I dont have to exit the compiler, just delete the .exe created for the file, but its still a pain. Especially when I dont realize why my changes arent taking effect and I waste time altering my code trying to fix the problem.

    I have coded in several different languages, but it seems that only C wants to agrovate me this way. Does anyone know why this happens or if there is a way to stop this?

  2. #2
    #C-help
    Join Date
    Jun 2007
    Location
    Las Vegas
    Posts
    53

    Talking Maybe You Forget To Save

    It happenes to me and that's why I need a spare keyboard! Try and save 2 times, make sure you saved and one tip I would give you, Dev C++ is very very stupid! I use gcc, cc and g++ and I never had a problem with them!

    I do not know if they have cc or gcc or g++ for windows, I use Ubuntu Linux!
    <<deleted because of colour and size abuse>>

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    MinGW is the Windows port of GCC. cygwin is an alternative for Windows that uses GCC, and also ports over a lot of Unix/Linux functionality.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    It sounds like there's something messed up with your clock.

    You see, when IDEs like Dev-C++ and Borland go to compile a program, they don't compile only one source file if you have a project. They'll use a Makefile, which will compile only the source files that have changed and thus need recompiling. (And the source files that depend on those source files.)

    Usually these programs determine if a file has changed by looking at its timestamp, or time it was last modified. For example, if the timestamp on a source file is later than the timestamp on the executable that is being created, the source file needs to be re-compiled.

    This works quite well . . . until the clock gets messed up. (Sometimes make, if you run it directly, will detect this and complain with "clock skew detected".) If you have a time-syncronizing program which automatically syncronyizes your clock with some atomic clock or another -- and you probably do, one comes with Windows XP -- it could set the clock back a bit. Then you change your file, but its date is older than the executable, so your IDE doesn't think it needs re-compiling.

    So how can you fix this? I don't know how to do it in an IDE. Sometimes there's an option like "build all" or "rebuild project". From a command line, there's usually a target called clean. As you have discovered, what these do is basically just delete all of the object files and executable files created.

    If you only have one or two source files, or your program doesn't take very long to compile, you can probably get away with deleting these files every time you re-compile your program. You could do this with a batch file or something. But the best way would probably be to get your IDE to generate a Makefile, and modify it so that it does it for you. You can probably do this by adding this line to the top of the Makefile:
    Code:
    all: clean program.exe
    If "all" already exists, call it whatever you like. If "clean" doesn't exist, you'll need to post the Makefile here. Or read a tutorial on Makefiles.

    If your project does take a while to compile, you'll need to use a different method besides timestamps to tell if a source file has been modified. Perhaps the best way would be to make copies of each source file every time you compiled the program. Then you could compare these copies to the real thing when you went to compile. If they differ, the source file needs re-compiling. This could be done automatically with a Makefile, but unless you have a very big project, you probably won't need to do this.

    Or you could create your own Makefile. Something like this would work.
    Code:
    project.exe: clean main.o whatever.o
    <tab>$(CC) $(CFLAGS) main.o whatever.o -o project.exe
    
    clean:
    <tab>del main.o
    <tab>del whatever.o
    <tab>del project.exe
    where <tab> is a tab (spaces don't work) should do. Add as many object files as you want. (Some compiles also use .obj instead of .o; I think Borland is one of them.)

    Or you could try fixing your clock. Why does it need to be set backwards anyway? Maybe your battery is dying. There's a battery inside your computer that keeps the internal clock ticking. It doesn't need to be replaced very often, but I'm sure it needs replacing occasionally.

    This whole (very long) post was assuming that my guess was correct, and that your clock is what's messing everything up. I think it probably is, because when you delete the exe it works, though why the clock is the problem is beyond me. I've had similar problems before on a computer that's not even connected to the internet. I have a suspicion that not all IDEs update the timestamp on a file when they modify them.

    [edit] The first response is valid too. With some IDEs you have to save source files, you can't just hit "compile". I don't think Dev-C++ is one of them, though. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by dwks View Post
    This works quite well . . . until the clock gets messed up. (Sometimes make, if you run it directly, will detect this and complain with "clock skew detected".) If you have a time-syncronizing program which automatically syncronyizes your clock with some atomic clock or another -- and you probably do, one comes with Windows XP -- it could set the clock back a bit. Then you change your file, but its date is older than the executable, so your IDE doesn't think it needs re-compiling.
    Another reason it happens (and it happens to me a lot at work) is that your source code is stored on a network file server, and the time on the server doesn't match the time on your local system. I usually end up either cleaning the entire project or forcibly "touching" the one file I need to recompile. That forces it to adopt a new server-based timestamp.

  6. #6
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Wow thanks, thats quite an explanation dwks. I'll have a read of what I can do with the makefiles, only thing is at the moment I'm just running simple little test programs w/o a project. It does look as if it could be a faulty timestamp on the exe. Viewing file details in winXP gives the last modified time, next time it happens I'll check and see if anything looks wrong there. Oh and yeah, Dev-C++ saves before compiling.

    Cheers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scientific calculators with compilers?
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-06-2003, 08:29 PM
  2. small compilers?
    By Korn1699 in forum C++ Programming
    Replies: 2
    Last Post: 06-22-2003, 05:58 PM
  3. compilers
    By ZakkWylde969 in forum C Programming
    Replies: 12
    Last Post: 06-17-2003, 01:40 PM
  4. target OS compilers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 07-01-2002, 11:08 AM
  5. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21