Im trying to implement hot loading with SFML.
I manage to do it with a normal C Console application and the process goes like so:
1. create some code and compile it into a .DLL
2. load the code in my main-loop
However when i try to make a DLL with some SFML ckasses/functions I get a lot of unresolved externals, and i can't really understand how this would be solved.
any ideas??
first problem is making a DLL that has some classes/functions from the SFML-library.
gameCode.h:
#include "SFML\Graphics.hpp"
extern "C"
{
__declspec(dllexport) void CreateRect(sf::Vertex &vert);
}
gameCode.cpp:
#include "gameCode.h"
__declspec(dllexport) void CreateRect(sf::RectangleShape RS)
{
RS.setSize(sf::Vector2f(2.0f, 2.0f));
}
build.bat
@echo off
:: IMPORTANT! "=" has to come IMMEDIATLEY after VARIABLE NAME
SET compilerSwitches= /MD /EHsc -Zi -nologo
SET winLibs= user32.lib gdi32.lib winmm.lib Opengl32.lib ws2_32.lib advapi32.lib
SET sfmlDependLibsX64= /LIBPATH:"C:\SFML\SFML-2.5.1_x64\lib" freetype.lib openal32.lib flac.lib vorbisenc.lib vorbisfile.lib vorbis.lib ogg.lib
SET sfmlDependLibsX86= /LIBPATH:"C:\SFML\SFML-2.5.1_x86\lib" freetype.lib openal32.lib flac.lib vorbisenc.lib vorbisfile.lib vorbis.lib ogg.lib
SET sfmlLibsX64= sfml-system-s.lib sfml-graphics-s.lib sfml-window-s.lib sfml-audio-s.lib sfml-network-s.lib
SET sfmlLibsX86= sfml-system-s.lib sfml-graphics-s.lib sfml-window-s.lib sfml-audio-s.lib sfml-network-s.lib
If NOT EXIST ..\buildx64 mkdir ..\buildx64
If NOT EXIST ..\buildx86 mkdir ..\buildx86
If NOT EXIST ..\assets mkdir ..\assets
pushd ..\buildx64
REM cl %compilerSwitches% /I ..\include ..\src\CJsfml_002.cpp %winLibs% /link %sfmlDependLibsX64% %sfmlLibsX64%
cl %compilerSwitches% /I ..\include ..\src\gameCode.cpp /LD %winLibs% /link %sfmlDependLibsX64% %sfmlLibsX64%
popd
@echo x64 build Done!
::------------------ x86 BUILD (set vcvarsx86) -----------------
::pushd ..\buildx86
::cl /MD /EHsc -Zi -nologo /I ..\include ..\src\CJsfml_002.cpp %winLibs% /link %sfmlDependLibsX86% %sfmlLibsX86%
::popd
::
::@echo x86 build Done!
del *.~ *.cpp~ *.bat~ *.un~ *.h~
compilation Errors:
C:\SFML_Projects\SFML_CONSOLE_DEV\CJsfml_002\src>build
gameCode.cpp
Creating library gameCode.lib and object gameCode.exp
gameCode.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::RectangleShape::setSize(class sf::Vector2<float> const &)" (__imp_?setSize@RectangleShape@sf@@QEAAXAEBV?$Vector2@M@2@@Z) referenced in function CreateRect
gameCode.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::RectangleShape::~RectangleShape(void)" (__imp_??1RectangleShape@sf@@UEAA@XZ) referenced in function CreateRect