Using file for different projects from one folder - c++

In my file explorer, my C++ project folders are like this:
... -> Documents -> C++ -> Files . . . . Projects
[In C++ folder, there are two more folders, called Files and one called Projects. I keep all my games/projects in the Projects folder. Each game has its own folder inside.]
Now here's the problem: I want all my common functions (.cpp & .h) to stay in one file folder, so if I ever change it, it changes for all my games. I want to keep these in Files. Is there a way to achieve this, like #include [Directory]? I know I can keep a file in its own game, but I want these to be all changed easily, and my code does not need to be transferred between computers. Thanks

This is not the right way to do it. If you have functionality that is shared between different applications (games, in your case), make a library from them and include that library in all your projects.

Solution for Visual Studio (2017)
For Source Files:
In the solution explorer right click on Sourcefiles and click "Add"/"Add existing" and choose your file(s)
Setting Include directory:
In the solution Explorer right click on your "Project" and click Properties
On the top set "Configuration" to "All Configurations"
Choose in the lsit on the left "VC++ Directories"
Click on the Dropdown arrow on the row with "Include directories" (you might have to click once on the row for the arrow to appear
Click "edit"
Add one line for each include directory. Use the folder icon on the top to open the file explorer to choose the directories

Related

I Don't Know How To Use/Run These Files That Are In A Github C++ Library I'm Trying To Add To My Project?

https://github.com/gladosconn/ecdsa_cxxI have been trying to get this library into my project (C++ using Visual Studio 2022, in Windows) because I need to use the ecdsa signature algorithm, I have copied all the files in src folder to a folder called "ecdsa" in the src folder inside my project, and I didn't do anything with the test folders (I think that I don't need them since they're just tests), but then there are these files (.ytml) ,(.txt) ,(.py), I have no idea what am I supposed to do with them or where to put them, but I sure I need them because the program isn't working, it's giving me this error Cannot open include file: 'secp256k1.h': No such file or directory Libraries.Also I have done everything in the requirements section, my compiler supports C++11, and I have installed openssl, and I have CMake installed.This is my first time using anything from Github so I'm sure what to do.
In Visual Studio, right-click on your project in the Solution Explorer pane. From the menu that pops up, choose the 'Properties' item. It is usually at the very bottom. A dialog box will appear.
In the left pane of the dialog box, expand the options Configuration Properties > C++ > General. Now, in the right pane of the dialog box, probably at or near the top will be an item labeled 'Additional Include Directories`. Add the full path to the folder where you copied the source files from GitHub.
You may need to explicitly add ALL the files you downloaded from GitHub into your Visual Studio project.
Try compiling again.

Eclipse CDT add existing source without copying

I have a C++ project proj1 with some source files in, however I would like to also use some of the source files I have in another project proj2. proj1 and proj2 are both subdirs of a directory my_projects. I don't want eclipse to copy the files as I want to ensure I have only one copy to edit. This is like the "add existing item" option of MS Visual Studio.
The end result I'm aiming for is to be able to create makefiles for both proj1 and proj2, zip up the two directories together and send them to coworkers so they can build the two projects themselves using make.
Is this possible in Eclipse? I've searched and haven't found the solution.
Phil
If you have proj2 open in Eclipse right click on the project and choose Import... and then select General > FileSystem and hit next. In the top window choose the directory in proj1 that contains the resources you want to link. After selecting the files you want to link in the top window hit the Advanced button to open up a submenu and select Create Links in Workspace as shown in this screenshot:
This question addresses setting up a Makefile with relative instead of absolute paths: Getting Eclipse CDT to use relative include paths in generated Makefiles
I looked forever for a solution to this, and I finally found it. Right click on the project and select Build Settings. Under the Build header on the left click "Settings". Then under the "Tool Settings" tab click "Directories" under the compiler header. Then click the add button at the top. If the desired files are in another project in the same workspace click the workspace button and then navigate to the exact folder where the files are. Once you have done this voila! you should be able to build the project!

Eclipse CDT convert a "normal folder" to a "source folder" or vice versa

Because of me not being used to Eclipse I have projects whose subfolders are mixed "source" and "normal" folders. This is not much of a problem since those are Makefile projects but it bothers me to have my folders not being listed alphabetically (the source folders are displayed first).
I would like to convert my "normal" folders to "source" folders but I can't find anything related in the right click menu on said folders nor in the "properties" window.
Is there a way to convert folder types that doesn't involve editing the .cproject file manually ? If not, can I just edit the sourceEntries tag (it seems to work so far) ?
I am using CDT 8.0.2.
In order to do this in Eclipse, you should get in your project's properties, then expand C/C++ general -> Paths and Symbols -> Sources tab
Then click the Add Folder button, and choose the normal folders you wish to include as "source" folders.
Right click on the folder, "BuildPath" and "Use as Source Folder"

How do you compile Box2D for Code::Blocks/MinGW32 under Windows?

I've found similar questions across the internet, none of which helped me. The Code::Blocks workspace and project files included DO generate .a files, and I've moved them to Codeblocks/MinGW/lib, and I've moved the Box2D folder to Codeblocks/MinGW/include and yet the HelloWorld.cpp example still gives me these errors.
Looks like the project files you used to build the .a were missing some files. The file mentioned in the error message is one that was removed from Box2D after v2.1.2, so I'm guessing you are using 2.1.2 source code (or thereabouts) with project files from some other source?
In any case, setting these up yourself is really simple. In the 'Management' panel, right click the 'Engine' project, select Remove files and click OK to remove everything.
Now do the same and select Add files recursively, choose the folder that contains Box2d.h file:
Click OK a few times, and you're done.
In your case, since you had it building already I would expect this to be ok now but for anyone arriving here wanting to setup a project file from scratch, you'll also need to specify the search path for the Box2D headers.
To do this, in the same right-click menu choose: Properties -> Project settings tab -> Project's build options button -> Search directories tab -> Add button. Now choose the parent folder of the one you just chose above.

how to link the fmod library in visual studio

I am just a beginner at windows programming and was reading a tutorial about it.
It said something about resources for menu creation.
I am working in visual studio 2010 and would like to know how to create these resources (the turorial said something about adding them to the compiler which i could not understand) for simple things like menu bar creation.
Please help me.(Please keep in mind that I am a beginner therfore explain in detail if possible.)
To actually use the additional functionality you have to include the header and specify the directory where it is contained so the project can find the file
right click on project->properties
C\C++->general tab
the top element is Additional Include Directories - click the down arrow and specify the path to the header file
For your application to use the functionality you have to link with the lib
right click on project->properties
Linker->general tab
The 9th element from the top is Additional Lib Directories
& specify the path to the accompanying lib file
NOTE that the dll that corresponds (if dynamically linked) must be either in the system path or in the working directory of your application
under the linker -> input tab
you'll want to specify the name of the .lib file to load (the same as the file contained within the path you specify to link with with)
Alternatively - if the you'd like to make a project depend on another project within the same solution
right click the project->properties
the top tab is Common Properties
within that tab click the button "Add New Reference" and select the project