0

I'm trying to compile a few .c files that used msgpack-c functions into a shared library. I have the following Makefile:

MSGPACK_CS = msgpack.c

CFLAGS = -std=c99

MSGPACK_OBJECTS = $(subst .c,.o,$(MSGPACK_CS))

MSGPACK_LIBS = msgpack.so

all: $(MSGPACK_OBJECTS) $(MSGPACK_LIBS)

%.o: %.c
    $(CC) -c -shared -fPIC $(CFLAGS) $<

$(MSGPACK_LIBS): $(MSGPACK_OBJECTS)
    ld -Lmsgpack/.libs -share -o $@ $(MSGPACK_OBJECTS) -lmsgpack

I can compile a program that uses msgpack without problem, but this gives me the following error:

msgpack.o: In function `msgpack_pack_int64':
/usr/local/include/msgpack/pack_template.h:373: undefined reference to `__stack_chk_fail_local'
ld: msgpack.so: hidden symbol `__stack_chk_fail_local' isn't defined
ld: final link failed: Bad value

Apparently the linkage process isn't going well, but I don't know what is wrong. What can I do?

petermlm
  • 930
  • 4
  • 12
  • 27

1 Answers1

1

Try linking with the gcc driver instead of calling ld directly. ld doesn't know about the gcc support libs that are needed for the C runtime:

gcc -Lmsgpack/.libs -shared -o $@ $(MSGPACK_OBJECTS) -lmsgpack

If this still doesnt't work, you might need to add -fno-stack-protector to your CFLAGS to supress runtime stack checking.

mfro
  • 3,286
  • 1
  • 19
  • 28
  • Thank you, this worked just fine! Just one thing, the '-share' flag is actually '-shared', but it does what is expected, which is to create a shared library. Again, thanks – petermlm Apr 02 '15 at 13:20
  • 1
    Thanks. I fixed that "-shared"-typo. My fault. – mfro Apr 02 '15 at 15:47