SDL sample application

80 views
Skip to first unread message

Lionel G Landwerlin

unread,
Aug 26, 2015, 7:36:16 AM8/26/15
to Native-Client-Discuss
Hi there,

Is there an SDL (1.2) sample application example somewhere?

I found this example on github : https://github.com/opichals/NaCl-SDL-test
But it looks a bit outdated (as it doesn't compile).

I troed to build my application with a Makefile having the LIBS set to :

LIBS = SDL SDLmain nacl_io ppapi_simple ppapi_gles2 ppapi stdc++ z rt util pthread

But that doesn't compile because it misses the right include directory to find the SDL headers.

So I added the cflags returned by sdl-config config : 

CFLAGS = \
        -I$(NACL_SDK_ROOT)/toolchain/linux_x86_glibc/x86_64-nacl/usr/include/SDL \
        -Dmain=SDL_main \
        -D_REENTRANT

But that fails linking :

out/pepper_46/toolchain/linux_x86_glibc/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/bin/ld: out/pepper_46/toolchain/linux_x86_glibc/bin/../lib/gcc/x86_64-nacl/4.4.3/../../../../x86_64-nacl/lib/../lib64/libppapi_stub.a(ppapi_plugin_main_399d0cf7.o): undefined reference to symbol 'PPP_GetInterface'
out/pepper_46/lib/glibc_x86_64/Release/libppapi_simple.so: error adding symbols: DSO missing from command line

I then moved on leaving LIBS empty and set LDFLAGS manually to result of sdl-config --libs :

CFLAGS = \
        -I$(NACL_SDK_ROOT)/toolchain/linux_x86_glibc/x86_64-nacl/usr/include/SDL \
        -Dmain=SDL_main \
        -D_REENTRANT

LDFLAGS = \
        -L$(NACL_SDK_ROOT)/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib \
        -lRegal \
        -lglslopt \
        -lppapi_gles2 \
        -Wl,-unacl_main \
        -Wl,-undefined=PSUserMainGet \
        -lSDLmain \
        -lSDL \
        -lppapi_gles2 \
        -lcli_main \
        -lnacl_spawn \
        -ltar \
        -lppapi_simple \
        -lnacl_io \
        -lppapi \
        -lm \
        -lstdc++ \
        -lpthread

But then again it fails to link :

out/pepper_46/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib/libcli_main.a(cli_main.o): In function `cli_main':
cli_main.c:(.text+0x15a): undefined reference to `nacl_main'
collect2: ld returned 1 exit status

I understand SDL depends on ppapi_simple, but I can't find a set of flags that actually work.

Any tips?

Thanks,

-
Lionel 

Lionel G Landwerlin

unread,
Aug 26, 2015, 9:24:42 AM8/26/15
to Native-Client-Discuss
Changing the order of the linker's options makes the app compile :

LDFLAGS = \
        -L$(NACL_SDK_ROOT)/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib \
        -lRegal \
        -lglslopt \
        -Wl,-undefined=PSUserMainGet \
        -Wl,-undefined=nacl_startup_untar \
        -lSDL \
        -lppapi_gles2 \
        -lcli_main \
        -lSDLmain \
        -lnacl_spawn \
        -ltar \
        -lppapi_simple \
        -lnacl_io \
        -lppapi \
        -lm \
        -lpthread

The additional nacl_startup_untar was needed though.
But then the main function is never called.

Ben Smith

unread,
Aug 26, 2015, 2:21:41 PM8/26/15
to native-cli...@googlegroups.com
Take a look at the sdl-tests port in naclports. I just built it using x86-64_glibc and got the following commandline:

$NACL_SDK_ROOT/toolchain/linux_x86_glibc/bin/x86_64-nacl-gcc -o testbitmap.nexe \
naclports/src/out/build/sdl-tests/SDL-1.2.14/test/testbitmap.c -DNDEBUG -O2 \
-I$NACL_SDK_ROOT/toolchain/linux_x86_glibc/x86_64-nacl/usr/include/SDL \
-Dmain=SDL_main -D_REENTRANT -DHAVE_OPENGL \
-L$NACL_SDK_ROOT/lib/glibc_x86_64/Release \
-Wl,-rpath-link=$NACL_SDK_ROOT/lib/glibc_x86_64/Release \
-L$NACL_SDK_ROOT/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib -lRegal \
-lglslopt -lppapi_gles2 -Wl,-unacl_main -Wl,-undefined=PSUserMainGet -lSDLmain \
-lSDL -lppapi_gles2 -lcli_main -lnacl_spawn -ltar -lppapi_simple -lnacl_io \
-lppapi -lm -lstdc++ -lpthread -lnacl_io -lstdc++

Pretty horrible, but it seems to work.


--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-discuss.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Lionel G Landwerlin

unread,
Aug 27, 2015, 8:31:38 AM8/27/15
to Native-Client-Discuss
Hi Ben,

Thanks for pointing out the test. It does compile indeed.

I did create nmf & html files for the compiled at using :

$NACL_SDK_ROOT/tools/create_nmf.py testbitmap.nexe -o testbitmap.nmf -s .
$NACL_SDK_ROOT/tools/create_html.py testbitmap.nexe

But then the binary fails to load using sel_ldr.py :

 $NACL_SDK_ROOT/tools/sel_ldr.py -v testbitmap.nexe 
ROOT    = $NACL_SDK_ROOT
SEL_LDR = $NACL_SDK_ROOT/tools/sel_ldr_x86_64
IRT     = $NACL_SDK_ROOT/tools/irt_core_x86_64.nexe
HELPER  = $NACL_SDK_ROOT/tools/nacl_helper_bootstrap_x86_64
LD.SO = $NACL_SDK_ROOT/toolchain/linux_x86_glibc/x86_64-nacl/lib/runnable-ld.so
['$NACL_SDK_ROOT/tools/nacl_helper_bootstrap_x86_64', '$NACL_SDK_ROOT/tools/sel_ldr_x86_64', '--r_debug=0xXXXXXXXXXXXXXXXX', '--reserved_at_zero=0xXXXXXXXXXXXXXXXX', '-q', '-a', '-B', '$NACL_SDK_ROOT/tools/irt_core_x86_64.nexe', '$NACL_SDK_ROOT/toolchain/linux_x86_glibc/x86_64-nacl/lib/runnable-ld.so', '--library-path', '$NACL_SDK_ROOT/toolchain/linux_x86_glibc/x86_64-nacl/usr/lib:$NACL_SDK_ROOT/lib/glibc_x86_64/Release:$NACL_SDK_ROOT/toolchain/linux_x86_glibc/x86_64-nacl/lib', 'testbitmap.nexe']
[138669,2608871296:13:25:27.149953] BYPASSING ALL ACL CHECKS
[138669,2608871296:13:25:27.150294] Native Client module will be loaded at base address 0x000035d000000000
testbitmap.nexe: error while loading shared libraries: testbitmap.nexe: cannot open shared object file: Error 38

Adding the --library-path ./lib64 doesn't help either.

Interestingly it seems to load fine in Chrome 43 (on Linux desktop), but as I mentioned in my second mail, the main function doesn't seem to be called.
I added a fprintf(stderr, "Start!\n"); statement in the app and that doesn't appear anywhere in the page.
Also nothing's being drawn in the area of the nacl plugin.

Are you seeing the same problem?

Thanks,

-
Lionel
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-discuss+unsub...@googlegroups.com.

Lionel G Landwerlin

unread,
Aug 27, 2015, 12:05:02 PM8/27/15
to Native-Client-Discuss
Looking at the SDL 1.2 code, it seems it was missing the following line :

PPAPI_SIMPLE_REGISTER_MAIN(nacl_main);

in SDL_nacl_main.c (which the sdl 2.0 package has).

Adding this makes it work.

Thanks for your help!

-
Lionel
Reply all
Reply to author
Forward
0 new messages