Getting XCode to include, compile and link existing (C++) codebase in XCode 4.3(.1) - iphone

I'm trying to 'import' my existing C++ codebase into my XCode iOS project.
Problem is, xCode won't compile (and therefore not link) my code.
This is what I've done so far:
File > Add files to "Project". I don't tick 'Copy files' since it's a shared codebase for multiple platforms and multiple copies of source code is not an option.
I've added appropriate path to the "Header Search Path" project settings. Including header files works, I can #include "stuff.h" from my Objective-C++ (.mm) file.
However, I can't find any way of actually telling XCode to compile the .cpp files?
A few points:
I'm not looking for a way to pre compile it into a library and linking that way
The project is a standard iOS Objective-C project. The C++ code is called from it (that's not a problem)
Update
I've added the codebase directory to the target's "Compile Sources". I actually have to click "Add other..." in the dialog that pops up, since I can't select the directory reference to my codebase.
When I add it, XCode asks me if I want to "Create external build system project". I leave it ticked and the two fields with the default values "/usr/bin/make" and "$(ACTION)". However, my codebase doesn't get compiled during the build. Do I have to write my own Makefile ?
If I don't select "Create external build system project" then a directory reference is created under the target, but not compiled during the build and a warning is emitted:
warning: no rule to process file '$(PROJECT_DIR)/../codebase'
of type folder for architecture i386

Even if you don't check Copy Files you have to check Add to Targets when adding the files to the project.
If you forgot to do that, you can select the target, go to the Build Phases tab and add the files to Compile Sources.

If you go to your Targets -> Build Phases -> Compile Sources -> "+" -> "Add Others" -> (select your external source folder) -> Select: Create Group for any added folders -> Unchecked: Copy items into destination.
Now your folder will be in XCode, mimic the structure. If you add source files to that folder in XCode the source files will be added to your external source directory just fine. So the ease of using multiple IDEs and having to manage source linkage is solved.
The catch. You still have to manually add files into the "Compile Sources" area. This is rather simple. Just click and drag your source files from the group directory in XCode right into the Compile Sources window. So there is an extra step when you add a source file now. Forgetting to add them to the Compile Sources window will yield unresolved symbols compile errors.

Related

Unable to get xcode project to index appropriate directories

So I had to delete my project and then reclone it from my repository, but when I clone down the project and I open it, other files from some time ago show in there, how is this possible?
Example this is the cloned directory:
But when I open the project, it shows this project structure:
Also it produces the following error when attempting to build the project:
Build input file cannot be found: '/Users/Development/Projects/MapGlider/Application/Utilities/Extensions.swift'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?
All help will be appreciated!
The structure of the project as you see it in Xcode is a combination of file system + information about your project in YourProject.xcodeproj/project.pbxproj file. So you have a mismatch between file system and that file, which is typically a result of inaccurate checkin (for example some changes were done directly in file system, and the project was not updated), or a bad merge (developer A did everything right, developer B, or even the same developer on a different branch, overrode those changes incorrectly).
So what you need to do is to fix those errors one by one.
Note: the steps below assume the project is in your control. If you are using some script or tool to generate the project, you will have to address those issues via that tool or script instead.
First, fix the project structure:
Make sure Inspectors on the right side in Xcode are open. Choose File inspector tab
Focus on a folder inside Xcode, and check Name, Location and Full Path of the folder. Especially notice the Full Path, if it's incorrect, change it to a correct one. Here's the example how. Repeat for all folders and files you want to have in the project
Delete all folders and files you don't want to have in the project from Xcode. For example you can delete Extensions which appears as a file in your project, while it's actually a folder. Typically while deleting you should be able to delete them from file system as well if it exists, but if not, you can double check in file system and delete files / folders from there as well.
Add folders and files missing from the project if needed. Follow Add existing files and folders to a project section in the linked page.
Once you cleaned up the project, you need to review / fix all your project targets:
To fix the Project targets
Try to build each target. If it succeeds, most likely everything is resolved (although watch out for runtime errors for resource files - so you may need to test your app to ensure nothing is missing too).
If building a target fails, you will need to see why. For example
if file is missing from the target, but you already added it to the Xcode project, you can add it to the target (see this page).
if file is missing from the target and is not visible in Xcode, go back to step 4 of the previous procedure and add those files to Xcode project, and then add them to the target
if a file is nowhere to find and is not needed, you can delete it from target. If it was needed, then... well, you have a problem and need to locate your missing code in your source repo or rewrite it.

Iphone Linker Error – “class.o for architecture i386" confused?

I am getting error Linker Error – class.o for architecture i386 on xcode project while i try to build the project. on my project i have used some third party framworks as well. any solution for this ??
To break down this issue here are some tips.
1>Make sure to included the QuartzCore framework or other required frameworks in your project. It should be in the Build Phases->Link Binary With Libraries.
3>Check while switching to the new version, you put the new library in a folder next to the old one, in case you had to switch back at some point. Normally when you removed the old version, it did not remove the path to the old version of the .a file from Library Search Paths in the build settings in "Project Name -> Under Targets" and delete the old path and add new one if required.
2>To add new class please select Project Name -> Under Targets select your target project name -> Build Phases -> Expand Compile Sources -> Click + at bottom of Compile sources and add the correct source file.
4>If the above tips are not working for you then be careful while adding files , don’t copy files directly, just create class by clicking on "new files" in Xcode and copy code one by one and add required frameworks. it won't show linker error .
I believe the class is not in your compile sources list.
Select your project on the navigation sidebar -> goto "build phases" -> expand "compile sources" -> add the corrensponding .m file for your class
Please check the class for which you are getting error message is linked to the target you are building.
Also make sure the third party library you are linking into project is properly linked and also linked at runtime of the project.
That is sure that application is able to find the class which you have mentioned at runtime.

.class file opens instead of .java while debugging

Current setup:
MainProject which is a Library Project
BranchProject which is a new projects and has MainProject as a Reference
Whenever I debug and a file from MainProject is on focus (actually BranchProject has only graphic and xml layout changes) the Debug window opens a .class file which is read only. I want it to open the .java file so I can edit it directly.
Skyler's answer from this post worked for me:
Opening source code from debug view edits .class after Android R18 update
Here is a summary:
The fix is to right click the Project name in the debug view, and select "Edit Source Lookup..." from the menu. From there, remove the Default lookup path. After that, manually add the associated projects (not jars) that your project references. This is done by clicking Add, selecting Java Project, then checking the appropriate projects.
When you're using a Library project one of the things you're in fact doing is compiling your Library project into a jar and then referencing that jar in your calling Project.
If you right click the Project, and select "Configure Build Path" you'll see a tab called "Libraries", if you look inside "Android Dependencies" you'll notice a list of jar's corresponding to your Library projects.
These jars are expandable, showing you that they have a slot for a source attachment. Usually this would be editable allowing you to directly link the source but in terms of ADT these are already filled and are uneditable.
When debugging these files you're linked to a read-only class file with this attached source. This is because you're not running against source files directly, you're running against a pre-compiled class file. Until the ADT team get this functionality in place, you're pretty much forced to jump to the direct source code and rebuild everything.
EDIT
See #Steven linked answer :)
I faced the same issue while debugging the a .java file using Eclipse IDE. As per my understanding this issue comes when we put the xyz.class file of xyz.java file or JAR at the project build path. Delete the .class or JAR file from the project class path and rerun .java file in the debug mode. This time you see a source not found window. Click on "Source not found" button and check "Find duplicates..." at the bottom of the window. Done your problem is solved :)
The problem is that the class file is preferred over the java (by default), here is how you can change that for Eclipse (tested on NEON 2):
Right-click on the Project in the Project-Explorer, click Properties
On the new window select: Run/Debug Settings
Create a new configuration (or duplicate another one)
Select the new config and click Edit...
Go to the tab Source
Select the Default and Remove
Create a new path with Add..., select Java Library, then JRE System Library
Create a new path with Add..., select the location where the sourcecode is by Workspace folder (if it is a project in the same workspace) or File System directory (it it is not)
I think this depends on, how you set up the dependency in eclipse. You should set up your BranchProject to depend on the source-Files of your MainProject. If you depend on compiles Class-Files is obvious that the debugger opens the class files, because it does not know about the source files.
I found a good solution for me here:
Using Android library in eclipse and jumping to class files instead of source file that is within eclipse workspace
Simply, select each library project your project depends on, and use Top or Up to move it above the projects outputs. Eg. move all library projects to the top.
Open main project properties -> Java Build Path -> Projects tab and add there projects the main project depend on.
Switch to Order and Export tab and uncheck Android Dependencies
Enjoy
If you tried all above hints and it still doesn't work try this solution, it worked form me:
Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path...
Select tab Order and Export
select library that you can't reach code and then click on button Bottom
Then click on Apply and Close
hope this can help you
Most of the time it happens when specific source folder are not added in build path Sources tab.
Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path -> Source Tab
Add the source folder if your project source folder is not there.
Select Add folder -> select your project source folder specifically. Eg: project_name/src . Then Apply it and restart server.

What happens if I remove all files from Compile Sources in Build Phases for the project?

What happens if I remove all files from Compile Sources in Build Phases for the project?
Under Targets -> Build Phses -> Compile Sources -> list of files are present. What happens if no files are present over there?
Thanks
As the warning itself says, the compiler doesn't know how to process some file.
Check for the filename that follows the "no rule to process file" warning, and look for it in the build phases. Then try removing only that file and rebuild the project.
Usually this happens when there's a header file (.h) in the Compile Sources list under Build Phases.
You list objective-c as a tag. Are your files all either .h, .m or .mm? - in addition to any .xib or .nib files?
The group "compile sources" is the set of files that the compiler is expected to compile. Those that are members of a specific target then have the output of their compilation linked together to make that target. The error "no rule to process file" normally indicates that the system can't deduce which language the files are and therefore how to compile them.
added main.m and yourclassess .m file into the compile source after below did
It's very similar:
1.Select the project in the project navigator.
2.Select the Target in the detail view.
3.Select the Build Phase tab.
4.Expand the Compiled Sources section
5.Remove the file you don't want to be compiled anymore

Three20 HEADER_SEARCH_PATHS strange behaviours

In one of my Three20 project, I have the HEADER_SEARCH_PATHS
HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/../three20 $(BUILT_PRODUCTS_DIR)/../../three20
But according to this: https://github.com/facebook/three20
I have must the following line in the path..
../three20/Build/Products/three20
I have re-created a project using ttmodule.py and confirm ../three20/Build/Products/three20 is the default but I am not sure why my existing project left it out.
Now the issue is:
Q. Why the project can build without error (Simulator/Device), what do you think is the reason?
in pre xcode 4 days the build folder would be under the project source directory which made sense to add a search header in a relative manner.
Three20 copies the header files into a specific place as part of a copy build phase.
Since xcode4 is out the build directory moved completely out of the project source tree into a temporary place configured as $(BUILT_PRODUCTS_DIR).
The reason you see 2 directories is because xcode generates 2 different paths for Archive builds and all the other kinds of builds (Run/Debug etc...)
$(BUILT_PRODUCTS_DIR)/../three20 $(BUILT_PRODUCTS_DIR)/../../three20
Notice that the manual instruction tells you to find that directory but it doesn't tell you where it is:
Finally, we need to tell your project where to find the Three20 headers. Open your "Project Settings" and go to the "Build" tab. Look for "Header Search Paths" and double-click it. Add the relative path from your project's directory to the "three20/Build/Products/three20" directory.