Sxiv: Building on MacOS

Created on 26 Feb 2019  路  9Comments  路  Source: muennich/sxiv

Is it possible to build sxiv 25 on macos? It seems to depend on X11 library:

$ make
GEN config.h
CC autoreload_inotify.o
In file included from autoreload_inotify.c:19:
In file included from ./sxiv.h:27:
/usr/local/include/Imlib2.h:26:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
         ^~~~~~~~~~~~
1 error generated.
make: *** [Makefile:50: autoreload_inotify.o] Error 1

XQuartz is a thing and can be installed via a homebrew cask. For what it's worth, sxiv 1.3.2 is in homebrew and it does run with xquartz as a runtime dependency. But 1.3.2 does not have X11 as a build dependency and it is coming up on five years old.

I was able to clear the X11 build errors by (perhaps stupidly) editing all the libraries in /opt/X11/include/ with basically s#<X11#</opt/X11/include/X11#, but I was still not able to build because of sxiv build dependency on inotify.h:

$ make
CC autoreload_inotify.o
autoreload_inotify.c:25:10: fatal error: 'sys/inotify.h' file not found
#include <sys/inotify.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make: *** [Makefile:50: autoreload_inotify.o] Error 1

I don't know of a provider for inotify.h on macos. If anyone has suggestions, or has managed to build sxiv 25 on macos, please let me know.

Most helpful comment

That did it. Thank you!

I'll take a stab at getting the formula updated in homebrew.

All 9 comments

You can simply disable the autoreload feature by using the backend "nop", then sxiv will not depend on inotify. Just set "AUTORELOAD=nop" for make.

If you're more adventurous you can create a new autoreload-backend that uses the Mac OS FS Events api instead of inotify, to port this feature to mac.

Thanks. That got me to the next error:

$ make AUTORELOAD=nop 
CC autoreload_nop.o
CC commands.o
CC image.o
CC main.o
GEN version.h
CC options.o
CC thumbs.o
thumbs.c:96:32: warning: result of comparison of constant 4294967295 with expression of type 'Imlib_Load_Error' (aka 'enum _imlib_load_error') is always false [-Wtautological-constant-out-of-range-compare]
                                if ((err = r_mkdir(cfile)) == -1)
                                    ~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
1 warning generated.
CC util.o
CC window.o
LINK sxiv
ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:42: sxiv] Error 1

I'll be working on this now, but help is appreciated of course.

If you're more adventurous you can create a new autoreload-backend that uses the Mac OS FS Events api instead of inotify, to port this feature to mac.

That is ambitious for me. I don't know a whole lot about C. As it stands, getting the homebrew formula updated will be challenging since it seems so many changes to xquartz itself are necessary, and I don't know if they will be accepted either.

If I can get my own binary compiled (and leave a trail of breadcrumbs for others), that may have to be enough.

I too have grown very fond of sxiv and would love to find a way to get it to work on macos.

I got the same errors as you, but have withered my own error message to just

CC autoreload_nop.o CC commands.o CC image.o CC main.o GEN version.h CC options.o CC thumbs.o thumbs.c:96:32: warning: result of comparison of constant 4294967295 with expression of type 'Imlib_Load_Error' (aka 'enum _imlib_load_error') is always false [-Wtautological-constant-out-of-range-compare] if ((err = r_mkdir(cfile)) == -1) ~~~~~~~~~~~~~~~~~~~~~~ ^ ~~ 1 warning generated. CC util.o CC window.o LINK sxiv

by adding
LDFLAGS = -L/opt/X11/lib -lX11 -lpthread
to the makefile.

I tried to resolve the warning in thumb.c:96. This was the only real issue here. Thanks @oskarits for working out which LDFLAGS are needed to make it compile on Mac OS.

Hm, I still have this issue when I haven't hacked up the libraries provided by xquartz:

$ git clone [email protected]:muennich/sxiv.git && cd sxiv && make
Cloning into 'sxiv'...
remote: Enumerating objects: 75, done.
remote: Counting objects: 100% (75/75), done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 3572 (delta 32), reused 58 (delta 26), pack-reused 3497
Receiving objects: 100% (3572/3572), 1.53 MiB | 3.14 MiB/s, done.
Resolving deltas: 100% (2315/2315), done.
GEN config.h
CC autoreload_inotify.o
In file included from autoreload_inotify.c:19:
In file included from ./sxiv.h:27:
/usr/local/include/Imlib2.h:26:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
         ^~~~~~~~~~~~
1 error generated.
make: *** [Makefile:50: autoreload_inotify.o] Error 1

@muennich in your opinion is this a defect with xquartz?

Calling make AUTORELOAD=nop LDFLAGS=-L/opt/X11/lib LDLIBS=-lpthread should work.

$ make AUTORELOAD=nop LDFLAGS=-L/opt/X11/lib LDLIBS=-lpthread
GEN config.h
CC autoreload_nop.o
In file included from autoreload_nop.c:19:
In file included from ./sxiv.h:27:
/usr/local/include/Imlib2.h:26:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
         ^~~~~~~~~~~~
1 error generated.
make: *** [Makefile:50: autoreload_nop.o] Error 1

make AUTORELOAD=nop CPPFLAGS=-I/opt/X11/include LDFLAGS=-L/opt/X11/lib LDLIBS=-lpthread

That did it. Thank you!

I'll take a stab at getting the formula updated in homebrew.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

astier picture astier  路  17Comments

Knusper picture Knusper  路  4Comments

causes- picture causes-  路  3Comments

SammysHP picture SammysHP  路  3Comments

se7en-x230 picture se7en-x230  路  5Comments