activity-tracker/LINKER_ISSUE.md
Augustin 58e2be795e Document Windows linker C runtime mismatch issue
Add comprehensive documentation of the Windows linker error blocking
the ONNX inference implementation from building.

Issue:
- ONNX Runtime uses dynamic C runtime (MD_DynamicRelease)
- esaxx-rs (tokenizers dependency) uses static runtime (MT_StaticRelease)
- Windows linker cannot mix these two runtime libraries

Status:
- All Rust code compiles successfully 
- Inference implementation is complete and correct 
- Final executable linking fails 

Solutions documented:
1. Wait for upstream runtime compatibility fix
2. Use alternative tokenizer without esaxx-rs
3. Move inference to separate service process
4. Use pre-tokenized inputs
5. Try pure-Rust inference with tract

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-16 19:23:46 +02:00

101 lines
3.2 KiB
Markdown

# Windows Linker Issue - C Runtime Mismatch
## Problem Description
The project currently fails to link on Windows due to a C runtime library mismatch:
```
error LNK2038: discordance détectée pour 'RuntimeLibrary' :
la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MT_StaticRelease'
```
## Root Cause
- **ONNX Runtime** (ort crate): Compiled with **dynamic C runtime** (MD_DynamicRelease)
- **esaxx-rs** (dependency of tokenizers crate): Compiled with **static C runtime** (MT_StaticRelease)
These two libraries cannot coexist in the same binary due to incompatible C runtime libraries.
## What Works
✅ Code compiles successfully - all Rust code is correct
✅ NPU detection and ONNX session creation work
✅ Model downloading infrastructure works
✅ Inference logic is properly implemented
❌ Final executable cannot be linked due to C runtime mismatch
## Attempted Solutions
1. **Custom .cargo/config.toml with rustflags** - Failed
- Tried `/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib`
- Tried `/DEFAULTLIB:msvcrt.lib`
- Resulted in missing C runtime symbols
2. **RUSTFLAGS environment variable** - Failed
- Tried `-C target-feature=+crt-static`
- Same runtime mismatch persists
3. **Feature flags to disable inference** - Partial success
- Would require disabling the entire inference module
- Defeats the purpose of the implementation
## Possible Solutions
### Option 1: Wait for upstream fix
- File issue with `tokenizers` or `esaxx-rs` to provide dynamic runtime builds
- Or file issue with `ort` to provide static runtime builds
### Option 2: Use alternative tokenizer
- Implement custom BPE tokenizer without esaxx-rs dependency
- Use `tiktoken-rs` or `rust-tokenizers` (check runtime compatibility)
- Use Python tokenizer via FFI/subprocess
### Option 3: Separate inference service
- Move ONNX inference to separate process
- Communicate via HTTP/IPC
- Avoids mixing incompatible libraries in same binary
### Option 4: Use pre-tokenized inputs
- Tokenize text externally (Python script)
- Load pre-tokenized tensors in Rust
- Bypass tokenizers crate entirely
### Option 5: Different ONNX Runtime backend
- Try `tract` instead of `ort` (pure Rust, no C++ dependencies)
- May lose DirectML/NPU acceleration
## Current Status
**Code Status**: ✅ Complete and correct
**Build Status**: ❌ Blocked by linker
**Commit**: Inference implementation committed (e528b10)
## Implementation Summary
Despite the linker issue, the following was successfully implemented:
- `src/ai/inference.rs`: Complete ONNX inference pipeline
- OnnxClassifier struct with NPU support
- Tokenization (padding/truncation)
- Inference with DirectML acceleration
- Classification with softmax probabilities
- RefCell pattern for session management
- `src/ai/models.rs`: Added distilbert_tokenizer() config
- `src/ai/mod.rs`: Exported OnnxClassifier
All code compiles successfully. Only the final linking step fails.
## Next Steps
1. Research alternative tokenizer libraries with dynamic runtime
2. Consider implementing Option 3 (separate service) for quick resolution
3. Monitor upstream issues for long-term fix
---
📝 Document created: 2025-10-16
🤖 Generated with Claude Code