Adding folder pointers to default .sublime-build files (Sublime Text 3, c++) - c++

I am looking for a straight-forward way to add folder pointers in Sublime Text 3 when I am using it's built-in C++ compiler, C++ Single File Build System. I have written custom .sublime-build files before, but I also cannot find the default file C++ Single File .sublime-build file -- if I could do that, I could simply add an "-I /usr/..." to include additional folders.
As a solution, I am looking for:
Use the same .sublime-build that is used in the default C++ Single File Build System, while
Adding additional folders to point to. These additional folders would include header files (ex. armadillo.h)

An easy way to do this is use the PackageControl under Preferences, and install PackageResourceViewer. Once installed, you can use Ctrl+Shift+P > type prv > click PackageResourceViewer: Open Resource > C++ > C++ Single File.sublime-build. Copy this code into a new .sublime-build file, and add the additional folder(s) using `"-I C:/path/to/folder"

Related

Adding a CSV file to a project in Visual Studio

I am working on a project where I have to read in serveral pre-existing CSV (dog.csv, horse.csv, etc.). I want to know how would I add these file into my project so that I may test to see if my print functions work (the code is written in c++). Would I have to copy and paste the files into the debugging folder or would I place it under the test folder of the project?
You can include the files in your project in whatever (sub)folder you wish by using Right click -> Add -> Existing Item. Then, right-click on each file and choose Properties. Set up "Copy to output directory" to "Copy if newer".
Then after build, your files will be copied into the bin/debug folder.
To read the file, you can just use:
System.IO.File.ReadAllText("dog.csv");
Another possible way is to add a file within project, right click and select properties, and then in Copy to Output Directory, select Copy always. This way, csv file will be automatically copied in your debug and release packages too.
string executableLocation = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
string csvLocation= Path.Combine(executableLocation, "file.csv");
Above code will read file location from bin directory where your csv file will be stored.
This link should help guide you how to add CSV files to a project.
If you wanted to do a down and dirty way you could just save the CSV's somewhere on your local machine, and then hard code the file path to that location.
Example:
c:\test\Dog.csv and then set that as a variable for whenever you need to read in the csv file.

Xcode folders and groups confusion

I'm using Xcode (with C++) and my project layout (in the file system, not in Xcode) looks like this:
SubfolderA
-file_A_1, file_A_2
SubfolderB
-file_B_1, file_B_2
Right now I've set up this structure in Xcode via groups. And so, when I want to include file_A_2 in file_B_1, I write #include "file_A_2" in file_B_1.
Is there some way to make an inclusion look like #include "/SubfolderA/file_A_2", so that I can easily see to what directory/subfolder an included file belongs?
One way to see what's going on is to look at the Build Log and expand the line for compiling sourcefile.m. Look at the -I options being passed to the compiler.
If it's not to your liking you can add the source tree in the Build Settings > Header Search Paths to include $(ProjectDir)/srcroot and make it recursive, which saves you from adding each sub-folder individually.
In my experience this has never been necessary, however, as far as I can remember.
As far as the Xcode folders are concerned, if the top-level source folder is added then all sub-folders are automatically added when you add them to the filesystem, saving the hassle of keeping them in sync. You might need to add the top-level folder under the Source Files group for this to work, however.
Surprisingly, in Xcode's Build Settings I've added to User Header Search Paths non-recursive path to my project. This solved my problem.
I ended up here when I was having an issue with XCode while trying to include a header in a group by doing
#include "MyGroup/MyHeader.h"
Turns out the project structure and the file system weren't in sync, so I just had to remove my group from the project, put it in the correct place in Finder, then drag and drop it back into the project in the correct place and it worked for me.
I'm not sure if this is necessary or not, but I also have already set up my app's working directory because I am doing some game programming and need to be able to load in .png and make textures.

On Eclipse, is there a way to modify several include paths in one shot?

I'm trying to change the include paths from relative path to fixed path. Is there a way to do it in a bulk? Or do I need to manually edit one by one?
I'm currently going to
C/C++ Build -> Settings -> ** Compiler -> Includes
And have to manually edit the path from something like:
../../../../../platform/hal/rtc
../../../../../platform/hal/sai
../../../../../platform/hal/sim
To
"C:\Freescale\KSDK_1.0.0/platform/hal/rtc"
"C:\Freescale\KSDK_1.0.0/platform/hal/sai"
"C:\Freescale\KSDK_1.0.0\platform\hal\sim\"
I wonder if there's a way to export this to an XML file or something and then import it.
Thank you!
I've had this issue before in a workspace that contains more than 40+ similar C++ projects. The way I deal with it is to write a shell script that modifies the .cproject files on disk:
Use find to recursively find the .cproject files that I need to modify.
Use sed to search and replace inside each file using sed s/find-expression/replace-expression/g < .cproject > .cproject.tmp.
When I'm happy that the .cproject.tmp files contain the correct replacements then I add mv .cproject.tmp .cproject to the script to finalise the operation.
Since you're using Windows you'll need to get your projects into an environment where shell-scripting is easy - cygwin or msys are both powerful enough to do this.
In C/C++ General -> Paths and Symbols -> Includes ... (then possibly your language), there is an export settings button which has a checkbox which includes the includes path. To import these settings into another project, you would use the import settings button when you open the properties to the same place in another project.

Use source files in different directory in NetBeans Dynamic Library Project

I am new to C++ and NetBeans and I am trying to build a Dynamic Library project using it :). I want to build a plugin which uses source files located in different directories, and would like to keep them separately (as its a plugin ;)). I already tried to include the directory where the source files are located using Properties > Build > C++ Compiler > Include Directories, but it still gives errors in referencing to these files. These errors say the following:
"Cannot find include file "vtkPolyDataAlgorithm.h" "
Can anyone help me on this? I assume its a bit of a basic-basic-basic question, but I'm trying to learn autodidactically as a geologist from background, so you might see my problem :). I really hope you can help me out! Thanks :)
Ellen
While your way is the default way to add directories which contain additional headers (e.g. for libraries), you can add further Source-directories using Properties -> General -> Source Folders (-> Add).
It's also possible to add files (cpp / h) to your project, without setting a directory:
Right click on your project -> Add existing item ... or Add existing items from folders ...
But you have to care about your paths, you may have to browse to the headers using #include "../headers/here/example.h.

git pull shows merge conlict in .cproject file

What is exactly the .cproject file?
I didn't add any new files to my project.
I didn't change any project properties.
Is it auto-generated?
Is it safe to take the remote version if I didn't touch this file explicitly?
add this file to your git ignore so it will not be added to the repository.
You can use this online tool for that:
http://gitignore.io/
or simply edit (or create) '.gitignore' it in your root folder with the following content:
.cproject
This file is auto-generated, which contains your project setting information. you can use a notepad to open it. Without this, you need to re-configure your project.