检查nvcc在makefile中是否可用 [英] check if nvcc is available in makefile

查看:292
本文介绍了检查nvcc在makefile中是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中有一个函数的两个版本,一个在CUDA中实现,另一个在标准C中实现。它们在不同的文件中,让我们说 cudafunc.h func。 h (实施位于 cudafunc.cu func.c )。我想在编译应用程序时提供两个选项。如果这个人安装了nvcc,它会编译 cudafunc.h 。否则,它会编译 func.h



还有,检查一个机器是否在makefile中安装了nvcc,

解决方案

这应该工作,包含在您的Makefile中:

  NVCC_RESULT:= $(shell其中nvcc 2> NULL)
NVCC_TEST:= $ (notdir $(NVCC_RESULT))
ifeq($(NVCC_TEST),nvcc)
CC:= nvcc
else
CC:= g ++
endif
测试:
@echo $(CC)

对于GNU make,配方行



测试:之后,可以使用条件,基于 CC <



您可以将 test: target更改为



作为一个测试,只需运行上面的 make 。您应该根据检测到的结果获得 nvcc g ++ 的输出。


I have two versions of a function in an application, one implemented in CUDA and the other in standard C. They're in separate files, let's say cudafunc.h and func.h (the implementations are in cudafunc.cu and func.c). I'd like to offer two options when compiling the application. If the person has nvcc installed, it'll compile the cudafunc.h. Otherwise, it'll compile func.h.

Is there anyway to check if a machine has nvcc installed in the makefile and thus adjust the compiler accordingly?

Thanks a bunch,

解决方案

This should work, included in your Makefile:

        NVCC_RESULT := $(shell which nvcc 2> NULL)
        NVCC_TEST := $(notdir $(NVCC_RESULT))
ifeq ($(NVCC_TEST),nvcc)
        CC := nvcc
else
        CC := g++
endif
test:
        @echo $(CC)

For GNU make, the recipe line(s) (after test:) actually start with tab characters.

With the above preamble, you can use conditionals based on the CC variable to control the remainder of your Makefile.

You would change the test: target to whatever target you want to be built conditionally.

As a test, just run the above with make. You should get output of nvcc or g++ based on whatever was detected.

这篇关于检查nvcc在makefile中是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆