Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: cannot load shared library dllsdl2_stubs #33

Open
idimension18 opened this issue May 10, 2023 · 8 comments
Open

Fatal error: cannot load shared library dllsdl2_stubs #33

idimension18 opened this issue May 10, 2023 · 8 comments

Comments

@idimension18
Copy link

Hi, I am on manjaro (arch linux base distro)
I tried to compile a game with ocamlc + ocamlfind and it works.
But when I run the executable I get the error :
Fatal error: cannot load shared library dllsdl2_stubs
Reason: /home/idimension/.opam/default/lib/stublibs/dllsdl2_stubs.so: undefined symbol: SDL_WriteBE32

SDL2 version : 2.26.5
OCaml version : 4.14.0

@fccm2
Copy link

fccm2 commented Jul 13, 2024

If you don't need this function (this is probably the case), just remove it from the sources.
Here is the patch:

diff --git a/src/sdlrwops.ml b/src/sdlrwops.ml
index 64fac6b..185e9f4 100644
--- a/src/sdlrwops.ml
+++ b/src/sdlrwops.ml
@@ -72,7 +72,6 @@ module BigEndian = struct
   external read64 : t -> uint64 = "caml_SDL_ReadBE64"
 
   external write16 : t -> uint16 -> unit = "caml_SDL_WriteBE16"
-  external write32 : t -> uint32 -> unit = "caml_SDL_WriteBE32"
   external write64 : t -> uint64 -> unit = "caml_SDL_WriteBE64"
 
 end
diff --git a/src/sdlrwops.mli b/src/sdlrwops.mli
index 3f6e106..23d0880 100644
--- a/src/sdlrwops.mli
+++ b/src/sdlrwops.mli
@@ -86,9 +86,6 @@ module BigEndian : sig
   external write16 : t -> uint16 -> unit = "caml_SDL_WriteBE16"
   (** {{:http://wiki.libsdl.org/SDL_WriteBE16}api doc} *)
 
-  external write32 : t -> uint32 -> unit = "caml_SDL_WriteBE32"
-  (** {{:http://wiki.libsdl.org/SDL_WriteBE32}api doc} *)
-
   external write64 : t -> uint64 -> unit = "caml_SDL_WriteBE64"
   (** {{:http://wiki.libsdl.org/SDL_WriteBE64}api doc} *)
 end
diff --git a/src/sdlrwops_stub.c b/src/sdlrwops_stub.c
index 0649505..f940c52 100644
--- a/src/sdlrwops_stub.c
+++ b/src/sdlrwops_stub.c
@@ -165,7 +165,6 @@ write_int_stub(Uint8, SDL_WriteU8, "writeU8")
 write_int_stub(Uint16, SDL_WriteLE16, "LittleEndian.write16")
 write_int_stub(Uint16, SDL_WriteBE16, "BigEndian.write16")
 write_int_stub(Uint32, SDL_WriteLE32, "LittleEndian.write32")
-write_int_stub(Uint32, SDL_WriteBE32, "BigEndian.write32")
 write_int_stub(Uint64, SDL_WriteLE64, "LittleEndian.write64")
 write_int_stub(Uint64, SDL_WriteBE64, "BigEndian.write64")
 

@fccm2
Copy link

fccm2 commented Jul 13, 2024

Recent versions of ocaml provide an equivalent function:

String.get_int32_be : string -> int -> int32

@36000000
Copy link

Please confirm:

git apply patch
cd src
cp Makefile.config.unix Makefile.config
make gen
make dep
make opt byte
cd ..
opam install .
utop
#use topfind;;
#require sdl2;;
Cannot load required shared library dllsdl2_stubs.
Reason: /home/user/.opam/default/lib/stublibs/dllsdl2_stubs.so: /home/user/.opam/default/lib/stublibs/dllsdl2_stubs.so: undefined symbol: SDL_WriteBE32.

The issue persists.

@fccm2
Copy link

fccm2 commented Aug 27, 2024

if you don't need this function, just remove it from the sources,
otherwise you can try an alternative solution

@36000000
Copy link

36000000 commented Sep 6, 2024

Sorry, I made the error with

1) opam install .

It should be

2) opam install -w .

or

3) opam upgrade -w .

In 1) the changes in the source code means nothing. It is not "applied". It install the old version without changes made in code. But in 2), 3) the changes in the source compile to binary and installs. The issue is no more. We may close this

@fccm2
Copy link

fccm2 commented Sep 6, 2024

i think you're right, if i remember correctly i think i also had a similar issue in the past
if i remember correctly, what i did was to remove or moved away, or renamed the ".git" directory (for example as "_git")
if i remember correctly, it's also possible to have 2 different directories, one managed with git, and another "private/drafty" developpement directory for local experiments.
i'm not using opam anymore, because my new computer seem to be weaker than the previous one, where i was using opam more. i'm not using ocamlfind anymore too, this is why it's difficult to maintain the "opam" file, and also the ocamlfind files.
if you are willing to maintain those 2, in this repo (in the fccm2's fork, because i forgot my password for fccm), you are wellcome.

do you think I should add your explanations in the readme file? or in the install file? or in another file? maybe I should name it "development.txt" ? or just "DEV.txt" ?

do you think i should remove the links to all those "SDL_WriteBE32/16/64" functions from the next release, and/or git-head ?

do you know if opam accepts .zip files ? (because 'tar cf' is broken on my current computer)

what do you think would be the best solutions for all these issues ?

@fccm2
Copy link

fccm2 commented Sep 7, 2024

hi again,
i downloaded SDL2-2.26.5 from: https://www.libsdl.org/release/SDL2-2.26.5.tar.gz
at line +795 of the file: SDL2-2.26.5/include/SDL_rwops.h, the function SDL_WriteBE32() is still there:

extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);

the doc-page doesn't seem to talk about any issue with it.

This function doesn't seem to be there in dbuenzli's tsdl.ml, maybe dbuenzli removed it from his thin bindings because there is an issue with it...?

... or is it an issue, because i usually forget to put -fPIC ? (now that chatgpt is there, i have been able to ask what is position independant code)

@fccm2
Copy link

fccm2 commented Sep 19, 2024

I got an update to debian 12, which brings the same version of sdl2 that you mention ("2.26.5").
I don't have any issue with: undefined symbol: SDL_WriteBE32

I probably did an error somewhere that produces an error in your environment.

Did you try to compile a small C test file with this function?
like for example the one below (provided by chatgpt):
(compile with:

gcc -o wbe32.exe wbe32.c -lSDL2

)

#include <SDL2/SDL.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        fprintf(stderr, "SDL initialization error: %s\n", SDL_GetError());
        return 1;
    }

    // Open the file using SDL_RWFromFile (SDL_RWops)
    SDL_RWops *rw = SDL_RWFromFile("output.bin", "wb");
    if (!rw) {
        fprintf(stderr, "Error opening file: %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    // Integer to write (in Little-Endian on most systems)
    Uint32 value = 123456789;

    // Write the value in Big-Endian to the file
    if (SDL_WriteBE32(rw, value) == 0) {
        fprintf(stderr, "Error writing to file: %s\n", SDL_GetError());
        SDL_RWclose(rw);
        SDL_Quit();
        return 1;
    }

    // Close the file
    SDL_RWclose(rw);

    // Clean up SDL
    SDL_Quit();

    printf("Writing completed successfully\n");

    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants