Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to include a file into all project files in C++?

Tags:

c++

project

Suppose we have a pretty big amount of files in a project, so writing #include "somefile" to all of them will take a long time, so it there a way to include "somefile" into all files in the project?

like image 387
AdmiralMyxtaR Avatar asked Dec 19 '25 06:12

AdmiralMyxtaR


2 Answers

If it is visual studio, use the /FI option (force include).

https://msdn.microsoft.com/en-us/library/8c5ztk84.aspx

like image 83
Sven Nilsson Avatar answered Dec 21 '25 18:12

Sven Nilsson


Some compilers have an option for this. For example, the option for GCC is -include.

-include file

Process file as if "#include "file"" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the "#include "..."" search chain as normal.

If multiple -include options are given, the files are included in the order they appear on the command line.


Of course, using such option will make your project depend on the support for such compiler feature. A portable solution is to simply edit all your files.

like image 33
eerorika Avatar answered Dec 21 '25 19:12

eerorika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!