1

I am trying to re-build a simple GCC plugin (which builds fine on GNU Linux).

I am intending to compile the plugin using GNU GCC v4.6.3 which I have already installed under Mac OS X.

The Makefile contents are given below:

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

I am getting the following error:

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 compiler is built using the following configuration:

../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/
artless noise
  • 21,212
  • 6
  • 68
  • 105
Shahzad
  • 1,999
  • 6
  • 35
  • 44

1 Answers1

2

Had the same problem, hit this page without answers. Decided to continue digging. Found the answer on a Sourceforge page from 2008.

Instead of linking with gcc -shared ..., use gcc -dynamiclib -undefined dynamic_lookup ... So in your example,

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

should be replaced with

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

Also, found that this homebrew formula was actually able to install GCC 4.6 on Mac OS X 10.10.

Hannes Mühleisen
  • 2,542
  • 11
  • 13