Makefile 变量替换有时会被忽略

发布于 2024-09-18 09:58:12 字数 1532 浏览 5 评论 0原文

编译一个支持 CUDA 的 Aircrack-ng 版本,该版本已经有一段时间没有修复错误了,因此需要一些修补才能完成大部分工作。

基本上,make找不到这一段代码的相关编译器(nvcc);

相关 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

相关 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

如您所见,make 似乎正在删除环境变量“CUDA_BIN”。

echo $CUDA_BIN的输出

/usr/local/cuda/bin

which nvcc的输出

/usr/local/cuda/bin/nvcc

我无论如何都不是制作大师,所以如果我做了一些明显错误的事情,请原谅我。

在尝试使用完整路径对 nvcc 标志进行硬编码后,该部分会进行编译,但是当涉及到加密部分(涉及 libssl)时,它无法找到必要的库,并且以与上面类似的方式不会替换“CUDA_INSTALL_PATH”,即使它在环境中,这也表明正在发生一些奇怪的事情。

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.

Basically, the make cannot find the relevant compiler (nvcc) for this one section of code;

Relevent Makefile section

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 
lt;
endif

Relevant Make output

/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'.

Output of echo $CUDA_BIN

/usr/local/cuda/bin

Output of 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九局 2024-09-25 09:58:12

在 makefile 中依赖环境变量通常不是一个好主意。在 makefile 中显式地显示该值,或在调用中指定它(例如 make CUDA=...)实际上是正确的方法。

如果您仍然想使用环境中的值,我不知道为什么您的 makefile 不起作用,但您可以尝试以下操作:

 CUDA_BIN := $(shell echo $CUDA_BIN)

It's usually not a good idea to rely on environmental variables in a makefile. Making the value explicit in the makefile, or specifying it in the call (e.g. make CUDA=...) is actually the correct way to go.

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:

 CUDA_BIN := $(shell echo $CUDA_BIN)
何必那么矫情 2024-09-25 09:58:12

如果环境变量已导出,则只能在 Makefile 中使用它们。即,如果您这样做:

export CUDA_BIN=/usr/local/cuda/bin

更基本的命令 CUDA_BIN=/usr/local/cuda/bin 将产生正确的结果
对于命令 echo $CUDA_BIN 但不会确保 Makefile 有权访问该变量

You can only use environment variables in a Makefile if they have been exported. I.e. 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文