I received several .dll files with a simple framework. And in the project I have only two files.

1), where to contain all declarations of functions from dll. 2) The file where I want to call some of these functions.

one)

#pragma once #if defined(FRAMEWORK_PROJECT) #define FRAMEWORK_API __declspec(dllexport) #else #define FRAMEWORK_API __declspec(dllimport) #endif Class Sprite; FRAMEWORK_API Sprite* createSprite(const char* path); FRAMEWORK_API void drawSprite(Sprite*, int x, int y); FRAMEWORK_API void getSpriteSize(Sprite* s, int& w, int &h); FRAMEWORK_API void destroySprite(Sprite* s); FRAMEWORK_API void drawTestBackground(); FRAMEWORK_API void getScreenSize(int& w, int &h); FRAMEWORK_API unsigned int getTickCount(); FRAMEWORK_API void showCursor(bool bShow); enum class FRKey { RIGHT, LEFT, DOWN, UP, COUNT }; enum class FRMouseButton { LEFT, MIDDLE, RIGHT, COUNT }; class FRAMEWORK_API Framework { public: virtual void PreInit(int& width, int& height, bool& fullscreen) = 0; virtual bool Init() = 0; virtual void Close() = 0; virtual bool Tick() = 0; // param: xrel, yrel: The relative motion in the X/Y direction // param: x, y : coordinate, relative to window virtual void onMouseMove(int x, int y, int xrelative, int yrelative) = 0; virtual void onMouseButtonClick(FRMouseButton button, bool isReleased) = 0; virtual void onKeyPressed(FRKey k) = 0; virtual void onKeyReleased(FRKey k) = 0; virtual ~Framework() {}; }; FRAMEWORK_API int run(Framework*); 

2)

 #include "Framework.h" class MyFramework : public Framework { public: virtual bool Tick() { drawTestBackground(); return (false); } }; int main(int argc, char *argv[]) { return run(new MyFramework); } 

But on any call, I get an undfined reference error. I do not have the source code dll. Tell me what is wrong: my mistake, or perhaps in the most dll?

I just started working on Windows and first encountered a DLL, so I will be grateful for any indication of errors.

I compile it like this: g ++ frame.lib game.cpp

Error examples

  • 2
    and transfer the library for linking to the compiler via the -l key, who will? - Fat-Zer 3:54 pm
  • This kind of error occurs if the linker does not see the code, that is, the implementation of the called functions. He sees the headers, takes functions on them, tries to link the implementations, but cannot find the undefined reference - Alexander Chernin
  • Comrade @ Fat-Zer, please tell me how to properly compile with this flag. Let me have a frame.lib. I compile like this: g ++ -o game.exe game.cpp -lframe But it does not find my lib. - Laughing_Man
  • @Laughing_Man, where exactly does she lie? in the current directory? and .lib is most likely a static library, not a shared library. So most likely it should be specified along with the rest of the source / object files in the compiler options (linker); through -l should also work, but I don’t presume to. I do not know the peculiarities of the linker operation under win ... And also the -l key should usually be specified before the source codes / object codes that use these symbols (put it at the beginning). - Fat-Zer pm
  • @ Fat-Zer, everything in the current directory and .lib files and .dll - Laughing_Man

1 answer 1

So, what to do in such cases:

  1. link files correctly with -l -L flags.

  2. check or file was not created via visual stduio. If so, the file must be added to the project in Visual Stduio. Just through the command line will not compile.