compiling a library?

Member
Posts: 194
Joined: 2009.02
Post: #1
My app uses libpng and even though I include the lib into my project, a computer still requires libpng to be installed separately on a computer before it will run my app. Is there someway to avoid this?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Link statically by compiling against libpng.a instead of a dynamic library. Don't install libpng; keep it contained within your library so you can be sure of what you're linking against and keep your project portable across computers without having to install it everywhere you go.
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #3
Yes static library should help. My advice: Stay away from dynamic libraries, they are nasty when it comes to being universal and linking them in correctly, leading to many bugs that just wont die. Most of you should know what I mean (If you used the #idevgames during the Sticky Event)... Sad
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #4
ThemsAllTook Wrote:Link statically by compiling against libpng.a instead of a dynamic library.


I don't understand what you mean by this, how exactly would I go about this?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #5
NelsonMandella Wrote:I don't understand what you mean by this, how exactly would I go about this?

What are you linking with at the moment? Are you compiling libpng yourself or using a prebuilt one? If the former, how are you compiling it? If the latter, where did your prebuilt one come from?
Quote this message in a reply
Member
Posts: 194
Joined: 2009.02
Post: #6
ThemsAllTook Wrote:What are you linking with at the moment? Are you compiling libpng yourself or using a prebuilt one? If the former, how are you compiling it? If the latter, where did your prebuilt one come from?

I guess I'm using a prebuilt one. Basically I just drag the libpng.a file, from the libpng folder which I downloaded(not sure exactly where I got it since it's been a few years), into the groups & files panel of my project- and though I have libpng installed separately on my computer, the app won't compile unless I actually include libpng.a into my project. And I have tried running the app on other computers, it won't run unless I install libpng separately.
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #7
It is extremely counter-intuitive, but the problem is that gcc (which Xcode uses) won't necessarily link against the library you have in your Xcode project. In your case it sounds as though it is dynamically linking against the installed version instead (which is why it only works if your user has it installed - dynamic linking doesn't include the library as part of your code).
Generally the easiest way to deal with this is to avoid installing third party libraries on your machine, and to not have dynamic libraries (.dylib) around when you want to use the static version. If you need to have the library installed for some reason, you can use compiler arguments to be more specific about what it should link against (but since I avoid doing that I can't tell you exactly how off the top of my head).
Quote this message in a reply
Post Reply