0

so I'm working on a game engine in VS2022 (https://github.com/DancingRicardo/Kepler-Engine for anyone who's interested) and I wanted to implement a very basic online multiplayer system, and decided on the standalone version of ASIO. However, I came across an error saying I can't overload a function with extern C linkage on Line 4706 of WinUser.h when compiling:

CloseWindow(
    _In_  HWND hWnd);

and Line 9324:

ShowCursor(
    _In_ BOOL bShow);

I assume this is in conflict with ASIO, as I never had this issue before, but I'm pretty sure I can't alter the Windows API lmao. Any help is appreciated. If you are trying to replicate the issue by building my game engine, apologies for the set up process, as it can be quite annoying since I haven't changed the linking process. All relevant code files are in /game/Networking.hpp or the /game/Networking folder. Thanks.

I wasn't able to try anything, since I am not experienced enough to mess around with ASIO and the WinAPI.

  • You probably define extern C functions CloseWindow and ShowCursor in your code - the error message should say where the conflicting function is defined. C language does not allow functions overload - you should rename them so they don't conflict with system names. C libraries often have names with library-specific prefixes to be safe (e.g. [libcurl](https://curl.se/libcurl/c/curl_easy_init.html), [libpq](https://www.postgresql.org/docs/9.1/libpq-exec.html#LIBPQ-EXEC-MAIN)). – dewaffled Jan 14 '23 at 20:05
  • "since I am not experienced enough to mess around with ASIO and the WinAPI" - that's a false premise. People use libraries without having to mess with them. The good news: you don't need to be crazy experienced. Just the basic knowledge about the compilation model (e.g. [here](https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work)). Next up go to the [FAQ about unresolved externals](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) and you will be able to diagnose your problem. – sehe Jan 14 '23 at 21:03

1 Answers1

0

C symbols cannot be overloaded (function overloading is a C++ feature that requires name mangling).

Something in the preprocessor stage is causing different declarations of the same C function to look different to the compiler.

Like someone commented, this can be because your own code declares different symbols by the names CloseWindow or ShowCursor. Alternatively, it could be that some of your code is interfering with the tokens (including _In_, HWND, hWnd or bShow) causing the same source to mean different things after the preprocessing stage.

You can ask the IDE to give you the preprocessed source to inspect. You can also search your code-base for these names - in particular when CloseWindow/ShowCursor appear as free functions in your own code or libraries or when these tokens appear in a #define preprocessor directive.

To make matters more complicated, preprocessor symbols can be defined in the build config (e.g. .vcproj, CMakeLists.txt, etc). I figure the chance of that directly happening is so slim, it's not worth trying to manually track. Instead, focus on the preprocessor output. Anything will eventually show up there.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • This makes sense. I’m also using Raylib, which has functions named CloseWindow and ShowCursor. I should be able to alter the api relatively easily for this then, since I rarely need to use those, and they don’t seem to be used anywhere else in the library. Thanks. – Bradley Fernandez Jan 14 '23 at 22:58
  • The usual way is to separate namespaces. Most serious C++ libraries already have/use namespaces to avoid precisely this problem. A very 1980s kind of problem :) – sehe Jan 14 '23 at 23:51