rdbo / libmem

Advanced Game Hacking Library for C, Modern C++, Rust and Python (Windows/Linux/FreeBSD) (Process/Memory Hacking) (Hooking/Detouring) (Cross Platform) (x86/x64) (DLL/SO Injection) (Internal/External) (Assembler/Disassembler)
GNU Affero General Public License v3.0
830 stars 101 forks source link

Added LM_STATIC preprocessor flag when doing a static build #243

Closed Overhatted closed 3 days ago

Overhatted commented 5 months ago

Simple PR to avoid adding "__declspec(dllexport)" to function declarations when creating a static library.

rdbo commented 2 weeks ago

Does it not work with LM_EXPORT defined in static builds? My idea was either export or import, I'm not sure about having neither as an option

luadebug commented 2 weeks ago

Does it not work with LM_EXPORT defined in static builds? My idea was either export or import, I'm not sure about having neither as an option

afaik if defined & during MSVC windows build it will let you build LIB. if not defined it should let you build DLL on windows OS by MSVC toolchain.

Overhatted commented 2 weeks ago

It does work with __declspec(dllexport) when building static libraries. Not even sure what the consequences are or if the methods get exported if the .lib is linked into a .dll. I think the compiler creates some trampoline methods when dllexport is specified though. Either way, all the projects I've used, used this approach of not adding anything when building a static library. For example:

  1. https://github.com/freetype/freetype/blob/3f3e3de34ee3613d621b643c58a40b93148e0932/include/freetype/config/public-macros.h#L72
  2. https://github.com/danoli3/FreeImage/blob/ebcb99952c6437f5e5afff52ad1a28664587782f/Source/FreeImage.h#L40
  3. https://github.com/google/googletest/blob/d144031940543e15423a25ae5a8a74141044862f/googletest/include/gtest/internal/gtest-port.h#L874
  4. https://github.com/libsdl-org/SDL/blob/d1af211010adb1030ce04860437fd5a580cf8eed/include/begin_code.h#L60
luadebug commented 2 weeks ago

Does it not work with LM_EXPORT defined in static builds?

Yes it works, this one is optimization targeted for Windows OS I guess. Dunno too problematic to push it without testing existing CI workflows that build libmem itself & Rust/Python3 bindings over different OS-es as well. Maybe bindings would need rework, but in case of OS-es it should be fine.

My idea was either export or import, I'm not sure about having neither as an option

Do you tend to keep only one define for this situation such as LM_EXPORT or LM_STATIC (This one keeps stuff relying over EXPORT defininition https://github.com/libsdl-org/SDL/blob/d1af211010adb1030ce04860437fd5a580cf8eed/include/begin_code.h#L60)?

Overall it looks good now.

Overhatted commented 3 days ago

This PR seems to be approved. Can someone merge it? I don't think I have permissions.

rdbo commented 3 days ago

I'm afraid this might break the automated build system... Only one way to find out 👀

rdbo commented 3 days ago

Works, thanks!