Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Building on MacOS #350

Closed
rpdelaney opened this issue Feb 26, 2019 · 9 comments
Closed

Building on MacOS #350

rpdelaney opened this issue Feb 26, 2019 · 9 comments

Comments

@rpdelaney
Copy link

rpdelaney commented Feb 26, 2019

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.

@sdx23
Copy link
Contributor

sdx23 commented Feb 26, 2019

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.

@rpdelaney
Copy link
Author

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.

@oskarits
Copy link

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 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.

xyb3rt added a commit that referenced this issue Mar 15, 2019
Warning generated on MacOS, reported in issue #350.
@xyb3rt
Copy link
Owner

xyb3rt commented Mar 15, 2019

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.

@xyb3rt xyb3rt closed this as completed Mar 15, 2019
@rpdelaney
Copy link
Author

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

$ git clone git@github.com: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?

@xyb3rt
Copy link
Owner

xyb3rt commented Mar 24, 2019

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

@rpdelaney
Copy link
Author

$ 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

@xyb3rt
Copy link
Owner

xyb3rt commented Mar 25, 2019

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

@rpdelaney
Copy link
Author

That did it. Thank you!

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

neg-serg pushed a commit to neg-serg/sxiv that referenced this issue Apr 5, 2020
Warning generated on MacOS, reported in issue xyb3rt#350.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants