最新版本的GNU-Make http://www.gnu.org/software/make/提供了许多高级function,包括许多有用的function。 (…)在支持dynamic加载对象的系统上,你可以用任何语言编写你自己的扩展(可以编译成这样一个对象)并加载它来提供扩展的function… http://www.gnu。组织/软件/制作/手动/ make.html#加载对象
我试图运行下面的简单示例($(hellostring)函数)。 它起作用,如果我第一次编译hello.so。 但是如果我按照这里提供的例子运行它(带有一个load
指令) http://www.gnu.org/software/make/manual/make.html#Loading-Objects,它是行不通的。 Make4安装在当前目录中。
./Makefile:
all: echo $(hello world) load hello.so hello.so: hello.c $(CC) -shared -I./include -fPIC -o $@ $<
。/你好ç:
#include <stdlib.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <gnumake.h> int plugin_is_GPL_compatible; char * hello(const char *nm, unsigned int argc, char **argv) { int len = strlen (argv[0]) + 7; char *buf = gmk_alloc (len); sprintf(buf,"Hello %s",argv[0]); return buf; } int hello_gmk_setup () { gmk_add_function("hello", hello, 1, 1, 1); return 1; }
运行示例:
./bin/make -v GNU Make 4.0 Built for i686-pc-linux-gnu $ ./bin/make Makefile:4: hello.so: cannot open shared object file: No such file or directory Makefile:4: *** hello.so: failed to load. Stop.
我怎样才能用“load”指令来运行这个例子?
我建议在评论中使用
-load hello.so
而不是只load hello.so
; 这与在Makefile
使用-include
类似。
逻辑上是make
插件通常在你运行一些使用它们之前退出(通常,你会使用递归make,例如,在顶层Makefile
运行$(MAKE) -C subdir
,并确保插件确实存在运行$(MAKE) -C subdir
)
如果在解析-load hello.so
时hello.so
不存在,那么GNU make
会忽略该指令。 (我不确定你想要一个真正的插件)。
我仍然认为,通常不应该由load
它们的Makefile
构建插件。
我也相信在make
中使用Guile扩展比使用插件更明智。