RobLoach / raylib-cpp

C++ Object Oriented Wrapper for raylib
https://robloach.github.io/raylib-cpp/
zlib License
669 stars 87 forks source link

RLAPI macro in Functions.hpp causes linking error when using MSVC + vcpkg #273

Closed Zentrom closed 9 months ago

Zentrom commented 9 months ago

The issue

The functions prefixed with the RLAPI macro in Functions.hpp cause a linking error. https://github.com/RobLoach/raylib-cpp/blob/f865785fee2cb18da6ad6a9012a2993a73f2a2b1/include/Functions.hpp#L301 Everything else works fine.

My setup

I use VS Studio 2022(MSVC) and vcpkg, which downloads, builds and links raylib on its own. I got raylib-cpp and included the header.

What causes the error

Vcpkg makes raylib use dynamic linking from the .dll by replacing a line: https://github.com/microsoft/vcpkg/blob/7032c5759f823fc8699a5c37d5f7072464ccb9a8/ports/raylib/portfile.cmake#L81 In raylib.h: Képkivágás Because of this the linker tries to import the wrapped functions marked with RLAPI from raylib.dll, which won't find. I guess this error only exists when raylib is used with dynamic linkage, because raylib-cpp tests contain tests of these functions and they don't fail.

Solution

Changing the RLAPI macro to RLCPPAPI solves it for me, which basically changes __declspec(dllimport) to static. So any reason not to change it in the lib aswell?

RobLoach commented 9 months ago

I believe we should likely move that function to a static class. It has always caused issues