In CLion, how can I rename a project? - clion

I try to rename my project from encoding to Tutorial, but after I refactor directory name, it comes out an error, like:
Error: CMakeLists.txt not found in D:\code\encoding
I find that files in .idea directory don't change automatically, they are still encoding.iml, encodings.xml.

In the project folder, cd to the .idea directory. Locate the .name file and open it for editing. A single line of the current project name is displayed. Change it and save it.
If the .name file is not present, create it, then add a single line of text with the desired name.
Now reopen CLion and the project name has changed.

When using CLion with CMake, the project name is set by the project command inside the CMakeLists.txt.
Look for a line like the following and change "my_project_name" to the CLion project name you want.
project(my_project_name)
Then reload the file using Tools >> CMake >> Reload CMake Project or, if present, by clicking on Reload changes in the yellow bar across the top of the CMakeLists.txt editor window.
Note, if you use New Cmake Project From Sources... to create your project, then CLion generates the CMakeLists.txt at that time including a project command using the directory name. It is fine to edit CMakeLists.txt after it is generated, including changing the project name.

On Mac:
Close CLion
Rename your project folder, found at ~Users/Your_User/ClionProjects
Open CLion
Click "Open Project"
Browse for your renamed project
Wait for your project to fully load and update

If your are running Clion on a Mac, all you have to do is rename the directory that contains your .cpp and .h and CMake files then in Clion go to open then to the new name of the directory and Clion automatically figures everything else out.
That is what I did. However before you open the new project which is the project you renamed. Clion will create a project directory with the original name and it will be blank so you will have to Delete that directory.
However, if you are using windows or other machines it may not be the same. Because, now that i look, i don't have and .idea file.
Now that i think about it. Maybe this is a new feature since the new update. I am not sure when the new update for jetbrain IDEs was released. So, maybe that is a new feature that was not around at the time of your original post.

Easier Answer:
Why are you making it so hard? I have done this by either editing or adding a .name file to the .idea directory. I have done this several times and it works:
Edit or create your .name file in the .idea directory
Change or add file name.
Save file
Reopen project and voila, the new project name.

I did that in Linux. Grep oldProjectName in my project dir by cmd:
grep -rn oldProjectName
CMakeLists.txt, cmake-build-debug/ .idea/ have that str, so I replace all by cmd:
sed -i "s/oldProjectName/newProjectName/g" `grep -rl "oldProjectName" .`

Related

Project ... cannot be opened because it is missing its project.pbxproj file

I recently downloaded LLVM-3.9 and built XCode project files for it with:
mkdir llvm-3.9.0.XCode # The .XCode in the name was probably a bad idea
cd llvm-3.9.0.XCode
cmake -G Xcode ../llvm-3.9.0.src/
The cmake then generated a valid looking XCode project files.
Then when I tried opening the project directory with XCode, I kept getting error:
Project .../llvm-3.9.0.XCode cannot be opened because it is missing its project.pbxproj file.
Apparently this error message is often the result of corrupt project files, but this is not the problem in my case. It seems this error can be shown due to different reasons. Here are some similar, but not identical questions that did not help me:
One about merge problems.
A question about where the file shoud be.
One about dropbox problems?
One where the problem seems to be corrupt project files
One where the problem was permissions
The solution I used was this:
cd llvm-3.9.0.XCode
cd LLVM.xcodeproj
open .
In other words, I navigated to the newly generated LLVM.xcodeproj with the shell
and used the system open command on that folder.

I am getting this error when i perform make on codeblocks source code

configmanager.cpp:39:44: error: wx/mac/corefoundation/cfstring.h: No such file or directory
The compilator can't find the cfstring.h file. Try reinstall codeblocks.
It happens because you are creating the file in documents or other folder.
Create the file in your Desktop and while giving it a name don't include space in it, click build and run, the terminal will open with the output. It worked for me at least, then you can move it to your desired folder.

Is there any way to disable write-access to source code from within Xcode?

Is there any easy solution to prevent Xcode from writing to source files in a project? I want to edit source files externally and only use Xcode for debugging and so I want to prevent any accidental modifications getting saved via xcode. (Obviously I want Xcode to pickup external changes to files when I build/debug)
One possible solution that I thought of was to enable app sandbox entitlements on xcode and manually maintain a list of directories that it should not write to. Is this feasible? Any other ideas?
On the sandboxing thing, I'm not sure if Xcode is disqualified as per Apple's Sandboxing Requirements.
I don't think there's any way to prevent XCode from getting all into your source, writing temp files and whatnot.
One option would be to create a simple shell script that pushes your source to a directory for XCode to use. Since you're not using XCode for development (debugging only), just copy your entire project tree into a temporary directory and then open that in XCode.
Something like (push_to_xcode.sh):
#!/bin/bash
#first, wipe existing project from your temp directory
rm -rf /tmp/xcode_temp_code
#then, copy your existing project into the temp folder
cp -R /path/to/your/project/myProject /tmp/xcode_temp_code
#lastly, launch the project
open /tmp/xcode_temp_code/myProject.xcodeproj
Once you've created the script, change it to executable by typing chmod +x push_to_xcode.sh
Then open a terminal, cd to the directory where you saved the script, and type ./push_to_xcode.sh or double click on it in finder.
That will launch Xcode with this project. No changes you make in XCode, either purposefully or accidentally, will affect your original code.

I'm getting "clang: error: no input files"

I had a file which I deleted and replaced with another file, somewhere else, of the same name.
Despite cleaning, and trying this multiple times, I keep getting this error:
clang: error: no such file or directory: '/Users/Andrew/App/Version 1.1/XCode/UIImage+Alpha.m'
clang: error: no input files
I can't continue working on my app because of it. Any ideas?
The problem might be because your project > target > Build Phases > Compile Sources is trying to compile a file that doesn't exist. It might be in there twice, like the below screen shot. My project contains UIImage+FFXtras, I can even remove it and re-add it and this won't resolve the problem!
I'm not sure how the project gets into this state - but I know it's not obvious what is going wrong. Highlight the red problem one and remove it.
So have a look in compile sources phase for the file clang is complaining about.
Got the similar troubles.
It seems XCode does not generate correct relative filepath when your project refer to an already existing source tree (relative path does not contain the .xcodeproj in the path of the file to be compiled).
There is a simple fix however: in the project explorer select the file or files files then look at the options in the file inspector. One of them is labeled "Location"; set it to absolut path and try again. This fixed the issue for me :)
Additional to all answers:
delete derived data
reboot
delete derived data
clean
build
Success!
Only this sequence works for me in my case.
I use quite a few cocoa pods and have just had this happen to me. A quick "pods update" sorted things out for me. -phil
If you are using vs code and facing this issue which says
clang: error: no such file or directory: 'filename'
clang: error: no input files
Error while running files:
I solved this issue by removing the space or replacing the space with underscore(_) in the filename .extension
In case everything fails (i.e. first try bames53 suggestion)
Ok, this might be dangerous so make a copy of your whole project first:
close Xcode
locate the project file in the Finder
right click, choose "show package contents"
open project.pbxproj in a text editor of your choice, but not Xcode
search for your file
at the beginning of the line that shows up, you'll see some id like 640450991409CF5C00B3B580. Search for this and delete any line you find.
pay attention, not to break the syntax (balance parenthesis and brackets, pay attention for commas)
when you are done, save the file and try to open the project in Xcode. Add the missing file via the Add file… dialog of Xcode. It is still in the folder of your project — if you added it successfully in the first place — you just got rid of all project references.
dont be surprised, if it doesnt work instantly — you have a copy. copy it again, new try.
And remember: make a copy of your whole project first — for every try. or copying the project.pbxproj might be enough.
Add this line in your pod-file and run pod install:
use_frameworks!
I had this error in monodevelop. I just went to edit>preferences
and changed the default location of the program files. It was set to the monodevelop default they give you when you open a file and not the folder i changed it too.
Likely, you need to adjust the settings of xcode, where you stored your files.
I was seeing this while setting up a React Native project. Solved it using:
sudo xcode-select --switch /Applications/Xcode.app
Source
Comment Quoted from another site was the issue is resolved for me
hmm that's strange. Try this - click on the name of your project on the list of files/folders on the left in Xcode (at the very top of the list). Look at the "Targets" section on the left-hand side of the window to the right. Likely, there's two listed with the second being a "test" item. Right-click on that item and select "delete". Then try to run the project again. See screenshot below for a visual cue.

Where does xcode resolve "$(BUILT_PRODUCTS_DIR) to on my system?

When Compiling for iPhone Simulator with Xcode 4.2, if I place
"$(BUILT_PRODUCTS_DIR)"
in
Build Settings / Header search paths / Debug
and exit editing I can see it resolves to:
"build/Debug-iphoneos"
Where should this be on my system? I have looked in:
Library/Developer/Xcode/DerivedData/{Project Name}/Build
but I can't find a file called build that contains a folder called Debug-iphoneos.
On my system, compiling an OSX project, that resolves to an absolute path:
BUILT_PRODUCTS_DIR /Users/andy/Source/MyProject/build/Debug
There are so many Xcode build variables that I keep a text file with a sample list of them which I got from executing a custom build script and viewing the output within the log tab.
If your code is going into the Library folder, then that is hidden under Lion. You can unhide it from the command line (Terminal) using:
$ cd ~
$ chflags nohidden Library
You should then be able to see its content.
Another tip: I have a ~/tmp folder where I let temporary stuff accumulate and I have set my Xcode preferences to put DerivedData and Archives into that folder so I can:
delete it now and again (I don't like temporary stuff accumulating where I cannot control it).
see it for packaging pre-release Archived project to testers.

Resources