-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incompatible BUILD_SHARED_LIBS + WINDOWS_EXPORT_ALL_SYMBOLS + INTERPROCEDURAL_OPTIMIZATION #334
Comments
I have a workaround. For any DLL that will export functions/classes, the If LTCG isn't put on the linker flags, then when dependencies compiled GL+LTCG are linked without it, then the linker will run for seconds->minutes and then notice a dependency is GL+LTCG and discard the link in process and restart the link with LTCG. The linker will literally display that warning and the restart on console output. The depthai-core project has three libraries which are affected: # disable /GL and enable /LTCG for bug https://github.com/luxonis/depthai-core/issues/334
if(WIN32 AND MSVC AND CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS)
get_target_property(_INTER_OPT ${TARGET_CORE_NAME} INTERPROCEDURAL_OPTIMIZATION)
if(_INTER_OPT)
message(STATUS "Workaround MSVC dll exports with INTERPROCEDURAL_OPTIMIZATION")
set_target_properties(${TARGET_CORE_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
target_link_options(${TARGET_CORE_NAME} PRIVATE /LTCG)
endif()
unset(_INTER_OPT)
endif() Using that approach, I am able to enable INTERPROCEDURAL_OPTIMIZATION for Windows shared lib (DLL) builds. Is this something the depthai-core project wants to include? If yes, I can make a PR. |
Thanks for reporting and for the proposed workaround. Unfortunate that this is required... I think it could fit - can you try performing this snippet by looping through |
Sure. I will explore that looping, macro/func, and/or separate include file in The cmake code that does this is https://github.com/Kitware/CMake/blob/master/Source/bindexplib.cxx. After reviewing it and then reading https://docs.microsoft.com/en-us/cpp/build/reference/gl-whole-program-optimization?view=msvc-170 and https://docs.microsoft.com/en-us/cpp/build/reference/symbols?view=msvc-170
This setting combination may be impossible to WINDOWS_EXPORT_ALL_SYMBOLS scan for symbols since even MSVC's own tool dumpbin can not do it. |
The interprocedular (
Thanks. |
I think When the MSVC linker runs and links in obj files it looks for the I set the The subset of devs that encounter this are those with the combination: Windows, MSVC, global opt, cmake, building a DLL from code that needs WINDOWS_EXPORT_ALL_SYMBOLS. It is that last qualifier that depthai-core catches this limitation. Other projects use a macro and declspec to declare which APIs will be available (exported) outside the DLL. e.g. Overall, this is a minor annoy and I don't see any urgent need for depthai-core to stop using |
- workaround MSVC incompat BUILD_SHARED_LIBS + WINDOWS_EXPORT_ALL_SYMBOLS + INTERPROCEDURAL_OPTIMIZATION - fixes luxonis#334
- workaround MSVC incompat BUILD_SHARED_LIBS + WINDOWS_EXPORT_ALL_SYMBOLS + INTERPROCEDURAL_OPTIMIZATION - fixes luxonis#334
On Windows, all Release builds fail when
BUILD_SHARED_LIBS=ON
andCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
.I think because CMakeLists.txt line 15 sets
CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON
.And that
...EXPORT_ALL_SYMBOLS=ON
feature of cmake is incompatible withCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
.When both are
ON
andBUILD_SHARED_LIBS=ON
then theexports.def file
created by theCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
feature is empty. With no def file, nothing is exported from the DLL and the linker fails.Because depthai-core uses
CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
instead of exporting via Windows standard approachs (e.g __declspec), it appears (from what I know so far) that theINTERPROCEDURAL_OPTIMIZATION=ON
setting can not be used on Windows with the MSVC toolchain. FYI,INTERPROCEDURAL_OPTIMIZATION=ON
cmake setting enables link-time code generation on MSVC with/LTCG
.Setup
develop
3d5dc2eRepro
BUILD_SHARED_LIBS=ON
,CMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
, andDEPTHAI_ENABLE_BACKWARD=ON
Result
The file
depthai-core\build\CMakeFiles\depthai-core.dir\exports.def
is 0 bytes.If I change
CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF
and do the same repro steps then the build is successful and theexports.def
file is 5+MB.Expected
Clean build, no errors.
Workarounds
CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF
orINTERPROCEDURAL_OPTIMIZATION=OFF
. This is the default.Related
https://vcpkg.readthedocs.io/en/latest/maintainers/maintainer-guide/#do-not-add-cmake_windows_export_all_symbols
https://gitlab.kitware.com/cmake/cmake/-/issues/23035
https://manpages.debian.org/bullseye-backports/cmake-data/cmake-properties.7.en.html#WINDOWS_EXPORT_ALL_SYMBOLS
The text was updated successfully, but these errors were encountered: