emscripten-core / emscripten-core/emscripten

Fails to compile when using strdup C23 standard function

Đang mở
#23,398 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C++
Star
27.6k
Fork
3.6k
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
117

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Tái hiện lỗi bằng lệnh emcc được hiển thị, sau đó kiểm tra sysroot/include/compat/string.h và các đường dẫn tìm kiếm header C23 trong đầu ra chi tiết. Xác nhận khai báo ожидаן? và kiểm tra rằng cùng lệnh đó biên dịch thành công khi có strdup.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, wasm
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.