2012-09-17 61 views
1

我在想爲什麼這兩個命令返回兩個不同的結果。第一個是:「make -C X」vs「cd X; make」

[[email protected] par-run-d2]# make -C NQU/ 
make: Entering directory `/home/ut/gpgpu-sim/benchmarks/par-run-d2/NQU' 
nvcc -c -arch sm_11 --keep --compiler-options -fno-strict-aliasing \ 
     -I. -I/usr/local/cuda//include/ -I/home/ut/NVIDIA_GPU_Computing_SDK/C//common/inc/ \ 
      -L/home/ut/NVIDIA_GPU_Computing_SDK/C//lib -lcutil -DUNIX nqueen.cu -o nqueen 
nqueen.cu(681): warning: variable "start" was declared but never referenced 

nqueen.cu(681): warning: variable "end" was declared but never referenced 

nqueen.cu(681): warning: variable "start" was declared but never referenced 

nqueen.cu(681): warning: variable "end" was declared but never referenced 

gcc -g -c nqueen.cu.cpp -o nqueen.cu_o 
echo ../../.. 
../../.. 
../../../scripts/gen_ptxinfo 
Generating nqueen.ptxinfo... 
make: *** [nqueen.cu_o] Error 255 
make: Leaving directory `/home/ut/gpgpu-sim/benchmarks/par-run-d2/NQU' 

,第二個是:

[[email protected] par-run-d2]# cd NQU/ 
[[email protected] NQU]# make 
g++ -g nqueen.cu_o -L../../../libcuda/ -lcuda \ 
     -L/home/ut/NVIDIA_GPU_Computing_SDK/C//lib -lcutil \ 
     -L../../../src/ -lgpgpusim \ 
     -L../../../src/intersim -lintersim \ 
     -L../../../src/cuda-sim/ -lgpgpu_ptx_sim \ 
     -lm -lz -lGL -o gpgpu_ptx_sim__nqueen 
rm -rf *.cpp*.i *.cpp*.ii *.cu.c *.cudafe*.* *.fatbin.c *.cu.cpp *.linkinfo *.cpp_o core *.cubin cubin.bin *_o *.hash nqueen 

任何想法,爲什麼 「讓-C X」 從 「CD X /;使」 不同?

回答

0

順序cd X; make正在更改調用shell(終端的交互式shell)的當前目錄。請像(cd X; make)一個子shell來避免這種情況,這比它執行make進程中的系統調用chdir所以不能改變父進程(你的交互shell通常情況下)的工作目錄鍵入更長的時間。

此外-w標誌的行爲會有所不同。而大多數遞歸$(MAKE)Makefile -s正在做一個-C somesubdir

PS。請記住內置的cd shell會調用對父進程沒有影響的系統調用chdir(2)

+1

我看不出如何改變子shell的工作目錄是與此有關,因爲make'後'有在子shell沒有命令。我不明白'-w'標誌的行爲會有什麼不同。你可以給我們一個Makefile來演示效果嗎? – Beta