vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.8k stars 2.16k forks source link

Undefined stbi symbols #19335

Open kuettler opened 1 year ago

kuettler commented 1 year ago

Describe the bug

Trying the v examples on linux I continue to hit a compile error:

$ v examples/tetris
==================
/tmp/v_1000/tetris.16755655504225379657.tmp.c:27103: warning: assignment discards qualifiers from pointer target type
tcc: error: undefined symbol 'stbi_flip_vertically_on_write'
tcc: error: undefined symbol 'set_png_compression_level'
tcc: error: undefined symbol 'write_force_png_filter'
tcc: error: undefined symbol 'write_tga_with_rle'
tcc: error: undefined symbol 'stbir_resize_uint8'
tcc: error: undefined symbol 'stbi_write_png'
tcc: error: undefined symbol 'stbi_write_bmp'
tcc: error: undefined symbol 'stbi_write_tga'
tcc: error: undefined symbol 'stbi_write_jpg'
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Reproduction Steps

See above

Expected Behavior

It works

Current Behavior

See above

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.1 a0490f2

Environment details (OS name and version, etc.)

V full version: V 0.4.1 a0490f2 OS: linux, Ubuntu 22.04.3 LTS Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz

getwd: /home/ulrich/lang/v/v vexe: /home/ulrich/lang/v/v/v vexe mtime: 2023-09-12 15:14:26

vroot: OK, value: /home/ulrich/lang/v/v VMODULES: OK, value: /home/ulrich/.vmodules VTMP: OK, value: /tmp/v_1000

Git version: git version 2.34.1 Git vroot status: 0.4.1-61-ga0490f2b .git/config present: true

CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

spytheman commented 1 year ago

That is weird 🤔 ... Please try this: v wipe-cache, then try again to compile Tetris with v -showcc examples/tetris, and paste the results.

spytheman commented 1 year ago

Another thing to try is: thirdparty/tcc/tcc.exe -std=gnu99 -D_DEFAULT_SOURCE -fwrapv -fPIC -I "thirdparty/stb_image" -o x.o -c 'thirdparty/stb_image/stbi.c' executed in the main V repo's top folder. If it works, do: nm x.o |grep stbi_write_tga . It should show something like this:

#0 22:00:33 ᛋ master /v/vnew❱nm x.o |grep stbi_write_tga
000000000001d141 T stbi_write_tga
000000000001caf5 t stbi_write_tga_core
000000000001d0a2 T stbi_write_tga_to_func
00000000000000a4 D stbi_write_tga_with_rle
kuettler commented 1 year ago
$ v wipe-cache
V cache folder /home/ulrich/.vmodules/cache was wiped.
V tmp.c and tests folder folder /tmp/v_1000 was wiped.

and I still get:

$ v -cg -showcc examples/tetris
> C compiler cmd: '/home/ulrich/lang/v/v/thirdparty/tcc/tcc.exe' '@/tmp/v_1000/tetris.11560144176784174811.tmp.c.rsp'
> C compiler response file "/tmp/v_1000/tetris.11560144176784174811.tmp.c.rsp":
  -fwrapv -g "/home/ulrich/.vmodules/cache/74/7412ca3ed3cd33244eea8513fd927ff5.module.stbi.o" -o "/home/ulrich/lang/v/v/examples/tetris/tetris" -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -D SOKOL_GLCORE33 -D SOKOL_NO_ENTRY -I "/home/ulrich/lang/v/v/thirdparty/libgc/include" -I "/home/ulrich/lang/v/v/thirdparty/fontstash" -I "/home/ulrich/lang/v/v/thirdparty/stb_image" -I "/home/ulrich/lang/v/v/thirdparty/sokol" -I "/home/ulrich/lang/v/v/thirdparty/sokol/util" -I "/home/ulrich/lang/v/v" "/tmp/v_1000/tetris.11560144176784174811.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE -bt25 -rdynamic "/home/ulrich/lang/v/v/thirdparty/tcc/lib/libgc.a" -ldl -lpthread -lm -lX11 -lGL -lXcursor -lXi -lpthread -ldl  
> C compiler cmd: 'cc' '@/tmp/v_1000/tetris.11560144176784174811.tmp.c.rsp'
> C compiler response file "/tmp/v_1000/tetris.11560144176784174811.tmp.c.rsp":
  -g "/home/ulrich/.vmodules/cache/74/7412ca3ed3cd33244eea8513fd927ff5.module.stbi.o" -o "/home/ulrich/lang/v/v/examples/tetris/tetris" -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -D SOKOL_GLCORE33 -D SOKOL_NO_ENTRY -I "/home/ulrich/lang/v/v/thirdparty/libgc/include" -I "/home/ulrich/lang/v/v/thirdparty/fontstash" -I "/home/ulrich/lang/v/v/thirdparty/stb_image" -I "/home/ulrich/lang/v/v/thirdparty/sokol" -I "/home/ulrich/lang/v/v/thirdparty/sokol/util" -I "/home/ulrich/lang/v/v" "/tmp/v_1000/tetris.11560144176784174811.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE -rdynamic "/home/ulrich/lang/v/v/thirdparty/tcc/lib/libgc.a" -ldl -lpthread -lm -lX11 -lGL -lXcursor -lXi -lpthread -ldl  
/tmp/v_1000/tetris.11560144176784174811.tmp.c:27120: warning: assignment discards qualifiers from pointer target type
tcc: error: undefined symbol 'stbi_flip_vertically_on_write'
tcc: error: undefined symbol 'set_png_compression_level'
tcc: error: undefined symbol 'write_force_png_filter'
tcc: error: undefined symbol 'write_tga_with_rle'
tcc: error: undefined symbol 'stbir_resize_uint8'
tcc: error: undefined symbol 'stbi_write_png'
tcc: error: undefined symbol 'stbi_write_bmp'
tcc: error: undefined symbol 'stbi_write_tga'
tcc: error: undefined symbol 'stbi_write_jpg'

This might well be an issue with tcc on my system or some other stray installation. I just did not know where to look.

kuettler commented 1 year ago

The single tests works fine:

ulrich@sancho v (master) $ thirdparty/tcc/tcc.exe -std=gnu99 -D_DEFAULT_SOURCE -fwrapv -fPIC -I "thirdparty/stb_image" -o x.o -c 'thirdparty/stb_image/stbi.c'
ulrich@sancho v (master) $ nm x.o |grep stbi_write_tga
000000000001d141 T stbi_write_tga
000000000001caf5 t stbi_write_tga_core
000000000001d0a2 T stbi_write_tga_to_func
00000000000000a4 D stbi_write_tga_with_rle
kuettler commented 1 year ago
$ nm ~/.vmodules/cache/74/7412ca3ed3cd33244eea8513fd927ff5.module.stbi.o | grep stbi_write_tga

does not show any match.

$ ll ~/.vmodules/cache/74/
total 160
drwxrwxr-x 2 ulrich ulrich   4096 Sep 13 21:46 ./
drwx------ 3 ulrich ulrich   4096 Sep 13 21:46 ../
-rw-rw-r-- 1 ulrich ulrich 151736 Sep 13 21:46 7412ca3ed3cd33244eea8513fd927ff5.module.stbi.o

vs

ll x.o 
-rw-rw-r-- 1 ulrich ulrich 295508 Sep 13 21:40 x.o
spytheman commented 1 year ago

Does it work if you do v -cc gcc run examples/tetris ?

spytheman commented 1 year ago

The difference in sizes in the .o files, makes me think, that they were compiled by different C compilers, or by the same one, but with different options.

kuettler commented 1 year ago

Using gcc does not change the situation:

ulrich@sancho v (master) $ v wipe-cache
V cache folder /home/ulrich/.vmodules/cache was wiped.
V tmp.c and tests folder folder /tmp/v_1000 was wiped.
ulrich@sancho v (master) $ v -cc gcc -cg -showcc  -dump-c-flags c-flags.txt examples/tetris
> C compiler cmd: 'gcc' '@/tmp/v_1000/tetris.1511315272736621368.tmp.c.rsp'
> C compiler response file "/tmp/v_1000/tetris.1511315272736621368.tmp.c.rsp":
  -fwrapv -g -no-pie "/home/ulrich/.vmodules/cache/9f/9fad469ee472836773f2de262ab5826d.module.stbi.o" -o "/home/ulrich/lang/v/v/examples/tetris/tetris" -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -D SOKOL_GLCORE33 -D SOKOL_NO_ENTRY -I "/home/ulrich/lang/v/v/thirdparty/libgc/include" -I "/home/ulrich/lang/v/v/thirdparty/fontstash" -I "/home/ulrich/lang/v/v/thirdparty/stb_image" -I "/home/ulrich/lang/v/v/thirdparty/sokol" -I "/home/ulrich/lang/v/v/thirdparty/sokol/util" -I "/home/ulrich/lang/v/v" "/tmp/v_1000/tetris.1511315272736621368.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE -rdynamic "/home/ulrich/lang/v/v/thirdparty/tcc/lib/libgc.a" -ldl -lpthread -lm -lm -lX11 -lGL -lXcursor -lXi -lpthread -ldl  
/tmp/v_1000/tetris.1511315272736621368.tmp.c: In function ‘sokol__sapp__get_dropped_file_path’:
/tmp/v_1000/tetris.1511315272736621368.tmp.c:27144:49: warning: passing argument 1 of ‘cstring_to_vstring’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
27144 |                 string _t1 = cstring_to_vstring(sapp_get_dropped_file_path(index));
      |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v_1000/tetris.1511315272736621368.tmp.c:13444:33: note: expected ‘char *’ but argument is of type ‘const char *’
13444 | string cstring_to_vstring(char* s) {
      |                           ~~~~~~^
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__set_flip_vertically_on_write':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:18943: undefined reference to `stbi_flip_vertically_on_write'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__set_png_compression_level':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:18947: undefined reference to `set_png_compression_level'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__write_force_png_filter':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:18951: undefined reference to `write_force_png_filter'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__write_tga_with_rle':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:18955: undefined reference to `write_tga_with_rle'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__resize_uint8':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:18998: undefined reference to `stbir_resize_uint8'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__stbi_write_png':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:19007: undefined reference to `stbi_write_png'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__stbi_write_bmp':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:19014: undefined reference to `stbi_write_bmp'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__stbi_write_tga':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:19021: undefined reference to `stbi_write_tga'
/usr/bin/ld: /tmp/ccrAmFoo.o: in function `stbi__stbi_write_jpg':
/tmp/v_1000/tetris.1511315272736621368.tmp.c:19028: undefined reference to `stbi_write_jpg'
collect2: error: ld returned 1 exit status
builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

This looks like different options to me. I was wondering how to see the compile command for the module. As far as I can tell all that is shown now is the command used for the main file(s).

kuettler commented 1 year ago

Running

ulrich@sancho v (master) $ v -cc echo -cg -showcc -show-c-output -dump-c-flags c-flags.txt examples/tetris
> C compiler cmd: 'echo' '@/tmp/v_1000/tetris.12403950015661733653.tmp.c.rsp'
> C compiler response file "/tmp/v_1000/tetris.12403950015661733653.tmp.c.rsp":
  -g "/home/ulrich/.vmodules/cache/19/19e0141532b7c0919b73e11d902c9cb8.module.stbi.o" -o "/home/ulrich/lang/v/v/examples/tetris/tetris" -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -D SOKOL_GLCORE33 -D SOKOL_NO_ENTRY -I "/home/ulrich/lang/v/v/thirdparty/libgc/include" -I "/home/ulrich/lang/v/v/thirdparty/fontstash" -I "/home/ulrich/lang/v/v/thirdparty/stb_image" -I "/home/ulrich/lang/v/v/thirdparty/sokol" -I "/home/ulrich/lang/v/v/thirdparty/sokol/util" -I "/home/ulrich/lang/v/v" "/tmp/v_1000/tetris.12403950015661733653.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE -rdynamic "/home/ulrich/lang/v/v/thirdparty/tcc/lib/libgc.a" -ldl -lpthread -lm -lm -lX11 -lGL -lXcursor -lXi -lpthread -ldl  
======== C Compiler output ========
@/tmp/v_1000/tetris.12403950015661733653.tmp.c.rsp

=================================

Still produces

~/.vmodules/cache/19/19e0141532b7c0919b73e11d902c9cb8.module.stbi.o

This is unexpected.

spytheman commented 1 year ago

That is really weird indeed. I'll create a VM to test locally.