Xcode Project with multiple cpp files - c++

I have a project directory which has multiple cpp files. Each of these files has a main function tied to the respective files. Can i execute each of these files individually or do i have to modify some configurations in Xcode to target each of the files individually. If so, what are steps that i have to take?
This is what the structure looks like in Xcode
Project1
Project1
main1.cpp
main2.cpp
main3.cpp

It's relatively straight forward to have multiple targets under the same project:
Click on your project in the project navigator:
Go to your target, here;
Go to "add target":
Select "macOS" and scroll down to "command line tool":
Give it a name, and finish:
You'll see both target in the same project:
Next to the 'run' and 'stop' buttons, set your active scheme to the desired main file:

Related

Visual Studio C++ - change main.cpp file for each build solution configuration

I need to change default(main.cpp) file for each build configuration.
Two cpp files
main.cpp - created on project creation time
second.cpp
Two build configurations.
Release - compiling main.cpp
Custom - also compiling main.cpp but i need to compile second.cpp
How can i do this?
Thank you very much.
Answer provided by Richard Critten:
Right click the file > Properties > General > Exclude from build
This excludes the file from the build for the currently selected configuration at the top of the dialog. You can create as many custom configurations as you need.

How can I tell Visual Studio to use the project directory instead of the current file directory when including files?

I am refactoring my Visual-Studio-C++ project to use a folder structure rather than the filters in Visual Studio but I have noticed that when I try to include a file, it will use the current directory of that file so my includes look something like...
#include "../../server/IGameServer.h"
This is quite problematic when I refactor and move things around as I then have to go into each file and change their includes...
Is there a way to make every file start from the base directory no matter where the current file is, or a way to include the folder path so I can just use
#include "IGameServer.h"
(1) Go to project properties:
And add folders to "Addiotional Include Directories". ...Make sure that you aply to "All Configurations" (Debug, Release, etc.) and "All Platforms" (X86, X64).
--
(2) Click on that line + one more click on right side, on the down-arrow) & click Edit.... It opens a dialog that looks like that (I already added some folders in this example):

Run .exe File with Dependencies on Location

I have a Visual Studio project (Project 1) that generates an executable file (a.exe). I have a project (Project 2) that runs the executable from project (Project 1) multiple times with different command line arguments. On the command line I can run:
C:\filepath\Solution\Project1> a.exe //command 1
But I cannot run:
C:\filepath\Solution\Project2> C:\filepath\Solution\Project1\a.exe //command 2
Because the .exe file depends on the surrounding file hierarchy.
In Project 2, I can run a system call to execute command 2, but I hit hierarchy/location dependency issues. The Solution structure is as follows:
Solution
--> Project 1
--> a.exe
--> Project 2
--> main.cpp // this will run system call to command 2
Is there any way I can get around this without changing the a.exe file?
In Project2, how are you executing Project1's .exe? If you set the Current Working Directory (CWD) to the folder where Project1's .exe resides, it should work as expected:
var p = new ProcessStartInfo(#"C:\Project1\bin\project1.exe");
p.WorkingDirectory = #"C:\Project1\bin";
Process.Start(p);
If this doesn't work for whatever reason, you can simply copy the entirety of Project1's binary output and the associated file structure into Project2's output folder. There are two ways to do this:
Option 1 (preferred): Add the binary output of Project1 to Project2. To do this, right-click on the Project2 node in Solution Explorer, select Add | Existing item... In the "Add Existing Item" dialog, change the file type to "All Files". Navigate to Project1's bin folder, select the Project1 .exe and all dependencies, click the "down arrow" on the right side of the "Add" button, and select "Add as link". In Solution Explorer, select the newly-added file links in Project2, and in Properties change "Copy to Output Directory" to "Copy if newer". For each subfolder in Project1's bin folder, you must use Solution Explorer to create a new corresponding folder in Project1, then repeat this process for all files in that subfolder.
Option 2: Create a post-build step to copy Project1's binaries and surrounding folder heirarchy to Project2's bin folder. To do this, right-click on the Project2 node in Solution Explorer and select Properties. Go to Build Events, and enter a Post-build command line such as the following:
xcopy "C:\Project1\bin\" "$(TargetDir)" /S
Option 1 is preferred because with Option 2, external tools are less likely to realize Project 2's dependency on Project1. In both cases, Project2 must be updated to run the Project1 .exe directly from Project2's output folder.
Good luck!

How to make Netbeans remove deleted files from the project?

I am developing a C++ program using CMake as a Makefile generator. I have added the project as an existing source to the Netbeans and everything works nice except when I update lists of dependencies for my build targets.
Netbeans is able to get the new files added to the project, but keeps removed files hanging with a small yellow warning icon in the list of files. So the only way they could be removed is to manually in the GUI or by removing them from configurations.xml in the project.
As far as I understand the issue is about the way Netbeans scans for external changes. Is there a way to tell it to remove deleted files from the project?
You can try solutions mentioned here:
right click on your project in the "Projects" window,
click on "Properties",
click on "Ignored folders" in the left panel called "Categories",
click on "Add folder" and select the folders you want to ignore.
You can also clear the cache located in:
C:\Users\username\.netbeans\7.0\var\cache. //Deleting this directory should clear the cache for you.
To remove a file name with no file from my C++ static library project...
< File < OpenProject < "YourProject" (< means left click) (Leads To Projects.)
< Source Files > a.cpp < Remove File From Project (> means right click)
< Header Files > a.h < Remove File From Project (And the header file.)
I'm using netbeans 8.2. Curiously only c.cpp is listed under "Source files".
And only c.h is listed under "Header Files".
All the other (actual, real) source and header files are listed under "Important Files".

Eclipse c++ project folders

I have a lot of classes in my project which means a lot of files too. I want to put everything in subfolders so it's a grouped together and a bit more clear.
There is already a folder names scr where all my cpp and header files are in but I want to create a folder named 'products' and put all the product-related files in there.
But when I do so, I get this error (after pressing build) that one of my classes can't be build. It says:
make: * [scr/Producten/AudioKaart.o] Error 1 KassaSysteem C/C++
Problem recipe for target `scr/Producten/AudioKaart.o'
failed subdir.mk /KassaSysteem/Debug/scr/Producten line 30 C/C++
Problem
What's the right way to put files in subfolders? Do I need to change the includes? Or do something more than just dragging and dropping them into the folder?
If you put headers in your Producten directory, you need to include this directory in your project settings. Another way is to include your header by specifying the sub-directory, something like
#include "Producten/xxx.h"
Eclipse uses directories for project folders, so you need to adjust all includes as well.