GetObject - GetObjectA Linker Error

In my project, I have a function called GetObject that is wrapped in one of my classes in my static library. When I call the function in another project that uses my library, I got this error:

Error 1 error LNK2019: unresolved external character "public: class hamur :: HamurObject * __thiscall hamur :: HamurWorld :: GetObjectA (class std :: basic_string, class std :: allocator> const &)" (? GetObjectA @HamurWorld @hamur @ @QAEPAVHamurObject @ 2 @ABV? $ Basic_string @DU? $ Char_traits @D @std @@ V? $ Allocator @D @ 2 @@ std @@@ Z) function link public: virtual void __thiscall MainState :: Draw (void ) "(? Draw @MainState @@ UAEXXZ) MainState.obj

As I understand it, the GetObject problem is the preprocessor definition in "windows.h", and instead it becomes GetObjectA.

My question is:

I have never added the title "windows.h" to any of my files. I use SDL, Fmod, OpenGL. I found that this comes from SDL_opengl.h

I tried using:

#ifdef GetObject
#undef GetObject
#endif

It worked. Is this a good or only possible solution? I am trying to implement a library that should run on multiple platforms, but I have not tested it for any platform other than Windows, so now I am very worried about porting. It would be really nice to have some advice before things got worse for porting ...

My current environment is Windows Xp - Visual Studio 2008.

Thanks at Advance

+3
source share
2

, - (GetObject WINDOWS_GetObject) . , .

( UNIX). , , Windows SDL OpenGL , #undef. , GetObject . , UNIX, Windows:

// Your header file

#ifndef YOURHEADER_INCLUSION_GUARD
#define YOURHEADER_INCLUSION_GUARD

// ... your various includes ...

#ifdef OS_WINDOWS
#    ifdef GetObject
#        define MYPROJECT_MACRO_GETOBJECT_WAS_DEFINED
#    endif
#    undef GetObject
#endif

// ... the rest of your header ...

#ifdef OS_WINDOWS
#    if defined(MYPROJECT_MACRO_GETOBJECT_WAS_DEFINED)
#        undef MYPROJECT_MACRO_GETOBJECT_WAS_DEFINED
#        define GetObject GetObjectA
#    endif
#endif

#endif // End header inclusion guard

sloppier , , .

+4

Windows, , GetObject , SetObject .. , API Win32 - , #undef .

+3

Source: https://habr.com/ru/post/1754119/


All Articles