Linux - compiling c++ project files from different locations [duplicate] - c++

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to add a default include path for gcc in linux?
I was wondering is it possible to compile together files from different locations if they are included in the code itself?
Lets say the header file is in another location but there is #include "header.h" in the cpp file.
I was looking for answer here on the site but the only thing I found was how to compile multiple files from the same location.
edit: I use g++ compiler on linux

You can put
#include "adress"
adress would be like C:/Users/Files.../header.h

Related

Is there a way to maually include the iostrem and fstream header files In VS code [duplicate]

This question already has answers here:
How to avoid errors in Vscode for putting header files in a separate directory than src
(2 answers)
#include errors detected in vscode
(22 answers)
Closed 4 months ago.
I am using the C/C++ IntelliSense extesion but using a different compiler for my script.
When I try to include the iostream and fstream header files it tells me to update my include paths and I think that my compiler doesn't have this file in its system include paths and i have not yet found a way to include it manually. I am new to this stuff and it would halp a lot if there is a way.
If i try to use the normal compiler my code wont work and i have not found a way around this problem.
I have also tried to include it manually but could not find a Path to the file.

Show all c++ #include dependecies [duplicate]

This question already has answers here:
Displaying the #include hierarchy for a C++ file in Visual Studio
(9 answers)
How To Get g++ to list paths to all #included files
(2 answers)
Closed 1 year ago.
Is there a way to list all files included in a generic .cpp file?
I need a list (flat) or a hierarchical tree that show all the included files from a .cpp file?
Does the compilator has some flag to show them? or using another tool? how can i achieve taht?

What is .c.obj / .cpp.obj file? [duplicate]

This question already has answers here:
What's an object file in C?
(5 answers)
Closed 2 years ago.
I got these console output while compilation via GCC.
Building CXX object xxxxxxx.cpp.obj
What are the .cpp.obj files? Are they the object file? Do the same as the .o file?
What is .c.obj / .cpp.obj file?
Object files created from compiling .c and .cpp files respectively.
What are the .cpp.obj files?
See above.
Are they the object file?
Yes.
Do the same as the .o file?
Yes.
Note that "extension" is just part of a filename and is customizable. You can name your file anything you want you want, it will not affect the content. In cmake see CMAKE_C_OUTPUT_EXTENSION.

Hello World C++ app in Visual Studio - Question about precompiled headers differing [duplicate]

This question already has answers here:
Can I use #include "pch.h" instead of #include "stdafx.h" as my precompile header in Visual Studio C++?
(3 answers)
Closed 3 years ago.
I am just beginning my journey in learning c++ with a view to creating games in Unreal Engine.
I have some great tutorial videos, which I hope to follow the whole series but I am stuck already on the very first one :[
I do have quite a bit of knowledge of C# and Java.
Basically, in the tutorial they make a HelloWorld! Windows Console App in Visual Studio 2017. The very first line in their code is '#include "stdafx.h"' , in my code there is '#include "pch.h"'
I understand that these precompiled headers give me access to specific code/functions within namespaces, but where is this code stored? and why if I add include stdafx.h to my headers does it give an error saying Source code cannot be opened?
Precompiled headers is simply a way to cache compilation when you want to compile the same headers for multiple .cpp (translation unit files).
So if you have
a.cpp
b.cpp
and these include, say,
<windows.h>
<iostream>
Then, only one compilation of these include headers will be done (for the first translation unit), the other translation units will reuse the compilation, as long as they include exactly the same stuff - that's why they stop to a specific file name. By convention, this file name is stdafx.h
So usually I have a stdafx.cpp, in which I specify "create PCH" and the others use it.

C/C++: Removing unnecessary includes [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
C/C++: Detecting superfluous #includes?
How should I detect unnecessary #include files in a large C++ project?
I'm looking to do some house cleaning in our code base. I would like to start by removing all unnecessary header includes from our source files (*.c and *.cpp). Does anyone know of a tool or technique for doing this?
We are using GCC on Mac, Linux and Solaris. Using Visual Studio on Windows. I looked through the documentation of both compilers and there did not seem to be a option to make it warn for unnecessary includes.
Any thoughts or advice are appreciated.
I had to do this once and I ended up doing this:
I removed almost every #include statements from both my haeder and source files
I tried to compile my source code
Whenever the compiler complains about something undefined, I either:
Added a minimal declaration instead of a header inclusion wherever I could (something like: "class SomeClass;" instead of `#include "someclass.hpp")
Added the required include when I had no other choice.
Go to 2. until it succeeds.
I admit this is long and boring, but it worthed it.