emscripten-core / emscripten-core/emscripten
Fails to compile when using strdup C23 standard function
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 125
Description
Please include the following in your bug report:
**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.74 (1092ec30a3fb1d46b1782ff1b4db5094d3d06ae5)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 322eb1a92e6d4266184060346616fa0dbe39e731)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/x/emsdk/upstream/bin
**Failing command line in full:**
Command line:
```
-> emcc src/usdc.c src/token.c external/lz4/lib/lz4.c -I external/lz4/lib -std=c23 -o build/wasm/wasm_usdc.html -Wall -Wextra --preload-file data -sMEMORY64=2
```
Output:
```
src/token.c:169:10: error: use of undeclared identifier 'strdup'; did you mean 'strupr'?
169 | .str = strdup(str),
| ^~~~~~
| strupr
/Users/urjasvisuthar/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/urjasvisuthar/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/urjasvisuthar/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_5hhhrejl/token_1.o' failed (returned 1)
```
---
**Full link command and output with `-v` appended:**
Command line:
```
emcc src/usdc.c src/token.c external/lz4/lib/lz4.c -I external/lz4/lib -std=c23 -o build/wasm/wasm_usdc.html -Wall -Wextra --preload-file data -sMEMORY64=2 -v
```
Output:
```
/Users/urjasvisuthar/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/urjasvisuthar/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 -v src/usdc.c -c -o /var/folders/7x/khcwdw3d39g8c3k03mcrcw3r0000gn/T/emscripten_temp_s3__nidp/usdc_0.o
clang version 20.0.0git (https:/github.com/llvm/llvm-project 322eb1a92e6d4266184060346616fa0dbe39e731)
Target: wasm64-unknown-emscripten
Thread model: posix
InstalledDir: /Users/urjasvisuthar/emsdk/upstream/bin
(in-process)
"/Users/urjasvisuthar/emsdk/upstream/bin/clang-20" -cc1 -triple wasm64-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name usdc.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature -bulk-memory -target-feature -bulk-memory-opt -target-feature -nontrapping-fptoint -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/Users/urjasvisuthar/Desktop/test/fta -v -fcoverage-compilation-dir=/Users/urjasvisuthar/Desktop/test/fta -resource-dir /Users/urjasvisuthar/emsdk/upstream/lib/clang/20 -D EMSCRIPTEN -I external/lz4/lib -isysroot /Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /Users/urjasvisuthar/emsdk/upstream/lib/clang/20/include -internal-isystem /Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/wasm64-emscripten -internal-isystem /Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include -Werror=implicit-function-declaration -Wall -Wextra -std=c23 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /var/folders/7x/khcwdw3d39g8c3k03mcrcw3r0000gn/T/emscripten_temp_s3__nidp/usdc_0.o -x c src/usdc.c
clang -cc1 version 20.0.0git based upon LLVM 20.0.0git default target x86_64-apple-darwin24.1.0
ignoring nonexistent directory "/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/wasm64-emscripten"
#include "..." search starts here:
#include <...> search starts here:
external/lz4/lib
/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/compat
/Users/urjasvisuthar/emsdk/upstream/lib/clang/20/include
/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
/Users/urjasvisuthar/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/urjasvisuthar/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 -v src/token.c -c -o /var/folders/7x/khcwdw3d39g8c3k03mcrcw3r0000gn/T/emscripten_temp_s3__nidp/token_1.o
clang version 20.0.0git (https:/github.com/llvm/llvm-project 322eb1a92e6d4266184060346616fa0dbe39e731)
Target: wasm64-unknown-emscripten
Thread model: posix
InstalledDir: /Users/urjasvisuthar/emsdk/upstream/bin
(in-process)
"/Users/urjasvisuthar/emsdk/upstream/bin/clang-20" -cc1 -triple wasm64-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name token.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature -bulk-memory -target-feature -bulk-memory-opt -target-feature -nontrapping-fptoint -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/Users/urjasvisuthar/Desktop/test/fta -v -fcoverage-compilation-dir=/Users/urjasvisuthar/Desktop/test/fta -resource-dir /Users/urjasvisuthar/emsdk/upstream/lib/clang/20 -D EMSCRIPTEN -I external/lz4/lib -isysroot /Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /Users/urjasvisuthar/emsdk/upstream/lib/clang/20/include -internal-isystem /Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/wasm64-emscripten -internal-isystem /Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include -Werror=implicit-function-declaration -Wall -Wextra -std=c23 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /var/folders/7x/khcwdw3d39g8c3k03mcrcw3r0000gn/T/emscripten_temp_s3__nidp/token_1.o -x c src/token.c
clang -cc1 version 20.0.0git based upon LLVM 20.0.0git default target x86_64-apple-darwin24.1.0
ignoring nonexistent directory "/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/wasm64-emscripten"
#include "..." search starts here:
#include <...> search starts here:
external/lz4/lib
/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include/compat
/Users/urjasvisuthar/emsdk/upstream/lib/clang/20/include
/Users/urjasvisuthar/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
src/token.c:169:10: error: use of undeclared identifier 'strdup'; did you mean 'strupr'?
169 | .str = strdup(str),
| ^~~~~~
| strupr
/Users/urjasvisuthar/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/urjasvisuthar/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/urjasvisuthar/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 -v src/token.c -c -o /var/folders/7x/khcwdw3d39g8c3k03mcrcw3r0000gn/T/emscripten_temp_s3__nidp/token_1.o' failed (returned 1)
```
---
Google group conversation:
https://groups.google.com/g/emscripten-discuss/c/3DMpT62eLuE
Contributor guide
Research direction
Reproduce the failure with the emcc command shown, then inspect sysroot/include/compat/string.h and the C23 header search paths in the verbose output. Confirm the expected declaration and verify that the same command compiles successfully with strdup available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100