2
votes

I'm trying to make a basic image processing program in Rust for a course project, but I'm having trouble figuring out how to start. I've looked into using rust-png, but I'm having difficulty understanding how to use it as an external library as I'm unsure if I'm linking the files correctly. When I compile lib.rs to create the crate I get this error.

error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'main' 'main.o' '-lmorestack' '-nodefaultlibs' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libnative-83574243-0.11-pre.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-aad93cea-0.11-pre.rlib' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-8f65d5a8-0.10-pre.rlib' '-L/Users/brianuosseph/Desktop/Course_Work/Spring_2014/CS_4414/final_project/.rust' '-L/Users/brianuosseph/Desktop/Course_Work/Spring_2014/CS_4414/final_project' '-lpng' '-lz' '-lshim' '-lSystem' '-lc' '-lm' '-Wl,-rpath,@loader_path/../../../../../../../usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/brianuosseph/Desktop/Course_Work/Spring_2014/CS_4414/final_project/.rust'
ld: library not found for -lshim
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error

I'm currently running on the 0.11-pre-nightly build of Rust.

For the project I'm just going to start with using libpng wrappings, but in the future I'd prefer to start from scratch and create my own PNG library for Rust. However, I simply don't know where to begin or if there are any existing image libraries for Rust, be it PNG, GIF or JPEG. Know of any?

1
It looks like that in order to compile rust-png you have to run ./configure first, then run make. The error in your question will go away (shim library seems to be a very simple library compiled out of shim.c file in the same repository). - Vladimir Matveev
When trying to compile 'shim.c' or running 'make' I run into the same error ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Any way I can get the needed symbols? - riban
That's strange. I just have git cloned the library, ran ./configure, edited Makefile to set path to Rust compiler and executed make. Everything compiled just fine, I've got .rlib and .so libraries. Maybe the library is just not adapted for Mac OS X. - Vladimir Matveev

1 Answers

2
votes

I wrote a wrapper for LodePNG:

https://lib.rs/lodepng

it doesn't need any external libraries (besides statically-linked lodepng.c, which it includes), so you shouldn't have any problems linking it.


I've also written bindings and makefile for MozJPEG, which gives you a low-level libjpeg API:

https://lib.rs/mozjpeg-sys