Change the working directory in Xcode - xcode

I managed to get my C++ project running in Xcode using cmake -G Xcode. Now I would like to debug it, because of the nice gdb fronted it provides.
However I need to change the working directory where gdb is executed otherwise it wont work. (It needs to read some data from files relative to the path of the working directory) What I can do is after gdb has stopped typing cd working_dir and then run it manually typing r. This works, but Xcode will complain constantly and is also not an elegant solution.
So somewhere in the build settings I should be able to set the working directory..but where?!

Just updating this solution to XCode 4.x
You go on Product -> Scheme -> Edit Scheme
On the tab Options you choose your working directory.

In Xcode 4 the working directory settings is under Scheme Settings.

In Xcode 3.x do a "Get Info" on the executable and look at the first tab - there is a setting there for working directory.

The default debug working directory is somewhere under ~/Library/Developer/Xcode/DerivedData/project-/Build/Products/Debug. You're better off using the full path.

Related

Project specific .lldbinit in current working directory not read by Xcode

I want to setup project specific .lldbinit files, so that "everything" would be under version control and easily setup in new computers. However it seems like I can read only ~/.lldbinit file and not any ~/git/project/.lldbinit files.
LLDB manual say:
lldb will read settings/aliases/commands from three files at startup, if
they exist.
First, it will read a ~/.lldbinit-debugger command file. If you are
using the lldb command line interface, this is ~/.lldbinit-lldb. If you
are using lldb inside a GUI debugger like Xcode this will be ~/.lldbinit-
Xcode. This is a useful place to put settings that you want to apply
only when a given lldb command interpreter is used.
Second, ~/.lldbinit is read.
Third, an .lldbinit file in the current working directory (where lldb is
started) will be read.
So my question is: how do I setup Xcode or project to use the "third" option i.e. read .lldbinit file from the current working directory? How would I check or change what's Xcode's "current working directory"?
Xcode now (written with the public Xcode 12) has support for setting a scheme-level LLDB Init File. This can be done as part of the Info tab in the Run phase of the scheme.
Open project in Xcode.
⌘ + Shift + , to open scheme editor.
Select Run then the Info tab.
Edit LLDB Init File value.
Use $(PROJECT_DIR) to reference the directory that contains the project.
Use $(SRCROOT) to reference the target's source root directory.
This is the working directory in which you launch whatever process loads the LLDB framework. Xcode doesn't have a useful working directory (it was / last time I looked), so you can't really use the cwd version.
A solution for Xcode project specific lldb settings that will work in many cases is to put a symbolic breakpoint on main, set it to auto-continue, then put the settings you want in the breakpoint commands of that breakpoint.
It would also be great if Xcode had some UI to specify target-specific lldbinit files.
There is now a "Xcode plugin to load project specific .lldbinit" at https://github.com/alloy/lldb-is-it-not
Xcode now has support for Target specific lldb init files. There's an entry form for the path to the file in the Run scheme for the Xcode target.

Intellij Golang cannot find a module

I am using Golang plugin for IntelliJ, after set the GO Sdk for the module and project. I tried to edit configuration for the project. When I click the edit configuration, in module dropdown box, it shows no module. it seems the configuration cannot find the module. Anything that I missed? I have issue the following command in order to make Go SDK work in Intellij.
# mkdir /usr/lib/go/bin
# ln -s /usr/bin/go /usr/lib/go/bin/go
# ln -s /usr/bin/godoc /usr/lib/go/bin/godoc
# ln -s /usr/bin/gofmt /usr/lib/go/bin/gofmt
In the recent version of IntelliJ (here is screenshot from Ultimate 2019.1.3) you can find the GOROOT and GOPATH in Preferences -> Language & Frameworks -> Go -> GOROOT/GOPATH.
Install to Golang in your system (I used brew):
Since OSX ElCapitan, the OSX forbid access to /bin directory, which would cause problems with compiling the project with the default settings and having error like:
Cannot run program "/bin/go" (in directory "/Users/XXX/go/src/YYY/ZZZ/service"): error=2, No such file or directory
So this should be solved by updating GO preferences.
Open IntelliJ and your go project and update GOROOT in your project
If you have a custom directory of GOPATH do update it as well.
Click to run your go program.
Try the recent latest releases of that plugin, to see if the issue persists.
Note that you shouldn't have to link anything, just set your $GOROOT environment variable (or not, as mentioned in this article), and your $GOPATH.
this works for me:
Close GoLand.
Navigate to the project root, backup and delete .idea
directory.
Open the IDE again.
by https://youtrack.jetbrains.com/issue/GO-11854

Can't find glew.h in Xcode 5.0

I updated to Xcode 5.0 and I can't seem to be able to include the GL/glew.h file. In previous Xcode version one had to set the base SDK to current OSX, but that option is no longer available (at least I can't find).
The file glew.h is in /usr/include/GL and I already set the header search paths to /usr/include, but it still doesn't work.
Can anyone help?
Thank you
Got it to work.
Find in the Project Build Settings > Search Paths > Always Search User Paths and set it to yes.
Also, I couldn't link with libGLEW so I had to go into the XCode.app and create a symbolic link to the the file.
Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib
It is definitely not a great solution but is a work-around for me.
Edit:
Here, I suppose that one is working with the Mac OSX 10.8 SKD. For other SDKS, the path should be another one.
In the terminal I created a link to my libGLEW.dylib (which was in /usr/lib) in this way
cd Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib
sudo ln -s /usr/lib/libGLEW.dylib libGLEW.dylib
Afterwards, back in XCode, in my project's "Build Settings" I set "Other Linker Flags" to -lGLEW

xcode library not found

I'm getting the following error:
ld: library not found for -lGoogleAnalytics
clang: error: linker command failed with exit code 1 (use -v to see invokation)
I've spent some time googling but can't find how to fix this problem. I'm new to xcode and this is an existing project that I need to work on.
In my case, the project uses CocoaPods. And some files are missing from my project.
So I install it from CocoaPods: https://cocoapods.org/.
And if the project uses CocoaPods we've to be aware to always open the .xcworkspace folder instead of the .xcodeproj folder in the Xcode.
You need to set the "linker search paths" of the project (for both Debug and Release builds). If this library was in, say, a sibling directory to the project then you can set it like this:
$(PROJECT_DIR)/../GoogleAnalytics/lib
(you want to avoid using an absolute path, instead keep the library directory relative to the project).
All in all, the Xcode cannot find the position of library/header/framework, then you tell Xcode where they are.
set the path that Xcode use to find library/header/framework in Build Settings --> Library/Header/Framework Search Paths.
Say, now it cannot find -lGoogleAnalytics, so you add the directory where -lGoogleAnalytics is to the Library Search Paths.
In my case I had a project with lots of entries in "Build Settings > Other Linker Flags"
I needed to reduce it down to just
$(inherited)
-ObjC
Old settings:
Updated settings:
For me, I open the projectname.xcworkspace file and it all works.
If you have pods installed, make sure to open the workspace folder (white Xcode icon) not the project folder. This resolved the library not found for ... error. Very simple issue but I was stuck on this for a long time.
This worked for me:
Go to build setting -> Linking -> Other Linker Flags -> Remove all other than $(inherited)
Cd ios && pod update
If you are using Pods to include the GoogleAnalytics iOS SDK into your project, it's worth noting that since the 3.0 release your Other Linker Flags needs to include -lGoogleAnalyticsServices not the old -lGoogleAnalytics
If your library file is called libGoogleAnalytics.a you need to put -lGoogleAnalytics so make sure the .a file is named as you'd expect
None of the above worked for me, what did was making sure the Pod file platform :ios, '11.0' matched with the minimum deployment target in the XCODE setting
You can also try to lint with the --use-library option, as cocoapods lint libraries as framework by default since v0.36
The problem might be the following: SVN ignores .a files because of its global config, which means someone didn't commit the libGoogleAnalytics.a to SVN, because it didn't show up in SVN. So now you try to check out the project from SVN which now misses the libGoogleAnalytics.a (since it was ignored and was not committed). Of course the build fails.
You might want to change the global ignore config from SVN to stop ignoring *.a files.
Or just add the one missing libGoogleAnalytics.a file manually to your SVN working copy instead of changing SVNs global ignore config.
Then re-add libGoogleAnalytics.a to your XCode project and commit it to SVN.
In XCode 10.1, I had to set "Library Search Paths" to something like $(PROJECT_DIR)/.../path/to/your/library
For me it was a silly thing: my mac uploaded the file into iCloud, and that is why Xcode did not find it.
If you turn off the automatic upload, it wont happen again.

How do you change the PATH used in an external makefile build using XCode?

I currently have a project that I'm building with a makefile. This project includes some additional software (jflex) which is not on one of the default system search paths (it's installed to (/opt/local/bin/). My .profile file adds this directory to my PATH, and so building the project from a terminal window succeeds.
However, if I try to run the makefile from within XCode (XCode project with an externally managed makefile), it fails since it's not looking in /opt/local/bin for jflex, and as such can't find it.
How can I change the settings of my XCode project to correctly build from within XCode? I assume there's some kind of path setting in XCode, or some kind of additional argument I can have XCode give to make so that it doesn't fail. Alternately, I could hardcode the path into my makefile if I could detect that it was being run from XCode (although this is the less preferable option for me, since my makefile will sometimes need to be called from the command line and I'd rather keep it simple).
I'm relatively new to using XCode, so apologies if I've missed something obvious.
Instead of calling make directly, you could call a shell script as the "Build Tool" in the "External Build Tool Configuration" pane. Then modify the path in the shell script and call make from there, i.e.
#!/bin/sh
PATH=/opt/local/bin:$PATH
make
Don't forget to set permissions such that Xcode can run the script, and provide the full path to the script as the "Build Tool".
May not be the best way, But can you launch XCode from command line. It will inherit the Path from it.
Or, in the XCode launcher change:
XCode
to
PATH=$PATH:/opt/local/bin/ XCode
may work (depending on launcher)
Or, did you relaunch the launcher/window manager (logout and back in again after setting .profile)?

Resources