2014-08-30 43 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比使用插件更明智。