Description
Issue
Recently, while compiling liblsl on a Windows 11 machine, I encountered a compilation error caused by the absence of the lslboost namespace, as shown in the image below:
On my computer, I have Boost installed through vcpkg as well, and I’ve integrated vcpkg with Visual Studio using vcpkg integrate install
. Now, when compiling liblsl with CMake (LSL_BUNDLED_BOOST=ON by default), it uses the Boost installed via vcpkg instead of the bundled Boost. Since the Boost installed via vcpkg uses the boost namespace instead of lslboost, this leads to a compilation error.
How to reproduce(on Windows)?
- install vcpkg
- run
vcpkg integrate install
- install
boost-smart-ptr
with vcpkg:vcpkg install boost-smart-ptr
- configure liblsl:
cmake ..
- compile liblsl:
cmake --build . --config Release
What happened?
In commit 07ba6a7, the SYSTEM keyword was added to target_include_directories in order to suppress warnings from these third-party libraries.
According to the CMake documentation:
If SYSTEM is specified, the compiler will be told the directories are meant as system include directories on some platforms. This may have effects such as suppressing warnings or skipping the contained headers in dependency calculations (see compiler documentation). Additionally, system include directories are searched after normal include directories regardless of the order specified.
When SYSTEM
is specified, those header directories are searched after normal include directories. In this case, the include paths for the bundled Boost are searched last. So, when Visual Studio finds the globally installed Boost from vcpkg first, the error occurs.
I believe bundled libraries should be given search priority, and the use of SYSTEM may introduce unexpected side effects. Boost is just one example where the issue became visible due to the namespace mismatch between the global and bundled versions. The same problem could occur with other third-party libraries added with SYSTEM.
For instance, if I have a version of pugixml installed via vcpkg and liblsl includes a different bundled version, the build process might pick up the vcpkg headers while linking against the bundled pugixml sources. This mismatch can lead to unpredictable problems.
Conclusion
Given this, I believe we should revert the use of SYSTEM. If we want to suppress warnings from third-party libraries, we should consider alternative approaches.