lamyj / odil

Odil is a C++11 library for the DICOM standard
Other
85 stars 21 forks source link

Linking issue on Windows when building examples with clang-cl #93

Open ClementTroesch opened 5 months ago

ClementTroesch commented 5 months ago

Hi there,

I'm currently trying to build a small test app with Odil on Windows 10 using clang-cl (VS 2022) but I get linking issue due to unresolved external symbols.

The issue also appears when building the examples, this is how I configure Odil with the examples:

cmake `
 -DWITH_DCMTK=OFF `
 -DBUILD_TESTING=OFF `
 -DBUILD_PYTHON_WRAPPERS=OFF `
 -DBUILD_JAVASCRIPT_WRAPPERS=OFF `
 -DBUILD_EXAMPLES=ON `
 -DICU_ROOT="<path_to_icu>"" `
 -DICU_UC_LIBRARY_RELEASE="<path_to_icu>"\lib\icuuc.lib" `
 -DJsonCpp_LIBRARY="<path_to_jsoncpp>\lib\jsoncpp.lib" `
 -DJsonCpp_INCLUDE_DIR="<path_to_jsoncpp>\include" `
 -DCMAKE_INSTALL_PREFIX="../install" `
 -DCMAKE_CXX_COMPILER="clang-cl.exe" `
 -DCMAKE_C_COMPILER="clang-cl.exe" `
 -DCMAKE_RC_COMPILER="llvm-rc.exe" `
 -DCMAKE_LINKER="link.exe" `
 -DCMAKE_C_FLAGS="-m64" `
 -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -m64 /EHa" `
 ../odil -G "NMake Makefiles JOM"

(Note: Boost, ICU and JsonCpp have all been built with clang-cl as well)

Here are the linking issues displayed in the compilation log:

When listing the symbols of the library using DUMPBIN /EXPORTS odil.lib it looks like the symbols are not available:

Do you have any idea on what I might be doing wrong?

Thanks a lot,

Clément

ClementTroesch commented 5 months ago

Ok so I have continued my tests and it seems to work with cl. The issue seems to come from the compilation with clang-cl. I am not quite sure what could be the issue here...

ClementTroesch commented 5 months ago

I managed to export the expected symbols using the -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE cmake parameter. I guess clang-cl does not export all symbols using the ODIL_API macro. I'm not sure why as some of the symbols are still exported as expected...

I'm leaving the issue open as I would expect the ODIL_API macro to be sufficient. If you are not planning to support clang-cl feel free to close the issue :)

Thanks, Clément