WIITD / raylib-freebasic

FreeBasic bindings for raylib
MIT License
25 stars 7 forks source link

Including shared object for linking #inclib "raygui" #9

Closed Axle-Ozz-i-sofT closed 1 year ago

Axle-Ozz-i-sofT commented 1 year ago

Hi, It may be worthwhile including the Linux and windows libraries in raylib.bi and or raygui.bi. At the moment I am including them in my project source using #ifdef

example:

' Test if Windows or Unix OS
#ifdef __FB_WIN32__
#inclib "raylibdll"  'Windows dll.a
' Other OS specific defines
#endif
#ifdef __FB_UNIX__'__FB_LINUX__
#include "raylib"  'Linux .so
' Other OS specific defines
#endif
#include once "raylib.bi"
#include once "raygui.bi"

I am not sure if we can use an include guard for library objects the same as we do headers. Axle

Axle-Ozz-i-sofT commented 1 year ago

I just tested the latest #include change for raylib.bi and raygui.bi

raylib.bi changes

'#inclib "raylib"

#if defined(__FB_CYGWIN__) or defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__)
    #inclib "GL"
    #inclib "X11"
    #inclib "raylib"
#endif

#ifdef __FB_LINUX__
    #inclib "dl"
    #inclib "rt"
#elseif defined(__FB_CYGWIN__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__)
    #inclib "Xrandr"
    #inclib "Xinerama"
    #inclib "Xi"
    #inclib "Xxf86vm"
    #inclib "Xcursor"
#elseif defined(__FB_DARWIN__)
    #inclib "OpenGL"
    #inclib "Cocoa"
#elseif defined(__FB_WIN32__)
    #inclib "opengl32"
    #inclib "gdi32"
    #inclib "winmm"
    #inclib "raylibdll"
#endif

Raygui.bi (I am using raylib,raygui as a combined build. aka raygui is built into the raylib dll/so. I commented out '#inclib "raygui" as it is already included in raylib.bi, but in your case I guess if if raygui is a separate build (which also includes raylib I beleive, then maybe

#ifdef __FB_WIN32__
#inclib "rayguidll"
' Other OS specific defines
#endif
#ifdef __FB_UNIX__'__FB_LINUX__
#include "raygui"
' Other OS specific defines
#endif

I am uncertain how to use include guard to separate the different C raylib/raygui dynamic library builds. I am using Makefile PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_21 so that it is a single shared library. raymath.h is already built with raylib rcore in raylib.so and raylibdll.a/raylib.dll

I felt it was easier to just include raygui in raylib as raygui is quite small anyway. :) Axle [edit] P.S. Only #include "raylib.bi" and as well #include "raygui.bi" are required in the project source with the above changes.

WIITD commented 1 year ago

inclib "raylib" for me worked on both windows and linux so i haven't made any changes to that, and about raygui, i made it use separate lib because prebuilt raylib lib form offical repo and raylib packages from linux repositories (for example raylib package from arch repo) dont include raygui by default, that way its obvious that user have to have raylib and raygui on their system to use raygui

Axle-Ozz-i-sofT commented 1 year ago

That's interesting. The static library archive is raylib.a and the shared library is raylibdll.a (using the default raylib/src/Makfile) If I don't use "raylibdll" on windows it looks for the static library and fails. Same with Lubuntu, I have to use "raylib". Maybe I am using different linker settings for the compiler. I'll watch as I do more examples.

I don't use the prebuilt libraries and build locally. As raygui will also build raylib to run I just combined them as raylib. I just #inclib "raylib/dll" for both. Building local is easy as long as you rename ./raylib.Vxx to ./raylib and raygui.Vxx to raygui and are both in the same directory. I had some problems building the libraries on Lubuntu and had to locate raylib and raygui in /home/user or I get path not found issues. (I'm not a strong Linux user). I am doing this for some books, so I have to keep some sort of version constancy, so I may do things a little different to what's common.

It shouldn't make any difference in the headers other than the #inclib "xxxx" line. :) I am uploading the first 2 books in Draft Preview at the moment to github with source for the examples. And I will also upload the examples for the next 4 books as I get to them including 5 libraries used in the books. I have put the shapes_basic_shapes and the raygui_controls_test_suite conversions. The Python conversions are based on cffi_raylib "pyray". I have made a note of the include variations raylib/raylibdll in the FB examples.

Thanks Axle

P.S. I am using the release versions only and not from the current repo. raygui-3.2.tar.gz raygui-3.2.zip raylib-4.2.0.tar.gz raylib-4.2.0.zip The examples had not been updated so some were broken.

WIITD commented 1 year ago

The static library archive is raylib.a and the shared library is raylibdll.a

i think i know why #inclib "raylib" worked for me on both windows and linux. i compiled raylib and raygui as shared libraries for linux as libraylib.so and libraygui.so and for windows as libraylib.dll and libraygui.dll which allowed fb compiler to locate and link them you are compiling raylib for windows as raylibdll.a which changes lib name, so the compiler can't find it because it looks for raylib/libraylib

Axle-Ozz-i-sofT commented 1 year ago

This is the default output for the .\raylib\src\Makefile

Windows:
Line 461:LDFLAGS += -Wl,--out-implib,$(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME)dll.a Output shared:

Linux:
Line 468:LDFLAGS += -Wl,-soname,lib$(RAYLIB_LIB_NAME).so.$(RAYLIB_API_VERSION) Output shared: libraylib.so.4.2.0 libraylib.so (symbolic link) Output static: libraylib.a

I am just following the defaults set by ray :) raylib standalone (no raygui) frorm https://github.com/raysan5/raylib/releases/tag/4.2.0 P.S. the precompiled versions are broken so you will need to look at v4..0.0 release. 2022-10-26 23 07 50 2022-10-26 23 08 02

P.S. I have updated the shapes and gui examples from the updates in the raylib repository. If you want me to change the info I am happy to modify it :) https://github.com/Axle-Ozz-i-sofT/A-BEGINNERS-GUIDE-TO-PROGRAMMING/tree/main/3_Libraries_Overview/Tests_source/raylib/FreeBASIC

Axle-Ozz-i-sofT commented 1 year ago

Hello

First what may be a needed apology. Since I started with FB on Windows and Linux.. Mainly Windows I have been attempting to work out where to place the library files. I have had many conflicting suggestions about where to place the .a and .dll files. Normally (coming from C MinGW) I would expect: .\include\name.h .\bin\name.dll .\lib\libname.dll.a

But, and I am still uncertain about this, it would appear that FB only needs the name.dll to be in the project folder, and no def or name.dll.a is required at all :( I have asked about this again in the FB forums to see if I can get a definitive answer...

I just attempted to compile the "shapes_basic_shapes.bas" with only libwinpthread-1.dll and raylib.dll next to the source and raylib.bi, raygui,bi and raymath.bi in the FB\inc directory and it compiles and links fine.

I removed all reference to #inclib "raylibdll" and left only #inclib "raylib" in your raylib.bi.

I am guessing that #inclib "raylib" is linking directly against the raylib.dll in the project directory the same as gcc does in Linux against the raylib.so

FB and the help docs are very ambiguous about this :(

So if I have added confusion I do very much apologize. Axle