简体   繁体   中英

Proper Xcode settings

I have Xcode 5.1.1 and am trying to create a project to build my application for the OSX.

The application is structured as follows:

I have a static link library (.a), 2 dynamic link libraries (.dylib), which depends on the static one, 1 dynamic library (.dylib) that depends on those 2 dynamic libraries and the executable binary which uses that 1 dynamic library (.dylib).

In the Xcode I changed the output directory by going to "Xcode ->Preferences->Derived Data (Advanced)". There I selected "Custom->Relative to Workspace". This way everything will be kept in one place.

Now here is the problem: I'm having difficulties adding ".a" library to one of the ".dylib".

I selected a target in the upper left corner of the Xcode window in order for the build properties to appear. Then in the "Search" window I typed "other linker flags". Then I selected "Other Linker Flags" in the "Build Settings Window" and typed "-ldbinterface.a". Trying to compile I got an error: "ld: library not found for -llibdbinterface.a".

Next I tried to add the following line: "-L/Users/igorkorot/dbhandler/dbhandler/Build/Products/Debug" to "Other Linker Flags". But I got exactly the same error.

Next I tried to remove those 2 lines and to add just "libdbinterface.a" to "Other Linker Flags". This time I got: "clang: error: No such file or directory".

For the reference, that file does exist:

Igors-MacBook-Air:Debug igorkorot$ pwd
/Users/igorkorot/dbhandler/dbhandler/Build/Products/Debug
Igors-MacBook-Air:Debug igorkorot$ ls -la
total 384
drwxr-xr-x  3 igorkorot  staff     102 Mar 26 18:37 .
drwxr-xr-x@ 3 igorkorot  staff     102 Mar 26 18:36 ..
-rw-r--r--  1 igorkorot  staff  193528 Mar 26 18:37 libdbinterface.a

What am I doing wrong? What is the proper way of adding the static library in my case?

Thank you.

If the filename of the static library is:

libdbinterface.a

Then you need to specify it to the -l linker option by stripping the leading lib and the file extention ( .a ):

-ldbinterface

However I see trouble ahead in that I think you might find a duplicate symbol definition (linker error or a runtime issue) as the symbols from the static library will appear in both dynamic libraries.

There are two ways of solving that:

  1. Make the static library dynamic.
  2. Compile the dynamic libraries with Symbols Hidden By Default set to Yes (under Build Settings > Code Generation ) and only expose the symbols you want to export by annotating the methods using:

     __attribute__ ((visibility ("default")))

which you would normal do with a macro:

#define EXPORT __attribute__ ((visibility ("default")))

and in the function/variable declarations only use this form:

extern EXPORT void aFunction(int someParam);

Note: You don't need to do this for Objective-C classes, but you might need to for C++ (I cannot remember).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM