Jump to page: 1 2
Thread overview
Use bindbc-sdl statically
Apr 24, 2021
Ishax
Apr 24, 2021
russhy
Apr 24, 2021
Ishax
Apr 24, 2021
russhy
Apr 24, 2021
Ishax
Apr 24, 2021
Ishax
Apr 24, 2021
russhy
Apr 24, 2021
Ishax
Apr 24, 2021
russhy
Apr 24, 2021
Ishax
Apr 25, 2021
Mike Parker
Apr 24, 2021
ichneumwn
Apr 24, 2021
Ishax
Apr 24, 2021
russhy
Apr 25, 2021
Mike Parker
April 24, 2021

I am trying to get graphics working in D. All seems well with bindbc sdl, but I hit a nitpick: I prefer to be able to create a standalone executable when possible. I cannot get bindbc to be happy with sdl .a files. It's a small problem, but if there's a simple solution, I'm eager to hear it.

April 24, 2021

On Saturday, 24 April 2021 at 15:58:26 UTC, Ishax wrote:

>

I am trying to get graphics working in D. All seems well with bindbc sdl, but I hit a nitpick: I prefer to be able to create a standalone executable when possible. I cannot get bindbc to be happy with sdl .a files. It's a small problem, but if there's a simple solution, I'm eager to hear it.

.a are object files for linux right?

for static usage make sure you remove the part of code where you manually loadSDL, since it is not needed for static compilation

make sure to use this subConfiguration: https://github.com/BindBC/bindbc-sdl#via-dub-subconfigurations

and then make sure to add the lib to link in your "lflags" or as a "sourceFiles", both will work

send us your dub.json file maybe some things are misconfigured?

April 24, 2021

On Saturday, 24 April 2021 at 16:02:27 UTC, russhy wrote:

>

.a are object files for linux right?

Are they? I'm not very familiar with c++. I'm using windows. For that matter I should mention I'm using dub in vscode.

>

send us your dub.json file maybe some things are misconfigured?

...
dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
sourceFiles "lib/libSDL2.a" "lib/libSDL_image.a"

The following works fine but links dynamically:

...
dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
libs "SDL2" "SDL_image"
April 24, 2021

On Saturday, 24 April 2021 at 16:10:13 UTC, Ishax wrote:

>

On Saturday, 24 April 2021 at 16:02:27 UTC, russhy wrote:

>

.a are object files for linux right?

Are they? I'm not very familiar with c++. I'm using windows. For that matter I should mention I'm using dub in vscode.

>

send us your dub.json file maybe some things are misconfigured?

...
dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
sourceFiles "lib/libSDL2.a" "lib/libSDL_image.a"

The following works fine but links dynamically:

...
dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
libs "SDL2" "SDL_image"

on windows, for static compilation you have to use ".lib" files, not ".a"

also you are missing the

subConfigurations "bindbc-sdl" "staticBC"
April 24, 2021

On Saturday, 24 April 2021 at 16:13:12 UTC, russhy wrote:

>

on windows, for static compilation you have to use ".lib" files, not ".a"

also you are missing the

subConfigurations "bindbc-sdl" "staticBC"

So I have the lib files. It's failing with only an exit code. No window is appearing. It's using the same D code as with the dynamic setup which I was able to produce a window with.

dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
subConfigurations "bindbc-sdl" "staticBC"
libs "SDL2" "SDL2_image"
April 24, 2021

Yet the .exe functions if I supply it with .dlls. Thats silly.

April 24, 2021

On Saturday, 24 April 2021 at 16:48:49 UTC, Ishax wrote:

>

It's using the same D code as with the dynamic setup which I was able to produce a window with.
Yet the .exe functions if I supply it with .dlls. Thats silly.

you didn't read my message

Remove all the code used to loadSDL, it's not needed anymore with static compilation

dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
subConfigurations "bindbc-sdl" "staticBC"
sourceFiles "my_sdl2.lib" "my_sdl2image.lib"
``


```D
import bindbc.sdl;
import core.stdc.stdio;

int main() {
  SDL_Window* window = null;
  SDL_Surface* screenSurface = null;
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    printf("could not initialize sdl2: %s\n", SDL_GetError());
    return 1;
  }
  window = SDL_CreateWindow(
			    "hello_sdl2",
			    SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			    SCREEN_WIDTH, SCREEN_HEIGHT,
			    SDL_WINDOW_SHOWN
			    );
  if (window == null) {
    printf("could not create window: %s\n", SDL_GetError());
    return 1;
  }
  screenSurface = SDL_GetWindowSurface(window);
  SDL_FillRect(screenSurface, null, SDL_MapRGB(screenSurface.format, 0xFF, 0xFF, 0xFF));
  SDL_UpdateWindowSurface(window);
  SDL_Delay(2000);
  SDL_DestroyWindow(window);
  SDL_Quit();
  return 0;
}

This should work

April 24, 2021

On Saturday, 24 April 2021 at 17:20:06 UTC, russhy wrote:

>

This should work

I just tried your code. I get:
Program exited with code -1073741701

I put the libraries straight into the project root this time.

name "sdl2try2"
description "A minimal D application."
authors "Isaac"
copyright "Copyright © 2021, Isaac"
license "proprietary"
dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
subConfigurations "bindbc-sdl" "staticBC"
sourceFiles "sdl2.lib" "sdl2_image.lib"
import bindbc.sdl;
import core.stdc.stdio;

const SCREEN_WIDTH = 1024;
const SCREEN_HEIGHT = 720;

int main() {
  SDL_Window* window = null;
  SDL_Surface* screenSurface = null;
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    printf("could not initialize sdl2: %s\n", SDL_GetError());
    return 1;
  }
  window = SDL_CreateWindow(
			    "hello_sdl2",
			    SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			    SCREEN_WIDTH, SCREEN_HEIGHT,
			    SDL_WINDOW_SHOWN
			    );
  if (window == null) {
    printf("could not create window: %s\n", SDL_GetError());
    return 1;
  }
  screenSurface = SDL_GetWindowSurface(window);
  SDL_FillRect(screenSurface, null, SDL_MapRGB(screenSurface.format, 0xFF, 0xFF, 0xFF));
  SDL_UpdateWindowSurface(window);
  SDL_Delay(2000);
  SDL_DestroyWindow(window);
  SDL_Quit();
  return 0;
}
April 24, 2021

Try to add this in your dub file:

libs "user32" "gdi32" "shell32"

April 24, 2021

On Saturday, 24 April 2021 at 16:44:09 UTC, Ishax wrote:

>

So I have the lib files. It's failing with only an exit code. No window is appearing. It's using the same D code as with the dynamic setup which I was able to produce a window with.

dependency "bindbc-sdl" version="~>0.1.0"
versions "BindSDL_Static"
subConfigurations "bindbc-sdl" "staticBC"
libs "SDL2" "SDL2_image"

Hi, Linux programmer here who just went through the process of working with dll's and lib's on windows. In my current understanding, there are three ways of working with libraries:

  1. Load DLL's at runtime (LoadLibrary and such)
  2. Linking with DLL's at compile time. The compiler adds code to automatically load the DLL's when your program starts. You do this by linking against an import library. These have a .lib extension
  3. Linking against static libraries. These have a .lib extension

Note that 2. & 3. are different things, but the files you need end in .lib in both cases. You'll have to check that your .lib files are actually static libraries, not import libraries.

I am not sure if linking to outside sources is appropriate, so I will just copy-paste from stackoverflow:

"Use the lib command. If it's static, lib will show you a pile of .obj files inside. Not so if it's am implib."

lib /list foo.lib
« First   ‹ Prev
1 2