Using Libraries in X Code

Discussion in 'Mac Programming' started by vatel, May 10, 2006.

  1. vatel macrumors member

    May 6, 2005
    I am compiling C++ command line apps in X Code, and I haven't figured out how to link a library file to the project other than to import them as source files. In the project info box under 'Build' you can specify library search paths. But then I don't see any way to specify the names of the libraries you need to link to.

    Please enlighten me. :confused:
  2. AlmostThere macrumors 6502a

    For a specific app:

    Targets -> Your Target -> Link binary With Executables -> Right Click -> Add ... -> Existing Files.

    Navigate to the location of the library and click OK. Use Shift-Apple-G to open /usr and other Unix directories.

    IIRC, you used to be able to drag and drop the .dylib files from Finder into the project, but I don't seem to be able to do this anymore (Xcode 2.2). The library will appear under groups and files, and can be dragged to whichever target requires it.

    It is also worth checking to see if there is a Framework that covers you library - this includes all the headers, libraries and other resources you need.

    [Edit: I guess this is what you are doing already. What is wrong with it?]
  3. vatel thread starter macrumors member

    May 6, 2005
    This is what I was doing, although I didn't know how to use the project browser as you indicated, I was just dragging and dropping. The main reason I don't like that approach is that my libraries then become linked, in a deletable way, to my project. It just doesn't seem smart (safe)

    I did find that in the inspector under Build, you can add the gcc command line flags for libraries under the Other Linker Flags (ie: -llibraryname)

    My programs are models, and I use various open source libraries for ODE solvers and thermo/chemistry models, so these aren't things that exist in frameworks, and in fact even where there is a framwork (ie: Framework accelerate replaces libblas.a) since after debugging I'll be running these files on a remote Unix-based machine, I prefer to keep everything as machine independent as possible. I just like to use XCode as a debugging environment.

    Thanks though, I've been trying to figure this out for months and it just came right after I posted to the forum.

Share This Page