Statically link cilk library on Mac with gcc

353 views Asked by At

I'm trying to statically link the cilk library to my program, in order to be able to run the executable on environments that don't have the cilk libraries installed (since it is not so common).

Here is the best I could come up with:

cilkc -Ofast -Wextra -pedantic -fwhole-program -flto -msse4.2 -m64 -lm -mtune=generic -funroll-loops -finline-functions -ffast-math -lpthread -lz -DUSE_GCC -Wc,-std=c99 -Wc,-pipe -DUSE_FILE32API /usr/local/lib/libcilk.a /usr/local/lib/cilk/libcilkrt0.a src/all.c src/CilkSearch.cilk

As stated, i manually link libcilk.a and libcilkrt0.a to prevent gcc to link to the shared libraries. This makes the program size increase from 266Kb to 344Kb, which makes me think the static linking succeeded.

Sadly, though, when i inspect with otool the dependencies of my executable, i get:

bin/hayabusa:
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/local/lib/libcilk.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/opt/local/lib/gcc47/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

I understand zlib and gcc, which i didn't statically link yet. But why is the libcilk.0.dylib dependency still there if i manually linked to libcilk.a?

I also actually try to run the program on another computer, but at startup the program terminates complaining that /usr/local/lib/libcilk.0.dylib cannot be loaded.

So my question is, explicitly specifying the .a to gcc is not enough to drop the specified library dependency? What else should I do to have my libcilk linked statically and not loaded at runtime?

I already know about the -static option, but i don't want every library including system ones to be statically linked, I only want the cilk library to be statically linked.
Is this possible at all?

1

There are 1 answers

2
user2062850 On

We explicitly do not support linking the Cilk runtime as a static library. The explanation of why is in our FAQ at http://www.cilkplus.org/faq/there-version-intel-cilk-plus-provides-statically-linked-libraries . I understand that you're building an application, not a library. But if you link your application against some other library which also uses Cilk Plus, you risk a combinatorial explosion of threads which can hurt performance.

That's not to say that it cannot be done. But if you run into any problems, they must be reproduced with the dynamically linked runtime before we will consider them.

- Barry Tannenbaum
  Intel Cilk Plus Runtime Developer