I have a solution with 2 projects, one is a static library and the other is an application that
links to it. In the static library I have a pre-compiled header file with the following code:
#pragma once
//C standard Library
#include <stdio.h>
//C++ Standard Library
#include <iostream>
#include <fstream>
#include <sstream>
#include <memory>
#include <functional>
//Data Structures
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
I have also added the necessary .cpp file and configured the project properties to use this specific pre-
compiled header. I also added the .h file to the top of every .cpp file as required. I proceeded to my
latter project and properly referenced the static library and wrote some simple code, here is an
example:
class Test : public Craft::Application
{
public:
Test()
{
}
~Test()
{
}
};
Craft::Application* Craft::CreateApplication()
{
return new Test;
}
This returned Test object will be linked with an entry point and proceeds through the pipeline and
encounters code from the std library, that's when I get these errors:
- error C2039: 'string': is not a member of 'std'
- message : see declaration of 'std'
- error C3646: 'Title': unknown override specifier
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- error C2039: 'string': is not a member of 'std'
- message : see declaration of 'std'
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- error C2143: syntax error: missing ',' before '&'
- error C2065: 'title': undeclared identifier
- error C2065: 'width': undeclared identifier
- error C2065: 'height': undeclared identifier
- error C2614: 'Craft::Window::WindowProps': illegal member initialization: 'Title' is not a base or member
- error C2039: 'unique_ptr': is not a member of 'std'
- message : see declaration of 'std'
- error C2143: syntax error: missing ';' before '<'
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- error C2238: unexpected token(s) preceding ';'
I understand that this project doesn't recognize the header files in my pre-compiled header. I can
confirm that as I included these files in the application and this resolved all errors. This sparks many
questions though: This project links to the library, so why doesn't it recognize this pre-compiled
header? What's the best solution for this? Is it a pre-compiled header per project? Is it something
entirely else?