1.Use xcode4 to create a work space, and then add two projects. One is to compile the Lib project (the target is a static library), and the other is to use this Lib for common IOSProgramProject.
Now we can think that the two projects are of the same level. It has nothing to do with it, but they are organized together by spam X4 using work space.
2.First, complete the Lib project and pay attention to the following:
2-1. Confirm the header file you want to export:
See, of course, public.
2-2. Set the installation path of this lib
The product of this lib project, static library, and the final installation path may depend on the spam X4 spam preference setting: locations. therefore, it may be installed to the derived data path or the path specified by our target. to make it the same in various cases, you need to set "installation directory" in the compilation settings to "$ (built_products_dir )". in this way, the compiled static library product can be found at a specific position. this location is the common directory of products compiled by various projects in this work space. at the same time, we also need to set the "Skip install" item for compilation in this lib project to "yes ", in this way, we can avoid the accidental installation of lib to "/usr/local/lib" (try to know where the "unexpected" directory is ).
2-3. Set the path of the Public header file.
That is to say, it is impossible to generate lib (*. A file). We also need header files used externally. The path of this header file should be set here.
Set the "Public headers folder path" of the Lib project compilation option to "$ (target_name)". In this way, the header file is in this path: $ (built_products_dir)/target_name/XX. h
Remember: This is the external header file used by a project using this Lib. A project needs to "see" the path of this header file. # include/import "XX. H ".
3.Start the whole project of the common IOS program using this Lib ".
That is, a project mentioned in 2-3 ".
3-1. click the target of the project and add "link binary with libraries" in the build phases project. the pop-up box is probably as follows: select the Lib in our workspace.
The result is as follows:
3-2. Add the search path for the external header file of the static library.
Build settings/user header search paths, add $ (built_products_dir), and select the previous hook-recursively traverse the subdirectories in the path.
Do you know why this is set? Because we set "that" in 2-3.
Now we can see the path of the external header file of Lib in this project, so you can use # include/import "XX. H.
It is important to have such a paragraph here. Let's take a look. No translation:
When using a static library which has des categories we will also have to add the "-objc" flag to the "other linker flags" build setting. this will force the linker to load all objective-C classes and categories from the library. if the library contains only categories "-all_load" or "-force_load" may be needed as well. see Technical Q & A qa1490 for a more detailed explanation of these settings.
3-3. Configure the scheme of the project.
Add lib under edit scheme \ build \ targets. Remember to drag this lib to the top.
Okay. Finished.
Summary: in fact, workspace is equivalent to the Vc solution. Yes, it is estimated that a spam product personnel is the reference vs20xx. It is still self-righteous to carry out micro-innovation.
There is a tangle of strange points in the process above. It is said that it is also a bug of garbage X4. it's not a big deal, so it's hard to describe it here. that is to say, the Lib of birthdate may be red, and the find in finder cannot be found by right-clicking. actually, there is. it is not described here.
Supplement on April 9 --
The above problem may still occur in xcode4.2.1, which is mentioned in the previous article. I didn't expect to be able to stop it .. The reason is finally found. the following details:
Wish the xcode4 product manager a day!
Well, as a poor person, I certainly use a simulator to compile it.
View the scheme menu at the top of the Workspace:
Two projects: addressbooklib is a static library project, and userapp is a project that calls this static library.
The iPhone 5.0 simulator is selected for both projects.
Set the activity project as userapp, as shown in the preceding figure. (A check is made before userapp)
Compile (I have to clean it before each compilation,Wish the xcode4 product manager a day!), The prompt is succeeded. But Nima, then again prompted that the header file could not be found!
I have set the search path: User header search paths: $ (built_products_dir:
The path is build/debug-iphoneos/
Now, I will manually delete all the files under build/products, and then compile the files. By the way, in order to prevent confusion, please be honest and clean first (the following descriptions are all for the first clean to compile,Wish the xcode4 product manager a day!). Compilation may fail! This is a real failure. An error is reported, indicating that no header file is running! It's okay. I grabbed command + B and pressed it several times. Well, the compilation was successful. (Wish the xcode4 product manager a day! No more.) Then a red error will be prompted: the header file cannot be found. It's okay. At least it can run correctly.
Well, let's see what else is added to build/products: the/debug-iphonesimulator/folder contains my static library, static library header file, and userapp. In this case, everything is normal. There are all these files and header files, but unfortunately, the above picture shows that the path is build/debug-iphonesos, not the poor-my-iphonesimulator!
In order to further confirm my guess, I will delete all the files under build/products, and set the activity project as my static library. My colleagues will select iOS device, for example:
Compile the static library. Then let's take a look at what is added to build/products:/debug-iphoneos/folder, which contains static libraries and header files.
Well, immediately set the activity project back to userapp (note that the poor I set the device to the iPhone 5.0 simulator again), compile, O, and I will not report any errors. Everything is normal. Why? Because/debug-iphoneos/is available under build/products, it contains the header file and static library.
The cause is found. userapp's user header search paths is $ (built_products_dir ), the final xcode4 should be resolved to debug-iphonesos or debug-iphonesimulator based on whether the device or simulator is selected! (You may have questions about how to add a products folder in the middle)
Well, to sum up, we have to put a tail under xcode4 in the future for joint Editing: first, compile Lib for iOS device and then compile userapp for iPhone 5.0 simulator. (If you can set them separately, but you cannot set them, both of them will change)
Or: Buy a device.IOS device is okay.
Or: manually copy the header file to the project directory of userapp... Speechless. What is your use of xcode.
(The first two methods are recommended .)
Refer:Http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#background