Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static library will not have any monitor type available #142

Closed
Andrepuel opened this issue Nov 6, 2016 · 4 comments
Closed

Static library will not have any monitor type available #142

Andrepuel opened this issue Nov 6, 2016 · 4 comments
Assignees
Milestone

Comments

@Andrepuel
Copy link

The way that monitor types are registered will not work with static libraries. The technique of creating a static object and inserting code in its constructor does not work with static libraries because the linker will discard any symbol that is not used, since no symbol from the file that contains the static constructor is used, the linker assumes it is safe to remove the static construtor at all.
In other projects I've noticed that just by injecting a fake dependency to any function of the file that contains the static constructor will force the linker to include the static constructor. But you would lose the conveniency of easily inserting new monitors to the project.
IMHO I don't think auto registrar should be used at all.

@biodranik
Copy link

I'm also stuck with this issue: monitors are not detected in statically built fswatch binary (Ubuntu).
I found the following workaround:

  1. Use $ make V=1 to see verbose output
  2. Replace final linker command

$ clang++ -std=gnu++11 -g -O2 -Wall -o fswatch fswatch.o ../libfswatch/src/libfswatch/.libs/libfswatch.a -lpthread

by

$ clang++ -std=gnu++11 -g -Os -Wall -o fswatch fswatch.o -Wl,-whole-archive ../libfswatch/src/libfswatch/.libs/libfswatch.a -Wl,-no-whole-archive -lpthread

Notice the -Wl,-whole-archive parameter. If you also add -static linker option you will get completely independent static binary (without local .so dependencies).

@noahfriedman
Copy link

I had to do something similar for OS X as of commit c7d8949
Running make V=1 I see this snippet:

Making all in src
clang++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I../..  -I../../libfswatch/src -DLOCALEDIR=\"/usr/local/share/locale\"   -g -O2 -Wall -c -o fswatch.o fswatch.cpp
/bin/sh ../../libtool  --tag=CXX   --mode=link clang++ -std=gnu++11  -g -O2 -Wall   -o fswatch fswatch.o ../../libfswatch/src/libfswatch/libfswatch.la  -lc -lpthread
libtool: link: clang++ -std=gnu++11 -g -O2 -Wall -o fswatch fswatch.o -Wl,-bind_at_load  ../../libfswatch/src/libfswatch/.libs/libfswatch.a -lc -lpthread -framework CoreServices

I changed -Wl,-bind_at_load to -Wl,-all_load in order for the monitors to work.

@emcrisostomo
Copy link
Owner

I agree this is complexity that does not pay us back with any meaningful advantage: I'm removing the monitor registration logic.

@emcrisostomo
Copy link
Owner

It has been closed in master and it will be released shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants