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

Compile failure with USE_COCOA flag #48

Closed
erasmospunk opened this issue Aug 27, 2013 · 11 comments
Closed

Compile failure with USE_COCOA flag #48

erasmospunk opened this issue Aug 27, 2013 · 11 comments

Comments

@erasmospunk
Copy link

Hi,

Firstly, thumbs-up for this util!

I have a problem building from source when using USE_COCOA=1

fatal error: 'CoreGraphics/CoreGraphics.h' file not found

(in v2 there is an extra error in the Makefile)

The solution is to change the import in rwpng_cocoa.m:

-#import <CoreGraphics/CoreGraphics.h>
+#include <ApplicationServices/ApplicationServices.h>

Want a pull request to fix this issue?

p.s. why the colors appear a bit desaturated when using the cocoa build? Something to do with the color profiles? Check here http://dabblet.com/gist/6351700

@erasmospunk
Copy link
Author

Also I don't know if it is related with this issue but the official CLI builds from http://pngquant.org/ are giving me segmentation fault and "illegal instruction: 4" in another machine. Both are using OS X 10.7, it works just fine in 10.8.

@kornelski
Copy link
Owner

It looks like your compiler doesn't have Cocoa headers in search path. I'm not sure how to make that work, because clang on my system (with xcode commandline tools) doesn't require any extra arguments to see CoreGraphics headers.

Can you compile this?

clang -c rwpng_cocoa.m -o rwpng_cocoa.o -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/usr/local/include -I/opt/X11/include

#import is the preferred method of inclusion in Objective-C, and methods that rwpng_cocoa.m uses are part of CoreGraphics, so I think this line is correct.

The change in saturation is due to color profile support in Cocoa. With stock libpng pngquant can't support color profiles, and dropping of color profiles often increases saturation. With Cocoa it loads images as sRGB and saves them tagged as sRGB, so the less saturated version is actually more accurate representation of the image.

I've rebuilt the executables with -mmacosx-version-min=10.6 passed to the linker. Did that fix the problem on 10.7?

@erasmospunk
Copy link
Author

The -mmacosx-version-min=10.6 did the job, the bin from pngquant.org now works! Before you were using -mmacosx-version-min=10.7?

I managed to compile rwpng_cocoa.m but I had to change -I/opt/X11/include to -I/usr/X11/include. What happens with Mountain Lion (or Mavericks) that don't have X11 installed by default, the compilation will fail?

It also worked by installing with Homebrew libpng and using -I/usr/local/opt/libpng/include.

Regarding the CoreGraphics.h issue I based on this solution http://stackoverflow.com/a/4173621/1183663, my experience with Objective-C is minimal. Changing #include to #import also worked:

-#import <CoreGraphics/CoreGraphics.h>
+#import <ApplicationServices/ApplicationServices.h>

I don't know why it cannot find CoreGraphics.h by default, I have the latest Xcode and the command line tools installed.

@kornelski
Copy link
Owner

I've previously only specified OS version in compiler flags, rather than linker flags.

It's odd, but it seems that OS X doesn't have public libpng. I'm haven't checked whether X11 lib directory exists on stock OS X. If it doesn't, then compilation will fail.

@erasmospunk
Copy link
Author

Just tested with Mountain Lion with only X Code and indeed it fails to compile. There is a directory /usr/X11/lib folder with a bunch of dylibs (libpng is also there) but no include folder.

The solution seems to be to install xquartz or libpng with Homebrew.

@kornelski
Copy link
Owner

Do you have png.h anywhere else? (locate /png.h or find / -name png.h)

@erasmospunk
Copy link
Author

hmmm, this what I found on the Mountain Lion system:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/include/libpng15/png.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/include/png.h

@sindresorhus
Copy link

Nothing on 10.8 (without X11), except for the one i installed with Homebrew...

@kornelski
Copy link
Owner

Yeah, so that's a pretty sad state. Cocoa has lousy support for saving PNG, so I can't do much without libpng anyway.

@sindresorhus
Copy link

@pornel can you include libpng in the build so people don't have to fetch external dependencies?

@kornelski
Copy link
Owner

The Mac binaries on pngquant.org are statically linked and don't require external libpng.

Inclusion of png.h in pngquant repository would be controversial.

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

No branches or pull requests

3 participants