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

image fails to run on Mac OSX 10.9 #16

Closed
vifino opened this issue Jul 6, 2014 · 20 comments
Closed

image fails to run on Mac OSX 10.9 #16

vifino opened this issue Jul 6, 2014 · 20 comments

Comments

@vifino
Copy link

vifino commented Jul 6, 2014

I was trying to use the image library, but this happens:

➜  ~  th -limage
> image.lena()
Wrong JPEG library version: library is 80, caller expects 62
/usr/local/share/lua/5.1/image/init.lua:115: attempt to index local 'a' (a nil value)
stack traceback:
    /usr/local/share/lua/5.1/image/init.lua:115: in function 'loader'
    /usr/local/share/lua/5.1/image/init.lua:247: in function 'load'
    /usr/local/share/lua/5.1/image/init.lua:1007: in function 'f'
    [string "local f = function() return image.lena() end ..."]:1: in main chunk
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/trepl/init.lua:510: in function </usr/local/share/lua/5.1/trepl/init.lua:452>  
> 

I have no idea how to fix that.

@clementfarabet
Copy link
Member

you must have upgraded your libjpeg, try re-installing image:

luarocks install image

?

@vifino
Copy link
Author

vifino commented Jul 6, 2014

I did with sudo luarocks --server=https://raw.githubusercontent.com/torch/rocks/master install image but still the same result :/

@vifino
Copy link
Author

vifino commented Jul 6, 2014

So, i reinstalled libjpeg via brew and reinstalled ( remove and install ) and still having the same issue.

@soumith
Copy link
Member

soumith commented Jul 6, 2014

Could you try a "brew cleanup" and then reinstall the image package. I've definitely seen the error before and it was because I installed a new version of libjpeg

@vifino
Copy link
Author

vifino commented Jul 6, 2014

Well, if I would not count the actual run, it seems like it has succeeded.
Still no change...

➜  ~  brew uninstall libjpeg
Uninstalling /usr/local/Cellar/jpeg/8d...
➜  ~  brew install libjpeg 
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.mavericks.bottle.2.tar.gz
######################################################################## 100,0%
==> Pouring jpeg-8d.mavericks.bottle.2.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/libjpeg.a
Target /usr/local/lib/libjpeg.a
already exists. You may want to remove it:
  rm /usr/local/lib/libjpeg.a

To force the link and overwrite all conflicting files:
  brew link --overwrite jpeg

To list all files that would be deleted:
  brew link --overwrite --dry-run jpeg

Possible conflicting files are:
/usr/local/lib/libjpeg.a
==> Summary
🍺  /usr/local/Cellar/jpeg/8d: 18 files, 780K
➜  ~  brew link --overwrite jpeg
Linking /usr/local/Cellar/jpeg/8d... 17 symlinks created
➜  ~  brew link --overwrite jpeg
Warning: Already linked: /usr/local/Cellar/jpeg/8d
To relink: brew unlink jpeg && brew link jpeg
➜  ~  sudo luarocks --server=https://raw.githubusercontent.com/torch/rocks/master install image
Password:
Installing https://raw.githubusercontent.com/torch/rocks/master/image-1.1.alpha-0.rockspec...
Using https://raw.githubusercontent.com/torch/rocks/master/image-1.1.alpha-0.rockspec... switching to 'build' mode
Cloning into 'image'...
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 22 (delta 1), reused 13 (delta 1)
Receiving objects: 100% (22/22), 1.64 MiB | 666.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.
Checking connectivity... done.
cmake -E make_directory build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/usr/local/bin/.." -DCMAKE_INSTALL_PREFIX="/usr/local/lib/luarocks/rocks/image/1.1.alpha-0" && make

-- The C compiler identification is AppleClang 5.1.0.5030040
-- The CXX compiler identification is Clang 3.4.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found Torch7 in /usr/local
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/luarocks_image-1.1.alpha-0-862/image/build
Scanning dependencies of target image
[ 25%] Building C object CMakeFiles/image.dir/image.c.o
Linking C shared module libimage.so
[ 25%] Built target image
Scanning dependencies of target jpeg
[ 50%] Building C object CMakeFiles/jpeg.dir/jpeg.c.o
Linking C shared module libjpeg.so
[ 50%] Built target jpeg
Scanning dependencies of target png
[ 75%] Building C object CMakeFiles/png.dir/png.c.o
Linking C shared module libpng.so
[ 75%] Built target png
Scanning dependencies of target ppm
[100%] Building C object CMakeFiles/ppm.dir/ppm.c.o
Linking C shared module libppm.so
[100%] Built target ppm
cd build && make install
[ 25%] Built target image
[ 50%] Built target jpeg
[ 75%] Built target png
[100%] Built target ppm
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lib/libppm.so
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lib/libjpeg.so
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lib/libpng.so
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lib/libimage.so
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lua/image/init.lua
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lua/image/lena.jpg
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lua/image/lena.png
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lua/image/lena_full.jpg
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lua/image/lena_full.png
-- Installing: /usr/local/lib/luarocks/rocks/image/1.1.alpha-0/lua/image/win.ui
Warning: Directory 'doc' not found
Updating manifest for /usr/local/lib/luarocks/rocks

image 1.1.alpha-0 is now built and installed in /usr/local/ (license: BSD)
➜  ~  th -limage                                                                               
> image.lena()
Wrong JPEG library version: library is 80, caller expects 62
/usr/local/share/lua/5.1/image/init.lua:115: attempt to index local 'a' (a nil value)
stack traceback:
    /usr/local/share/lua/5.1/image/init.lua:115: in function 'loader'
    /usr/local/share/lua/5.1/image/init.lua:247: in function 'load'
    /usr/local/share/lua/5.1/image/init.lua:1007: in function 'f'
    [string "local f = function() return image.lena() end ..."]:1: in main chunk
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/trepl/init.lua:510: in function </usr/local/share/lua/5.1/trepl/init.lua:452>  
> 

@vifino
Copy link
Author

vifino commented Jul 6, 2014

Even after many reboots and retries, nothing seems to have worked

@soumith
Copy link
Member

soumith commented Jul 6, 2014

"brew cleanup" was the key for me to fix this. If that didn't help, I'm not sure what else.

@vifino
Copy link
Author

vifino commented Jul 6, 2014

Hmmm... Thats bad.
I would really like to toy with this.
I guess that there is a way to get it working, but we dont know it yet :P

@JohnZed
Copy link

JohnZed commented Sep 25, 2014

I had a similar issue (actually problems with both libjpeg and libpng having bad versions). It turns out that I had the "UnixImageIO" framework installed in /Library/Frameworks/UnixImageIO.framework. Apparently, the build system was compiling against that framework (which includes jpeg version 62 and libpng 1.2), but linking against my homebrew libs at runtime. I removed the framework, uninstalled image and reinstalled it, then everything worked smoothly. I would also recommend running a command like:

find /usr/ /Library/ /opt/ /lib/ -iname "libjpeg*.dylib" 2>/dev/null

If you find a surprising copy of libpjeg where you don't expect it, try moving or deleting that copy. You may have some other totally random copy lying around in your path...

@laotao
Copy link

laotao commented Dec 16, 2014

@JohnZed is jpeg version 62 too new for torch7? When I try to install it (apt-get install libjpeg-dev), I always get this version on my debian machine:

dfs00104:/home/smt/gfx.js# apt-get install libjpeg-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libjpeg62-dev' instead of 'libjpeg-dev'
The following packages were automatically installed and are no longer required:
libtiffxx0c2 liblcms1-dev libexif-dev libjasper-dev libexif12
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
libjpeg62-dev
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/201 kB of archives.
After this operation, 492 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
libjpeg62-dev
Install these packages without verification [y/N]?

@marcinic
Copy link

marcinic commented Feb 1, 2015

I had a similar problem. Upgrading lua to 5.2.3 solved it for me.

@lefromage
Copy link

issue still there on MacOS Yosemite
th -limage -e "image.lena()"
Wrong JPEG library version: library is 80, caller expects 62

@allenwu5
Copy link

I had same problem in 10.10.2, and I try to upgrade the lua to Lua 5.3.0 to solve it, but the torch still run version 5.1.

@Atcold
Copy link
Contributor

Atcold commented Apr 22, 2015

I have the latest version of everything (brew, libjpg and image) and everything works just fine.
I guess we can close this issue.

@leocck
Copy link

leocck commented May 10, 2016

After trying many things, I solved this in torch only using PNG files

@nessig
Copy link

nessig commented May 30, 2016

-- Found JPEG: /Users/bakercp/anaconda/lib/libjpeg.dylib
-- Found ZLIB: /Users/bakercp/anaconda/lib/libz.dylib (found version "1.2.8")
-- Found PNG: /Users/bakercp/anaconda/lib/libpng.dylib (found version "1.5.18")
Pretty much what happened to me except it was getting built with my Postgres' libjpef.dylib. I just went into my bash profile and took that off my path where I was exporting it, then rebuilt with luarocks install image, and it worked after that! Check the logs when you run luarocks install image because thats where I was it was using a possibly out of date version of libjpeg. Strangely, my anaconda's libjpeg.dylib (which it linked too after I changed my PATH) works fine and built image without any problems.

@admercs
Copy link

admercs commented Jul 22, 2016

The solution of @JohnZed worked for me. This JPEG library was installed with GDAL and caused a conflict. Simply deleting it fixed the issue.

@ramsingla
Copy link

On my mac system the following solved the issue.

brew unlink jpeg
brew link homebrew/versions/jpeg6b
luarocks install image

after this the following command runs without issue

th -limage -e "image.lena()"

@davidavdav
Copy link

For me, I ran into similar problems with

luajit -limage -e "image.test()"
seed: 	1493905914
Running 41 tests
 1/41 CompressAndDecompress ............................................. [PASS]
 2/41 test_transformation_largeByteImage_vflip .......................... [PASS]
 3/41 CompressAndDecompressPNG .......................................... [WAIT]libpng warning: Application built with libpng-1.4.12 but running with 1.6.29
 3/41 CompressAndDecompressPNG .......................................... [ERROR]

...

CompressAndDecompressPNG
 Function call failed
/Users/david/src/torch/install/share/lua/5.1/image/init.lua:215: [write_png_file] png_create_write_struct failed
stack traceback:
	[C]: in function 'save'
	/Users/david/src/torch/install/share/lua/5.1/image/init.lua:215: in function 'compressPNG'
	/Users/david/src/torch/install/share/lua/5.1/image/test.lua:419: in function </Users/david/src/torch/install/share/lua/5.1/image/test.lua:416>
	[C]: in function 'xpcall'
	...s/david/src/torch/install/share/lua/5.1/torch/Tester.lua:477: in function '_pcall'
	...s/david/src/torch/install/share/lua/5.1/torch/Tester.lua:436: in function '_run'
	...s/david/src/torch/install/share/lua/5.1/torch/Tester.lua:355: in function 'run'
	/Users/david/src/torch/install/share/lua/5.1/image/test.lua:708: in function 'test'
	(command line):1: in main chunk
	[C]: at 0x010d8e6a00

which was finally resolved by following @JohnZed suggestion: search for stray libjpg files, and re-build luarocks install image. In my case, I had an unused old Mono.Framework on the system.

@tailsu
Copy link

tailsu commented Mar 9, 2018

Mono.framework causes CMake to produce an incorrect build due to libpng and libjpeg.

CMake has this funny parameter called CMAKE_FIND_FRAMEWORK which is set by default to FIRST. This means that CMake will first look for files first in all framework directories, and only then in regular include directories. Funnily enough Mono.framework contains the headers for libjpeg and libpng. So, CMake finds the headers in Mono, but the library in the regular install location, e.g. /usr/local/lib and therefore a version mismatch happens.

Mono is a known menace (for some time brew doctor warned if Mono is installed that builds may fail). You can see this behavior if you create a CMakeLists.txt file with the single line find_package(JPEG), run cmake . and take a look at the paths in the generated CMakeCache.txt file.

The fix that definitively worked for me was to check out the project manually, add set(CMAKE_FIND_FRAMEWORK LAST) to CMakeLists.txt before the find_package calls and then run luarocks make. This way CMake found the headers in the right folder.

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