PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.93k stars 4.61k forks source link

[FindRSSDK] On MSVC, invoking `find_package(RSSDK)` silently adds /NODEFAULTLIB:LIBCMTD to the linker flags #4253

Open traversaro opened 4 years ago

traversaro commented 4 years ago

Describe the bug

On MSVC, invoking find_package(RSSDK) silently adds /NODEFAULTLIB:LIBCMTD to the linker flags, due to this line: https://github.com/PointCloudLibrary/pcl/blob/pcl-1.11.0/cmake/Modules/FindRSSDK.cmake#L69 . It is not clear why that is needed, and it can create problems tricky to debug.

Context

I notice that line of code by inspection, and I found it strange that a Find<pkg>.cmake script modifies the linker flags even if the dependency is not actually used.

Expected behavior

I would expect Find<pkg>.cmake not to have side effects beside setting variables and defining imported target.

Current Behavior

Whenever find_package(RSSDK) is invoked, it silently adds /NODEFAULTLIB:LIBCMTD to the linker flags, even if RSSSDK is not found.

To Reproduce

The reported behaviour is dangerous in general, and it was found by inspection of the code and by a related problem on an not easy to reproduce system.

Screenshots/Code snippets

In order to help explain your problem, please consider adding

Your Environment (please complete the following information):

Possible Solution

Probably that line can be just removed, but it would be probably make sense to first test compilation with RSSDK enabled, if that is still supported.

Additional context

I actually encountered this problem by compiling an old version of PCL with an old version of vcpkg with an old version of Visual Studio, in particular in that case the error was the following:

Click to see details ~~~ The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated. Please include and use BOOST_ENDIAN_*_BYTE instead C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\include\boost/pending/integer_log2.hpp(7): note: This header is deprecated. Use instead. [5/413] C:\PROGRA~2\MIB055~1\2017\ENTERP~1\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\cl.exe /TP -DBOOST_LIB_DIAGNOSTIC -DPCLAPI_EXPORTS -Dqh_QHpointer -Dqh_QHpointer_dllimport -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\recognition\include\pcl\recognition\3rdparty -Iinclude -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\common\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\octree\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\openni\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\openni2\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\ensenso\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\davidSDK\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\dssdk\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\rssdk\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\pcap\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\png\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\vtk\include -IC:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\io\include -IC:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\include\eigen3 -IC:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\include -I"C:\Program Files\Ensenso\development\c\include" /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MP /FS -openmp -DBOOST_ALL_DYN_LINK -DBOOST_ALL_NO_LIB /D_DEBUG /MTd /Z7 /Ob0 /Od /RTC1 -DBOOST_ALL_NO_LIB -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DPCL_ONLY_CORE_POINT_TYPES /bigobj /showIncludes /Foio\CMakeFiles\pcl_io_ply.dir\src\ply\ply_parser.cpp.obj /Fdio\CMakeFiles\pcl_io_ply.dir\ /FS -c C:\src\vcpkg-idjl-deployment-2019\buildtrees\pcl\src\pcl-1.9.1-898b5a3155\io\src\ply\ply_parser.cpp Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27032.1 for x64 Copyright (C) Microsoft Corporation. All rights reserved. The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated. Please include and use BOOST_ENDIAN_*_BYTE instead [6/413] cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=io\CMakeFiles\pcl_io_ply.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\10.0.18362.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\10.0.18362.0\x64\mt.exe --manifests -- C:\PROGRA~2\MIB055~1\2017\ENTERP~1\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\link.exe io\CMakeFiles\pcl_io_ply.dir\src\ply\ply_parser.cpp.obj /out:bin\pcl_io_ply_debug.dll /implib:lib\pcl_io_ply_debug.lib /pdb:bin\pcl_io_ply_debug.pdb /dll /version:1.9 /machine:x64 /NODEFAULTLIB:LIBCMTD /debug /INCREMENTAL /DELAYLOAD:VCOMP140D.dll -LIBPATH:C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\lib -LIBPATH:C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_filesystem-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_thread-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_date_time-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_iostreams-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_system-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_chrono-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_atomic-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_regex-vc140-mt-gd.lib delayimp.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." FAILED: bin/pcl_io_ply_debug.dll lib/pcl_io_ply_debug.lib cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=io\CMakeFiles\pcl_io_ply.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\10.0.18362.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\10.0.18362.0\x64\mt.exe --manifests -- C:\PROGRA~2\MIB055~1\2017\ENTERP~1\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\link.exe io\CMakeFiles\pcl_io_ply.dir\src\ply\ply_parser.cpp.obj /out:bin\pcl_io_ply_debug.dll /implib:lib\pcl_io_ply_debug.lib /pdb:bin\pcl_io_ply_debug.pdb /dll /version:1.9 /machine:x64 /NODEFAULTLIB:LIBCMTD /debug /INCREMENTAL /DELAYLOAD:VCOMP140D.dll -LIBPATH:C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\lib -LIBPATH:C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_filesystem-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_thread-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_date_time-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_iostreams-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_system-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_chrono-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_atomic-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_regex-vc140-mt-gd.lib delayimp.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." LINK Pass 1: command "C:\PROGRA~2\MIB055~1\2017\ENTERP~1\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\link.exe io\CMakeFiles\pcl_io_ply.dir\src\ply\ply_parser.cpp.obj /out:bin\pcl_io_ply_debug.dll /implib:lib\pcl_io_ply_debug.lib /pdb:bin\pcl_io_ply_debug.pdb /dll /version:1.9 /machine:x64 /NODEFAULTLIB:LIBCMTD /debug /INCREMENTAL /DELAYLOAD:VCOMP140D.dll -LIBPATH:C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\lib -LIBPATH:C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_filesystem-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_thread-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_date_time-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_iostreams-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_system-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_chrono-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_atomic-vc140-mt-gd.lib C:\src\vcpkg-idjl-deployment-2019\installed\x64-windows-static-crt\debug\lib\boost_regex-vc140-mt-gd.lib delayimp.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:io\CMakeFiles\pcl_io_ply.dir/intermediate.manifest io\CMakeFiles\pcl_io_ply.dir/manifest.res" failed (exit code 1120) with the following output: Microsoft (R) Incremental Linker Version 14.16.27032.1 Copyright (C) Microsoft Corporation. All rights reserved. Creating library lib\pcl_io_ply_debug.lib and object lib\pcl_io_ply_debug.exp LINK : warning LNK4199: /DELAYLOAD:VCOMP140D.dll ignored; no imports found from VCOMP140D.dll ply_parser.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl `eh vector destructor iterator'(void *,unsigned __int64,unsigned __int64,void (__cdecl*)(void *))" (??_M@YAXPEAX_K1P6AX0@Z@Z) referenced in function "public: void * __cdecl boost::unique_lock::`vector deleting destructor'(unsigned int)" (??_E?$unique_lock@Vmutex@boost@@@boost@@QEAAPEAXI@Z) libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol _purecall ply_parser.cpp.obj : error LNK2001: unresolved external symbol _purecall libcpmtd.lib(locale0.obj) : error LNK2001: unresolved external symbol _purecall libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol _purecall libcpmtd.lib(wlocale.obj) : error LNK2001: unresolved external symbol _purecall libcpmtd.lib(wlocale.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) ply_parser.cpp.obj : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) libcpmtd.lib(xonce.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) libcpmtd.lib(syserror.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) libcpmtd.lib(syserror.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) libcpmtd.lib(wlocale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) ply_parser.cpp.obj : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) libcpmtd.lib(xthrow.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) libcpmtd.lib(locale0.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) libcpmtd.lib(xonce.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) ply_parser.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) referenced in function "protected: void __cdecl std::ctype::_Tidy(void)" (?_Tidy@?$ctype@D@std@@IEAAXXZ) libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) ply_parser.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl operator delete[](void *,unsigned __int64)" (??_V@YAXPEAX_K@Z) referenced in function "public: void * __cdecl boost::unique_lock::`vector deleting destructor'(unsigned int)" (??_E?$unique_lock@Vmutex@boost@@@boost@@QEAAPEAXI@Z) ply_parser.cpp.obj : error LNK2019: unresolved external symbol atexit referenced in function "class boost::exception_ptr __cdecl boost::exception_detail::get_static_exception_object(void)" (??$get_static_exception_object@Ubad_alloc_@exception_detail@boost@@@exception_detail@boost@@YA?AVexception_ptr@1@XZ) ~~~

This is not something I was able to reproduce on a modern enviroment, but in any case that hidden /NODEFAULTLIB:LIBCMTD hidden can create problems also for other reasons. Also in that enviroment, it was sufficient to set ENABLE_RSSDK to OFF to avoid the problem.

kunaltyagi commented 4 years ago

PR would need low effort, but the test setup might take time (and effort)

larshg commented 4 years ago

Its been around since its first introduction in https://github.com/PointCloudLibrary/pcl/pull/1401. I have not encountered many issues about this, either myself or here on the issue tracker for the last 5 years.

As I can read it disables the use of static runtime in debug mode, so you won't mix debug with librealsense release only build (maybe? just guessing). https://support.microsoft.com/en-gb/help/154753/description-of-the-default-c-and-c-libraries-that-a-program-will-link

So this also clarify why I rarely encounter it as I mostly compile with dynamic linking, which uses the MSVCRTD.lib.

But I agree in your assumptions that findXXLib should not add additional compiler/linker flags. Can be done later if it was found and is required.

traversaro commented 4 years ago

So this also clarify why I rarely encounter it as I mostly compile with dynamic linking, which uses the MSVCRTD.lib.

Good catch, indeed I was compiling with shared library linking but with MTd (i.e. static runtime), and that explain why I encountered the bug. As you can see in the error log, it seems that the linking error is on boost::unique_lock<class boost::mutex>, so it may be possible that with past boost version this was not a problem.