I am new to C++, although I am an experienced C# developer.
I am trying to challenge myself by writing a .NET CLI wrapper around Scumm VM.
I have created CLI project called CLRScrumm. It is currently full of empty methods.
My strategy is to copy sdl.h, sdl-events and sdl-graphics, rename them as clr-xxx and gut them. Note that the OSystem_CLR is based on sdl.h
My end goal is for the C# to pass in a callback function which can be called from clr-graphics.copyRectToScreen.
I managed to those class skeletons compile, but not link. I guess I must be missing some function implementations somewhere, but I can't for the life of me
see where. The errors from the linker are very cryptic.
I would appreciate if someone would:
1. Give me a general strategy for fixing these errors
2. Point me in the write direction for fixing them.
Note. I feel really guilty sticking in reams of code, like I have but I don't know of another way.
Here are a couple of the linker errors.
Error LNK2020 unresolved token (0A00010E) "public: __thiscall Common::String::String(class Common::String const &)" (??0String@Common@@$$FQAE@ABV01@@Z) CLRScumm D:\ScummVM\GIT\dists\CLRScumm\clr-graphics.obj 1
Error LNK2028 unresolved token (0A000112) "public: __thiscall Common::String::String(class Common::String const &)" (??0String@Common@@$$FQAE@ABV01@@Z) referenced in function "public: __thiscall Common::Event::Event(struct Common::Event const &)" (??0Event@Common@@$$FQAE@ABU01@@Z) CLRScumm D:\ScummVM\GIT\dists\CLRScumm\clr-events.obj 1
Error LNK2001 unresolved external symbol "public: virtual struct Graphics::Surface * __thiscall ModularBackend::lockScreen(void)" (?lockScreen@ModularBackend@@UAEPAUSurface@Graphics@@XZ) CLRScumm D:\ScummVM\GIT\dists\CLRScumm\OSystem_CLR.obj 1
class CLRGraphicsManager : virtual public GraphicsManager, public Common::EventObserver {
public:
CLRGraphicsManager(CLREventSource* source);
virtual ~CLRGraphicsManager() {}
typedef Common::Array<GraphicsMode> GraphicsModeArray;
GraphicsModeArray _graphicsModes;
Common::Array<int> _graphicsModeIds;
int _graphicsMode;
int _firstGLMode;
int _defaultSDLMode;
int _defaultGLMode;
//void setupGraphicsModes();
virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
virtual int getDefaultGraphicsMode() const;
virtual bool setGraphicsMode(int mode);
virtual int getGraphicsMode() const;
hey, welcome!
first, use code tags the <> in the side editor bar is the easy way to add them.
second, c++ errors propagate so usually the top 1-5 erros is all you care about when it spews. Fix and try again (unless its a billion lines of code and takes a day to compile, but presumably you are not on a gigantic project).
Next, the c++ string is string, and case matters. String is something else, a third party something, possibly a microsoftism. If you want to use whatever String is, you need to include a c++ file that defines it (.h header and .cpp) or a library or something. Its not part of the language. This could be <windows.h> in which case you need to be sure your project is set up to use the windows libraries.
string s; //c++, OK if you included <string>
String s; //not ok, third party!
It takes practice to read c++ errors. Once you 'get' it, you will see the madness in the method, but at first, it may as well be spouting in hieroglyphics.
Linker errors are not CODE errors, usually. They usually mean the code is OK but the project setup is borked. If it is a code error, it is usually a problem with a #include or misuse of a library.
This could be a chained problem. EG you download library X which needs Y which needs Z ... and so on... if something is missing it blows up. Microsoft has a binary examiner called 'depends.exe' that is part of visual studio and can help unravel these. Or you can read the docs on the libs one by one to see if they say what else you need. This process can be very painful.
Thanks for your help.
I got past those linker errors, by adding an include reference to 'D:\ScummVM\GIT\common' which is an external SCUMM VM project I am referencing.
However now I seem to be having troubling with this compiler error.
Severity Code Description Project File Line Suppression State
Error C2039 'fabs': is not a member of '`global namespace'' CLRScumm C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.22.27905\include\cstdlib 20
I found out that fabs is defined in corert_math.h which seems to be some sort of Microsoft mathematical library.
It is referenced by the Scumm VM project I just mentioned. This project compiles by itself so I am guessing I must be missing a reference to this external library in my project.
I guess this external Scumm VM project must be referencing it somehow, but I don't know how.
How would you generally go about referencing this library? Is there a visual studio project property I need to set?