Visual Studio 2017 C++ include for all - c++

Good day. I got some C++ project from GitHub. Originaly it buils using automake (there're makefile.am and configure.ac files). I'm trying to make C++ in VS2017 based on it. Source project has over 600 source files, and problem is what there's no any "include" directive in source files, and I have over 5000 compile errors. Is there any way to declare some kind of "global include for all source files" in project without modifying original souce files or create any "special" file with all required includes, which will be included automaticaly in source files on compiling?

Related

Visual Studio C++ how to add header files in a prefix folder

I cloned a github C++ repository. The repository is not a VS project. So I manually created a VS C++ blank project and added the files from the repo to the project. The files are not copied. This is not the problem.
The repo directory looks like this:
include\NTL\*.h
src\*.cpp
*.h means a bunch of header files and *.cpp means a bunch of .cpp source files.
The problem is that the .cpp files have #include <NTL/*.h> and when I build, VS fails to locate the header files (No such file or directory). Adding the path to the include to the Include Directories in project properties didn't help.
EDIT: After some experimenting, I've found that the error has nothing to do with the prefix NTL in #include <NTL/*.h> but with whether the files are copied into project directory. Even though the files appear in VS project view, they must be copied into the project directory.
EDIT: The only way I've managed to get the project to compile is to put the whole NTL directory containing header files in project directory. Include Directories and Additional Include Directories in project properties don't seem to have any effect.
All previous No such file or directory errors were the result of some combination of:
Mismatching project properties Configuration and Platform
Some .h files were actually missing from NTL github repo, e.g. mach_desc.h.
The solution to the problem consists of the following:
Under project Properties > C/C++, add the path to the include to Additional Include Directories.
VS project has a separate set of properties for each combination of Configuration and Platform. Make sure that step 1 applies to the active Configuration and Platform. E.g. If the project's currently configured to build for Debug x64 (active Configuration:Debug and Platform:x64), make sure that step 1 applies to Debug x64, and not something like Release Win32 or Release x64, etc.
Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

Adding multiple source files to build in Eclipse

I'm developing a code which uses Easylogging++ as the underlying logging library. Recently, I wanted to update the library since it has some high visibility / high impact bugs and I found out that the library is divided into two files (.cc and .h). This new structure needs inclusion of the .cc file in the build string alongside the main program code.
I'm using Eclipse to develop the project and generate the make files to build the project. I need to tell Eclipse (Oxygen.1) that it needs to compile the .cc file alongside the main file while building the project, however I was unable to do so. Any help is greatly appreciated.
It's easier than I thought. Eclipse's managed build is more intelligent than it seems. Adding many source files under the /src folder causes Eclipse to automatically compile all the files under that folder, unless you exclude them.
This means adding the .h to /lib folder and the .cc file to the /src folder and modifying to .cc to look for the .h file under /lib have solved the problem neatly.
To complete the compilation I had to add some flags, since the developer likes to extensively modify his library between releases.
Everything is working fine again.

Creating a C++ visual studio project based on existing files

I've never worked with C++ or C. I'm trying to create a Visual studio project based on existing files which can be found here: example1.cpp together with the resources. As you can see this is example code of a book for OpenGl. I have opengl and glut present on my computer and they work ( tested it).
Based on the files mentioned above a created an empty C++ project in visual studio 2012 (i also have other versions installed if you can provide a solution in 2010 or so). I included the header files & the source file. Though I still get the following in my IDE:
with errors such as:
cannot open source file "Angle.h"
( Though the file is present in the project)
Can anyone tell me how I get these files to compile and run ?
Make sure that the file angel.h it's in the same path that the .cpp file.
Header files need to be in same directory with source files in order to use #include with quotes.
#include "header.h"
In other words Angel.h must be in same directory with example1.cpp.
However,you can add spesicific paths to your project from Project Settings>VC++ Directories and include header files which exists in those paths using
#include <header.h>

How do you compile and run a project in Visual Studio when you have multiple source and header files involved in the same project?

I mostly worked with linux env, new to visual studio. (If you are in Linux, you would use the make utility...) How do you compile and run a project in Visual Studio when you have multiple source and header files involved in the same project? I have main.cpp, and few other source and corresponding header files, and when i built the project, I couldn't see an output although the project compiled fine and 'exited gracefully'. How do I tell Visual Studio that these files are part of the project?
To do that:
Select Project -->
Add Existing Item....
You should be looking in the same directory where you saved the project/solution.
Highlight the .h and .cpp files: date.cpp, date.h and main.cpp
Select "Add" to add the files to the project.
Result: Once I added the 'main.cpp' and other files in the project, it works fine and I am able to view the output.
References:
1 [http://www.cs.uregina.ca/Links/class-info/210/Lab1_VCIntro/]

CMake and Visual Studio resource files

I am converting a C++ project created using Visual Studio 2005 to CMake and have stumbled upon a bit of a problem with resource files that are included in the project.
The project includes a .rc file, a bunch of .ico files and a .rc2 file.
The regular .rc file works fine in the generated project and uses the resource compiler. The .ico and .rc2 files however are causing problems when they are just being included, because in the generated project Visual Studio attempts to compile them using the C/C++ compiler.
I assume that these files are included by the .rc file, so it would probably work to just not include them in the CMakeLists.txt file, but since it is obviously possible to list them in the project (they are visible in the original project) I would like to do so, so that the user of the generated project can see that these files are being used.
What is the correct way to handle these extra VS resource files in CMake?
Try to set_source_files_properties(your.ico your.rc2 PROPERTIES LANGUAGE RC).
By default it shouldn't do anything with those files. The source file property LANGUAGE should be empty and thus the action for the file should be checked by the file type. Which shouldn't be anything since it's not something it should compile.
Check your CMakeLists.txt that is doesn't contain a set_source_files_properties command that would mess with that property.
If you want to do something with the files, here are two ways to do things:
With add_custom_target you can add them and run custom commands for them when you build the project. Granted that the files have changed.
With configure_file you can easily copy them to a build directory if needed. With the COPYONLY flag.