[C++] Linking error for debug build on Windows
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
I experienced a linking error while building the debug flavor of the project I am working on, that links dynamically the arrow libraries, on Windows. Specifically the error is described in [Linker Tools Warning LNK4098](https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4098?view=msvc-170).
The issue stems from the following CMake line, [arrow/cpp/cmake_modules/SetupCxxFlags.cmake](https://github.com/apache/arrow/blob/8b440d1b5df4a0e58bcaa422b83e6d6ff1213b5f/cpp/cmake_modules/SetupCxxFlags.cmake#L643).
The solution that worked in my case was to explicitly mention which libraries to exclude when building the release and debug flavor, following the table at [Linker Tools Warning LNK4098](https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4098?view=msvc-170). Specifically the aforementioned link to the Microsoft page describes in detail which libraries to exclude when linking dynamically with C run-time, i.e.,
```bash
NOT ARROW_USE_STATIC_CRT
```
.
Additionally, for debug flavor builds, the /MDd or /MTd options might need to be set explicitly. I pass that from my project's configuration but I think it is not done explicitly within Arrow CMake files. Relevant link [Linker Tools Error LNK2001](https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2001?view=msvc-160), read segment "If you link to the release mode libraries when building a debug version [...]"
Apache Arrow ticket that introduced the aforementioned CMake line change and dealt with the same issue: ARROW-4014
**Environment**: Windows 10
**Reporter**: [Zois Tasoulas](https://issues.apache.org/jira/browse/ARROW-15298) / @zois-tasoulas
**Note**: *This issue was originally created as [ARROW-15298](https://issues.apache.org/jira/browse/ARROW-15298). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*
Contributor guide
Research direction
Start at cpp/cmake_modules/SetupCxxFlags.cmake around line 643 and compare the current flags with the Microsoft LNK4098/LNK2001 guidance and ARROW-4014. Reproduce a Windows debug build that dynamically links Arrow libraries, then verify the CMake configuration handles the appropriate CRT and debug flags without the reported linker diagnostics. Done means the affected debug build links successfully with the documented configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100