After a little investigation it seems like the problem is that when you use
`-std=c23` or `-std=c11` clang will define `__STRICT_ANSI__`.  `strdup` was
not available in this mode, at least not prior to C23.  So musl does not
declare it in that mode.

You can work around this by using `-std=gnu23` or by adding `-D_BSD_SOURCE`.

cheers,
sam

On Mon, Jan 13, 2025 at 11:58 AM Sam Clegg <[email protected]> wrote:

> `strdup` is available in emscripten.  Its part of the musl libc:
> https://github.com/emscripten-core/emscripten/blob/ebfeaf7a17f53ad322ea322efa8dfca5c752679b/system/lib/libc/musl/include/string.h#L70
>
> It looks like using `-std=c23` is somehow suppressing that definition.
>  Could you open a bug about that?
>
> cheers,
> sam
>
> On Mon, Jan 13, 2025 at 2:18 AM Urjasvi Suthar <[email protected]>
> wrote:
>
>> Hello,
>> I am trying to compile for wasm with emscripten but there seems to be no
>> 'strdup' C standard function.
>> ```
>> src/token.c:169:10: error: use of undeclared identifier 'strdup'; did you
>> mean 'strupr'?
>>   169 |                 .str = strdup(str),
>>       |                        ^~~~~~
>>       |                        strupr
>> /Users/x/emsdk/upstream/emscripten/cache/sysroot/include/compat/string.h:9:14:
>> note: 'strupr' declared here
>>     9 | extern char* strupr(char *);
>>       |              ^
>> 1 error generated.
>> emcc: error: '/Users/x/emsdk/upstream/bin/clang -target
>> wasm64-unknown-emscripten -fignore-exceptions -mno-bulk-memory
>> -mno-bulk-memory-opt -mno-nontrapping-fptoint -mllvm
>> -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm
>> -disable-lsr --sysroot=/Users/x/emsdk/upstream/emscripten/cache/sysroot
>> -DEMSCRIPTEN -Werror=implicit-function-declaration -Xclang
>> -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat
>> -Iexternal/lz4/lib -std=c23 -Wall -Wextra src/token.c -c -o
>> /var/folders/7x/khcwdw3d39g8c3k03mcrcw3r0000gn/T/emscripten_temp_u3yctg1o/token_1.o'
>> failed (returned 1)
>> ```
>> Is this C23 standard not supported yet or am I missing something?
>> I know I can implement it myself easily (that what I am currently doing
>> as workaround), but less code and #ifdefs the better :)
>>
>> Regards,
>> Urjasvi Suthar
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion visit
>> https://groups.google.com/d/msgid/emscripten-discuss/c666906e-ad13-4470-8f4a-3aae76b36925n%40googlegroups.com
>> <https://groups.google.com/d/msgid/emscripten-discuss/c666906e-ad13-4470-8f4a-3aae76b36925n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2_Oe0k%2Bo_Tmhj0GDKkuQTDJ1jp0HGK%3D%3DXqeLoSyfuK%3DCg%40mail.gmail.com.

Reply via email to