在Mac OS X 10.9.4上构建GCC插件

时间:2014-09-13 17:50:40

标签: macos gcc plugins linker gnu-make

我正在尝试重新构建一个简单的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/

1 个答案:

答案 0 :(得分:2)

遇到同样的问题,点击此页面没有答案。决定继续挖掘。在Sourceforge page from 2008找到了答案。

使用gcc -shared ...而不是与gcc -dynamiclib -undefined dynamic_lookup ...关联 所以在你的例子中,

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

应替换为

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

此外,发现this homebrew formula实际上能够在Mac OS X 10.10上安装GCC 4.6。

相关问题