1

我正在尝试重新构建一个简单的 GCC 插件(在 GNU Linux 上构建良好)。

我打算使用我已经在 Mac OS X 下安装的 GNU GCC v4.6.3 编译插件。

Makefile 内容如下:

GCC=/Users/xxx/compilers/gcc-4.6.3/install/bin/gcc
PLUGIN_SOURCE_FILES= plugin.c
PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
GCCPLUGINS_DIR= $(shell $(GCC) -print-file-name=plugin)
CFLAGS+= -I$(GCCPLUGINS_DIR)/include -I/Users/xxx/compilers/gcc-4.6.3/install/include - I/Users/xxx/compilers/gcc-4.6.3/gcc/ -fPIC -O0 -g3
plugin.so: $(PLUGIN_OBJECT_FILES)
    $(GCC) -shared $^ -o $@
plugin.o:plugin.c
    $(GCC) $(CFLAGS) -I$(GCCPLUGINS_DIR) -c $^ -o $@
clean:
    rm *.o *.so

我收到以下错误:

Undefined symbols for architecture x86_64:
"_register_callback", referenced from:
  _plugin_init in plugin_base.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [plugin_base.so] Error 1

GCC 编译器是使用以下配置构建的:

../gcc-4.6.3/configure --prefix=/Users/xxx/compilers/gcc-4.6.3/install/ --program-suffix=-4.6.3.x --enable-languages=c,c++ --disable-multilib --enable-cloog-backend=isl --with-gmp=/Users/xxx/compilers/gcc-4.6.3/install/ --with-mpfr=/Users/xxx/compilers/gcc-4.6.3/install/ --with-mpc=/Users/xxx/compilers/gcc-4.6.3/install/ --with-ppl=/Users/xxx/compilers/gcc-4.6.3/install/ --with-cloog=/Users/xxx/compilers/gcc-4.6.3/install/
4

1 回答 1

2

有同样的问题,点击这个页面没有答案。决定继续挖。在2008 年的 Sourceforge 页面上找到了答案。

gcc -shared ...在您的示例中使用gcc -dynamiclib -undefined dynamic_lookup ... So而不是与 链接,

$(GCC) -shared $^ -o $@

应该替换为

$(GCC) -dynamiclib -undefined dynamic_lookup $^ -o $@

此外,发现这个自制公式实际上能够在 Mac OS X 10.10 上安装 GCC 4.6。

于 2014-11-04T14:05:31.320 回答