Wgpu: Linking Errors.

Created on 12 Feb 2020  路  23Comments  路  Source: gfx-rs/wgpu

[ 33%] Linking C executable triangle /usr/bin/ld: CMakeFiles/triangle.dir/main.c.o: in functionmain':
/home/holden/Desktop/work/forks/wgpu/examples/triangle/main.c:260: undefined reference to wgpu_render_pass_set_pipeline' /usr/bin/ld: /home/holden/Desktop/work/forks/wgpu/examples/triangle/main.c:261: undefined reference towgpu_render_pass_set_bind_group'
/usr/bin/ld: /home/holden/Desktop/work/forks/wgpu/examples/triangle/main.c:262: undefined reference to wgpu_render_pass_draw' collect2: error: ld returned 1 exit status make[3]: *** [CMakeFiles/triangle.dir/build.make:101: triangle] Error 1 make[3]: Leaving directory '/run/media/holden/45993E4516E8C2C4/Git/forks/wgpu/examples/triangle/build' make[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/triangle.dir/all] Error 2 make[2]: Leaving directory '/run/media/holden/45993E4516E8C2C4/Git/forks/wgpu/examples/triangle/build' make[1]: *** [Makefile:84: all] Error 2 make[1]: Leaving directory '/run/media/holden/45993E4516E8C2C4/Git/forks/wgpu/examples/triangle/build' make: *** [Makefile:108: example-triangle] Error 2

bug

Most helpful comment

This is the same issue as this then right? https://github.com/rust-lang/rust/issues/50007

All 23 comments

Thank you for the report!
I was seeing this as well on Linux, although for the past weeks (months?) there was always more important things to address, so I didn't investigate.
A brief look at the symbols shows that they are there. Also, this works on macOS.
Any help in investigating this would be great!

I double-checked it now, and I was wrong - the symbols are totally missing:

kvark@ant /hub/moz/wgpu/examples/compute/build $ objdump -t /hub/moz/wgpu/target/debug/libwgpu_native.so | grep pass_dispatch
kvark@ant /hub/moz/wgpu/examples/compute/build $ objdump -t /hub/moz/wgpu/target/debug/libwgpu_native.so | grep set_pipeline

And here they are fully exposed by wgpu-core:

    #[no_mangle]
    pub unsafe extern "C" fn wgpu_compute_pass_set_pipeline(
        pass: &mut RawPass,
        pipeline_id: id::ComputePipelineId,
    ) {
        pass.encode(&ComputeCommand::SetPipeline(pipeline_id));
    }

So what might be happening is that the linker doesn't realize that C functions from dependent crates (going from wgpu-native) also need to be exposed?

Here is the Preceding Output:
1.txt

github.com/eqrion/cbindgen/issues/49

@ZKing1000 thanks for the links!

It appears that we are able to work around this issue by adding #[linkage = "external"]

It's annoying and strange that we'd need to put it on each and every function.

Edit: it doesn't work:

error[E0658]: the linkage attribute is experimental and not portable across platforms

I'm not very Familiar with Rust, but I can try to help..

This is the same issue as this then right? https://github.com/rust-lang/rust/issues/50007

Looks like it.

I think I fixed... The symbols are present in libwgpu_native.a, but not .so.

examples/triangle/build/CMakeCache.txt:WGPU_LIBRARY:FILEPATH=/home/holden/Desktop/work/forks/wgpu/target/debug/libwgpu_native.a FROM .so

but now there are issues with libm (math library)

Built it:
cd examples/triangle
gcc -lglfw -lm -ldl -pthread -I../../ffi -I../../examples main.c framework.c libwgpu_native.a -o main

backtrace.txt

I compiled this binary on Manjaro Linux with the -g flag.
Use GDB to run and debug.
https://drive.google.com/file/d/10yWzj4Mz4p2wFuu1Aoye3DJ4RtnoN-oE/view?usp=sharing

Edit: Compute Example compiles and runs fine.

Same on Windows. I dump exports in .lib file, they are exported but with undersocre prefix.

Dump of file C:\Users\elgun\Desktop\wgpu\target\release\wgpu_native.dll.lib

File Type: LIBRARY

     Exports

       ordinal    name

                  _rust_eh_personality
                  _wgpu_adapter_destroy
                  _wgpu_adapter_request_device
                  _wgpu_bind_group_destroy
                  _wgpu_buffer_destroy
                  _wgpu_buffer_map_read_async
                  _wgpu_buffer_map_write_async
                  _wgpu_buffer_unmap
                  _wgpu_command_buffer_destroy
                  _wgpu_command_encoder_begin_compute_pass
                  _wgpu_command_encoder_begin_render_pass
...

@elgunhuseynli this looks like a different issue. Underscores could very well be expected there - a subject of calling convention. The original problem with linking was about routines exported from wgpu-core only, while your list has stuff from wgpu-native.

@kvark If underscores are expected why I'm getting unresolved external symbol error in Visual Studio? Maybe am I doing something wrong? :/

@elgunhuseynli are you seeing the same symbols unresolved as the original issue? If not, let's have a separate one.

@kvark I get unresolved external symbol errors for all symbols even for wgpu_request_adapter_async

@elgunhuseynli please file another issue, it looks like nothing links for you at all.

Going to remove that from blockers for the release. First, because Rust users aren't affected. And second, because all is good as long as we provide the binary builds.

Seems this issue is external to us. If there is another issue, feel free to re-file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lordnoriyuki picture lordnoriyuki  路  21Comments

fintelia picture fintelia  路  23Comments

MarekLg picture MarekLg  路  39Comments

FlorianUekermann picture FlorianUekermann  路  18Comments

simast picture simast  路  15Comments