2014-08-30 38 views
4

最新版本的GNU-Make http://www.gnu.org/software/make/ 提供了许多高级功能,其中包括许多有用的功能。 (...)的支持动态加载的对象系统,你可以写 任何语言在自己的分机(可被编译成 这样的对象),并加载它提供扩展能力... http://www.gnu.org/software/make/manual/make.html#Loading-ObjectsGNU-make 4.运行“加载动态对象”的示例

我试图运行下面的简单例子($(hello string)函数)。它起作用,如果我第一次编译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 [email protected] $< 

./hello.c:

#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. 

我如何能与 '负荷' 运行这个例子指令?

+0

仅供参考:我刚刚将我的问题发布到make-help邮件列表。 – Pierre 2014-08-30 17:06:49

+0

不应该'全部'只取决于'hello.so'? – 2014-08-30 18:36:20

+0

试试'load。/ hello.so';因为'dlopen'处理没有'/'的特殊路径;也'全部'应该取决于'hello.so' – 2014-08-30 18:39:16

回答

2

我评论建议使用

-load hello.so 

,而不是仅仅load hello.so;这与在Makefile中使用-include类似。

的逻辑是:make插件一般都以为你会使用它们(经常运行一些make之前退出,你会在顶级Makefile使用递归之作,如运行$(MAKE) -C subdir,并确保插件确实存在,当你运行$(MAKE) -C subdir

如果在解析-load hello.sohello.so不存在,那么GNU make将忽略该指令。 (我不确定你想要一个真正的插件)。

我仍然认为make插件通常不应该由Makefile这是load - 他们。

我也认为使用Guile扩展名make比使用插件更明智。