GCC source/object timestamp switch

Is there a switch to pass to GCC so it doesn't re-compile my code if the object file is newer than the source file? This is getting quite annoying.
Err... it shouldn't be doing that. It would need to recompile if the object file is older than the source file... not vice versa.

Are you sure that's really what's happening?


EDIT:

Also does GCC even do this? I thought it just compiled whatever files you tell it to and it doesn't care about timestamps. I thought the build manager (ie: make, or whatever IDE you're using) keeps track of all this stuff.

Forgive my ignorance in this area....
Last edited on
I have no IDE, make, etc. I'm using batch files. I'm calling GCC manually, like so:

gcc -g -c main.c -o./obj/main.o -std=c99

I'd like GCC to not compile if it sees that the source file is older than the object file, because if that's the case, then the code hasn't changed since the last time it compiled the code. Sorry, i switched the two around in my question.
Last edited on
Sounds like the thing you would use a makefile for.
Is there a switch to pass to GCC so it doesn't re-compile my code if the object file is newer than the source file? This is getting quite annoying.
That's what Make is for. Why would the compiler do that?
If you really have no build system (make, ...) you may write a shell script. Starting idea:

build

1
2
3
4
5
6
7
8
9
10
11
12
# USAGE
#   build <source_file_name>

SRC_SUFFIX=.c
DST_SUFFIX=.o

src_file_name="$1"
dst_file_name=`basename "$src_file_name" $SRC_SUFFIX`$DST_SUFFIX

if [ "$src_file_name" -nt "$dst_file_name" ]; then
    gcc -g -c "$src_file_name" -o"$dst_file_name" -std=c99
fi
Topic archived. No new replies allowed.