简体   繁体   English

使用 Automake 一步生成一个编译和链接所有源文件的 Makefile

[英]Generate a Makefile that compiles and links all the source files in a single step with Automake

I am new with automake.我是 automake 的新手。 I am trying to write the Makefile.am files for my library, however due to some limitation of the nvcc compiler, I need to compile and link the source files in a single step, without producing the .o files, so that I directly generate the library without having to link separate files.我正在尝试为我的库编写 Makefile.am 文件,但是由于 nvcc 编译器的一些限制,我需要一步编译和链接源文件,而不生成 .o 文件,以便我直接生成库而无需链接单独的文件。 I could find several examples of Makefile.am files in the web, but none of them seemed to fit my need.我可以在网上找到几个 Makefile.am 文件的例子,但似乎没有一个适合我的需要。 Here is my (working) Makefile:这是我的(工作)Makefile:

CC=g++
NVCC=nvcc
CXXFLAGS= -O3 -Wall -fPIC
CUDAFLAGS= -arch sm_30 --ptxas-options=-v --relocatable-device-code true
LIBS= -lm
LDFLAGS = -shared   # linking flags

RM = rm -f   # rm command
TARGET_LIB = ./lib/libsharedcuda.so  # target lib

SRC_DIR   = src

SRC_FILES  = $(wildcard $(SRC_DIR)/*.cu)
SRC_FILES += $(wildcard $(SRC_DIR)/*.cpp)

H_FILES   = $(wildcard $(SRC_DIR)/*.h)
H_FILES += $(wildcard $(SRC_DIR)/*.cuh)

.PHONY: all
all: ${TARGET_LIB}

$(TARGET_LIB): $(SRC_FILES)
    $(NVCC) -ccbin=${CC} --compiler-options  '${CXXFLAGS}' ${CUDAFLAGS} ${LDFLAGS} -o $@ $^

.PHONY: clean
clean:
    -${RM} ${TARGET_LIB}

How should the Makefile.am be written in order to produce a makefile like this one?应该如何编写 Makefile.am 以生成这样的 makefile?

The correct answer to my question is the one written by Sam Varshavchik: as he pointed out, it is not possible.我的问题的正确答案是 Sam Varshavchik 所写的:正如他所指出的,这是不可能的。 However, for anyone who might be interested, I found a workaround that solves my problem, useful for instance if you want to build a CUDA-C/C++ shared library with Autotools.但是,对于可能感兴趣的任何人,我找到了解决我的问题的解决方法,例如,如果您想使用 Autotools 构建 CUDA-C/C++ 共享库,则很有用。

The trick is to generate first the src/Makefile.in file using autotools, then modifing this file before the make command.诀窍是首先使用 autotools 生成 src/Makefile.in 文件,然后在 make 命令之前修改此文件。 With my versions of autoconf/automake, the relevant line is:对于我的 autoconf/automake 版本,相关行是:

    $(AM_V_CXXLD)$(libexample_la_LINK) ... 

that should be replaced by something like:应该用类似的东西代替:

    nvcc -ccbin=g++ --compiler-options  '-O3 -Wall -fPIC' -shared -arch sm_30 --ptxas-options=-v --relocatable-device-code true -o source-files -lm

where libexample is the name of the library and source-files is the list of files to be compiled.其中 libexample 是库的名称,而 source-files 是要编译的文件列表。 Be careful: the line is preceded by a tab, not by spaces.注意:该行前面是制表符,而不是空格。 If you want to be able to use "make install", you should also modify the command that installs the library in the proper folder.如果您希望能够使用“make install”,您还应该修改将库安装在正确文件夹中的命令。 In my case in:在我的情况下:

    $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)";

"$$list2" should be replaced by "libexample.so" "$$list2" 应替换为 "libexample.so"

This patch could be done automatically by a shell script launched at the end of the config script.这个补丁可以通过在配置脚本末尾启动的 shell 脚本自动完成。 I have placed a complete working example in https://github.com/golosio/sharedcuda_autotools我在https://github.com/golosio/sharedcuda_autotools 中放置了一个完整的工作示例

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

相关问题 Makefile编译所有文件,即使更改是在单个c ++文件中完成的 - Makefile compiles all files, even though changes are done in a single c++ file 如果 Makefile 更改,则自动生成源文件 - Automake rebuild source file if Makefile changes Makefile将目录中的所有cpp文件编译为单独的可执行文件 - Makefile that compiles all cpp files in a directory into separate executable makefile编译所有文件,而不是最后编辑的文件 - makefile compiles all files instead of the last edited ones Visual Studio 2012始终会编译所有源代码文件 - Visual Studio 2012 always compiles all source code files Makefile编译所有文件,即使将.o文件放在其他文件中时文件未更改也是如此 - Makefile compiles all files even if file is not changed when .o files are placed in other floder 仅用于编译已更改文件的共享库的Makefile? - Makefile for shared library that only compiles changed files? autotools automake生成的makefile不起作用:make all-am - autotools automake generated makefile does no work: make all-am 所有文件的Makefile - Makefile for all files libboost _ *。so:无法识别文件:文件被截断使用libtool和automake动态链接以生成makefile时 - libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM