Profiling from Xcode - xcode

ALL,
I'm trying to find a memory leaks in my software written in C++. Everything is written and compiles fine when I try to run the build.
However, when I try to do "Product->Profile", the compilation fails. The compiler couldn't find some header file.
What is wrong and how do I fix it?
TIA!

Check the Scheme. Product -> Scheme -> Edit Scheme or Command <. See what's different within them.
Another place to look is Project Settings: General -> Linked Frameworks or something under Build Phases.

Related

How to use valgrind for a existing project

Someone told me that valgrind is a great profiling tool for general performance / cache misses.
But how do I use this tool for a large existing c++ project?
I'm working on this project with the XCode IDE (OS-X).
What would be the next step to get valgrind working for this XCode project?
Valgrind has a good documentation.
See e.g. http://www.valgrind.org/docs/manual/QuickStart.html
and http://www.valgrind.org/docs/manual/manual.html
For profiling, see:
http://www.valgrind.org/docs/manual/cl-manual.html
ok i figured out how to use valgrind with xcode:
1) Create new Scheme, no target and enter name (e.g. Valgrind)
2) Info -> Edit Scheme
3) Select Executable -> Other -> to the valgrind executable
(mine e.g: /usr/local/bin/valgrind)
4) Arguments -> add the valgrind arguments (e.g for cache misses
--tool=cachegrind)
5) Add the programm executable as arguement (e.g. /DerivedData/PerformanceTest/Build/Products/Release/PerformanceTest)
It might be possible that XCode automatically stores the Build folder in
/User/username/Libary/Developer/XCode/DerivedData/XXXXXXXXX..
But you can change the destination of this folder somewhere
For me this works perfectly!

Why does the Swift compiler mark errors pessimistically?

I find that Swift is quick to mark down changes i make as compiler errors in the side panel, and then when i compile, it decides i am right after all. Is Swift just pessimistic about my code?
Can I get the compiler to wait for me to finish the line before declaring it wrong?
There is nothing pessimistic. Xcode uses the same tool - the compiler - to get the errors. However, it usually compiles only one file, using cached compiled objects for the other files. It also doesn't invoke the compiler after every change in your code, so errors that are already fixed can stay there in the side panel.
Building the project fully forces Xcode to refresh the cache and get the current list of errors from the compiler. I do agree that Xcode has many imperfections and this is one of them. When you can't find an error, just rebuild the project.
Note that IDEs for other languages often rebuild the project automatically to solve such problems. This is currently not an option in Swift because it would take too much time.

How can I get Xcode to Compile my code instead of doing Build AST?

I just converted a Framework project from Xcode 3 to Xcode 4. I've been building this project for years under every version of Xcode and Project Builder.
For some reason, Xcode 4 runs Build AST on all of my classes rather than Compile, which doesn't actually build the framework executable. On digging into it I found that this passes the -fsyntax-only flag to clang which tells it to stop after producing an Abstract Syntax Tree for each class. I have another Framework that builds fine in Xcode 4, and I've compared the build settings without uncovering anything that looks like it would cause this.
Does anyone have an idea what would make Xcode want to perform the Build AST action rather than Compile? And more to the point, how to turn that behavior off?
Thanks for any ideas...
Okay, I found that in my case I had a custom Build Rule for '*.i' files in my project. The clang build process apparently produces .i files (along with several others) as an intermediate product, so this rule was interfering and stopping it from completing all stages of the build. Removing the custom Build Rule allowed everything to build normally.

Xcode flex lexer not generated

I'm having an issue with xcode. My project has a lexer which should be created (from lexer.l) before compiling anything. Flex should create two files from lexer.l: lexer.c and lexer.h. The latter is included in some other files. What happens now is Xcode does not process lexer.l and then complains about missing lexer.h. lexer.l is include in the compile sources list under build phases. Any thoughts?
One year late I can provide a solution. Maybe someone else can use it.
As I read on some answer on SO Xcode needs some special file extensions to map them to the different programming languages. When you want to compile c++ code f.e. you have to give the lexfile the ending .lpp. Xcode will handle the rest

Using Xcode for generic C/C++ development

I'd like to use all the power of Xcode for generic C/C++ projects but I can't figure out what are the basic steps to configure a new Xcode project and attach it to an existing source tree of a legacy, plain, C/C++ project.
Creating a new empty project, attaching it to a source tree and configuring a build target (using GNU Make) was a really silly task.
I can't figure out how to enable source code indexing in order to enable source refactoring tools, searching and fast-jumping and all the amenities that makes the Xcode programmer's life great.
Moreover I'd like to use the internal debugging facilities…
Does anyone point me to a tutorial, a hint or whatever could be useful?
Thanx
I've found a (dirty) path to enable refactoring tools:
I've added a new standard «console target» to the project and added all the source files under the Build Phases > Compiled Sources.
Refactoring tools now works. Having two targets doesn't seem to be a relevant issue (elegance apart)
Personally, I wouldn't attempt to use legacy Makefiles, even though I think there's some support for that.
Typically what I do with a traditional C/C++ project is to store my XCode project folder at the root of the project. So it might look like:
--myApp
--src
--inc
--myApp Xcode
I then drag the src folder and inc folder into the project navigator. This gives me an Xcode project to compile with on the Mac, and then I have the traditional Makefile for compiling on Linux (actually, I prefer CMake for other platforms, but either way works).

Resources