简体   繁体   English

Makefile 变量替换有时会被忽略

[英]Makefile variable substitution sometimes ignored

Compiling a CUDA enabled version of aircrack-ng that hasn't been bug-fixed in a while so needed a bit of patching to get most of the way there.编译启用了 CUDA 的 aircrack-ng 版本有一段时间没有修复错误,因此需要一些补丁才能完成大部分工作。

Basically, the make cannot find the relevant compiler ( nvcc ) for this one section of code;基本上,make 找不到这一段代码的相关编译器( nvcc );

Relevent Makefile section相关 Makefile 部分

ifeq ($(CUDA), true)
CFLAGS += -DCUDA_ENABLED

NVCC := $(CUDA_BIN)/nvcc
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include
COMMONFLAGS += $(INCLUDES) -DUNIX

NVCCFLAGS += --compiler-options -fno-strict-aliasing --host-compilation=C $(COMMONFLAGS)

# Change this only if you have COMPUTE > 1.0
NVCCFLAGS += -maxrregcount 12

# Enable this for extra compiler and as output
#NVCCFLAGS += --ptxas-options "-v" --verbose

LIBSSL += -L$(CUDA_INSTALL_PATH)/lib -L$(CUDA_INSTALL_PATH)/lib64 -lcuda -lcudart

%.o : %.cu   
    $(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -c $<
endif

Relevant Make output相关 Make 输出

/nvcc --compiler-options -fno-strict-aliasing --host-compilation=C -I. -I/include -DUNIX -maxrregcount 12  -o cudacrypto.o -c cudacrypto.cu
make[1]: /nvcc: Command not found
make[1]: *** [cudacrypto.o] Error 127
make[1]: Leaving directory `/home/bolster/src/aircrack-ng-cuda/src'
make: *** [install] Error 2

As you can see it looks like make is dropping the environment variables 'CUDA_BIN'.如您所见,make 似乎正在删除环境变量“CUDA_BIN”。

Output of echo $CUDA_BIN echo $CUDA_BIN的输出

/usr/local/cuda/bin

Output of which nvcc which nvcc的输出

/usr/local/cuda/bin/nvcc

I am not a make-guru by any stretch, so if I'm doing something patently obviously wrong, forgive me.无论如何,我都不是化妆大师,所以如果我做的事情明显是错误的,请原谅我。

After trying hard coding the nvcc flag with the full path, that section compiles, but when it comes to a crypto section (involving libssl) it cannot find the necessary libraries, and in a similar fashion as above isn't replacing 'CUDA_INSTALL_PATH', even though it is in the environment, which indicates to be that something weird is going on.在尝试使用完整路径对 nvcc 标志进行硬编码后,该部分会编译,但是当涉及到加密部分(涉及 libssl)时,它找不到必要的库,并且以与上述类似的方式不会替换“CUDA_INSTALL_PATH”,即使它在环境中,这表明正在发生一些奇怪的事情。

It's usually not a good idea to rely on environmental variables in a makefile.在 makefile 中依赖环境变量通常不是一个好主意。 Making the value explicit in the makefile, or specifying it in the call (eg make CUDA=... ) is actually the correct way to go.在 makefile 中显式指定值,或在调用中指定它(例如make CUDA=... )实际上是正确的方法。

If you still want to use the value from the environment, I don't know why your makefile isn't working, but you can try this:如果您仍想使用环境中的值,我不知道为什么您的 makefile 不起作用,但您可以尝试以下操作:

 CUDA_BIN := $(shell echo $$CUDA_BIN)

You can only use environment variables in a Makefile if they have been exported.如果环境变量已被导出,则只能在 Makefile 中使用它们。 Ie if you do:即如果你这样做:

export CUDA_BIN=/usr/local/cuda/bin

The more basic command CUDA_BIN=/usr/local/cuda/bin will lead to the correct result for the command echo $CUDA_BIN but will not ensure that the Makefile has access to the variable更基本的命令CUDA_BIN=/usr/local/cuda/bin将导致命令echo $CUDA_BIN的正确结果,但不能确保 Makefile 可以访问该变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM