c++ - compiling multiple files with -D option using gcc -


i have project multiple .cpp , .h files. have file called globals.h included in .cpp files. when compiling file use -d options. these options affect files not globals.h.

in makefile had use same -d options when compiling every file. of course when removing options "undefined" errors arise.

this means every time change 1 of these options have recompile whole project. there way let me compile globals.h these options?

this part makefile: lines create globals.o :

globals.o : $(globalslib) $(globalsinc)        g++ -c -wall $(codedefined) $(userdefined) $(globalslib) -std=c++0x -o globals.o 

$(globalslib) , $(globalsinc) paths files globals.h , globals.cpp $(codedefined) , $(userdefined) -u , -d options code creating .o file:

nt_fft_decomp.o : $(globalslib) $(globalsinc) $(nt_decomplib) $(nt_decompinc)        g++ -c -wall $(codedefined) $(userdefined) $(nt_decomplib) -std=c++0x -o nt_fft_decomp.o 

(nt_decomplib) $(nt_decompinc) paths files. notice had add same options in g++ command. there anyway around that?

no, that's not how headers work.

headers not separate compilation units. perhaps make more sense if precompile of files, via -e flag (i think). leave bunch of .i (i think) files compiled. note headers gone, contents spread across different source files. have recompile each time.

there ways minimize source recompilation. instance situation:

foo.h

int foo = 1; 

can turned one:

foo.h

extern int foo; 

foo.cpp

int foo = 1; 

so can change value of foo without recompiling.

but unfortunately, sounds header big. if throw in 1 header you're going doing lot of recompilation. factor more , may more avoidable.

also (or alternatively?) use precompiled headers reduce compilation time. i've never programmed them solve problem understand.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -