I'm currently working on making my own 2D game from scratch in C++ as a side project. The game is going to be using SFML for displaying textures and such, and because I can see myself making more than one game like this in the future, I thought it a good idea to separate out some of the components that I have built for future use as dynamic linked libraries.
Here lies the problem though: whenever I build my actual "game" project that requires one of the other projects that pull from the SFML library, I get errors telling me that "SFML/Window.hpp" doesn't exist.
2>------ Build started: Project: test-game, Configuration: Debug x64 ------
2>Test.cpp
2>c:\users\jsuskalo\documents\programming\projects\c++\2d-engine\render-engine\rewindow.h(4): fatal error C1083: Cannot open include file: 'SFML\Window.hpp': No such file or directory
2>Done building project "test-game.vcxproj" -- FAILED.
However if I simply compile the first project, which is the one that actually does a #include of the "SFML\Window.hpp" file, it compiles just fine.
Initially I assumed that perhaps I would just have to ensure the project could include and reference the libraries the same as the render project, but when I do that I got more errors:
1>------ Build started: Project: test-game, Configuration: Debug x64 ------
1>Test.cpp
1>c:\users\jsuskalo\documents\programming\projects\c++\2d-engine\test-game\test.cpp(7): error C2280: 'REWindow::REWindow(const REWindow &)': attempting to reference a deleted function
1>c:\users\jsuskalo\documents\programming\projects\c++\2d-engine\render-engine\rewindow.h(24): note: compiler has generated 'REWindow::REWindow' here
1>c:\users\jsuskalo\documents\programming\projects\c++\2d-engine\render-engine\rewindow.h(24): note: 'REWindow::REWindow(const REWindow &)': function was implicitly deleted because a data member invokes a deleted or inaccessible function 'sf::Window::Window(const sf::Window &)'
1>c:\users\jsuskalo\documents\programming\libraries\c++\sfml-2.4.2\include\sfml\window\window.hpp(530): note: 'sf::Window::Window(const sf::Window &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'sf::NonCopyable::NonCopyable(const sf::NonCopyable &)'
1>Done building project "test-game.vcxproj" -- FAILED.
When I did the include and reference properties edits I closely followed the SFML tutorial on such (https://www.sfml-dev.org/tutorials/2.4/start-vc.php) so I have to wonder if it's something wrong with my code at this point.
Inside my render project I have the following header and code file: REWindow.h in the render-engine project:
#pragma once
#include <string>
#include <SFML\Window.hpp>
using namespace std;
class REWindow {
public:
REWindow() : REWindow(800, 600, "Test Window", false) {};
REWindow(int iX, int iY, string sName) : REWindow(iX, iY, sName, false) {};
REWindow(int iX, int iY, string sName, bool bSplash);
bool isOpen();
bool updateEvents();
bool shouldClose();
void close();
sf::Event event;
private:
sf::Window window;
int m_iX, m_iY;
string m_sName;
bool m_bSplash;
};
REWindow.cpp in the render-engine project:
#include "REWindow.h"
REWindow::REWindow(int iX, int iY, string sName, bool bSplash) : m_iX(iX),m_iY(iY), m_sName(sName), m_bSplash(bSplash) {
if (bSplash) {
sf::Window window(sf::VideoMode(iX, iY, sf::Style::None), sName);
} else if (iX == -1 || iY == -1) {
sf::VideoMode vmDM = sf::VideoMode::getDesktopMode();
sf::Window window(sf::VideoMode(vmDM.width, vmDM.width, sf::Style::Fullscreen), sName);
} else {
sf::Window window(sf::VideoMode(m_iX, m_iY), sName);
}
}
bool REWindow::isOpen() {
return window.isOpen();
}
bool REWindow::updateEvents() {
return window.pollEvent(event);
}
bool REWindow::shouldClose() {
return event.type == sf::Event::Closed;
}
void REWindow::close() {
window.close();
}
And finally the offending file (it seems), Test.cpp in the test-game project:
#include "REWindow.h"
using namespace std;
int main()
{
REWindow wind = REWindow();
while (wind.isOpen())
{
while (wind.updateEvents()) {
if (wind.shouldClose()) {
wind.close();
}
}
}
return 0;
}
So the final question is simply, is the problem likely in how I included the files, is it an inherent limitation in Visual Studio, and if so, how would I work around it, or is it simply a code error?