How to compile part of ITK integrated into another library?

I tried all of the above and none is working.

There is no file called Directory.h. There is Directory.hxx (and Directory.cxx).

Ah now I see I invented Directory.h. Well, debug why it is not being included properly.

I know that ā€¦ there is one itkDirectoy.h which is using itksys/Directory.hxx

I am new to CMake thatā€™s why I am having hard time with it. It is a total paradigm shiftā€¦ unfortunately I could not find a step by step debugger for CMake. Thatā€™s a missing tool for sure.

I am also hardcore being noob and trying something as hard as what I planned.

CMake generates a VS solution, which you are hopefully more familiar with.

For debugging CMake, message("x: ${x}") is the only way I know. Also take a look at this script to print all active variables.

My only dream was being able to use the Blueberry Framework which is tightly integrated inside MITK. I didnā€™t want to use MITK because it is too specialized for Medical Imaging. I wanted CTK and Blueberry for OSGi foundation of my architecture. But when I realized that it is half modular and half monolith it made me angry to see that so much skill went into that project and nobody modularized the think.

Extracting Blueberry was a nightmare because of its deep intertwine with ITK.

Converting Blueberry from MITK plugins standard to CTK was not hard because MITK uses CTK under the hood.

I really donā€™t know what to do!!! It doesnā€™t work only that crap KWSys

I removed the KWSys which comes with ITK and used the original from Kitwareā€™s repo. How am I supposed to fix these linking errors?

 itkThreadPool.obj : error LNK2019: unresolved external symbol "public: __cdecl kwsys::SystemToolsManager::SystemToolsManager(void)" (??0SystemToolsManager@kwsys@@QEAA@XZ) referenced in function "void __cdecl kwsys::`dynamic initializer for 'SystemToolsManagerInstance''(void)" (??__ESystemToolsManagerInstance@kwsys@@YAXXZ)
3>  itkMultiThreaderBase.obj : error LNK2001: unresolved external symbol "public: __cdecl kwsys::SystemToolsManager::SystemToolsManager(void)" (??0SystemToolsManager@kwsys@@QEAA@XZ)
3>  itkPlatformMultiThreader.obj : error LNK2001: unresolved external symbol "public: __cdecl kwsys::SystemToolsManager::SystemToolsManager(void)" (??0SystemToolsManager@kwsys@@QEAA@XZ)
3>  itkThreadPool.obj : error LNK2019: unresolved external symbol "public: __cdecl kwsys::SystemToolsManager::~SystemToolsManager(void)" (??1SystemToolsManager@kwsys@@QEAA@XZ) referenced in function "void __cdecl kwsys::`dynamic atexit destructor for 'SystemToolsManagerInstance''(void)" (??__FSystemToolsManagerInstance@kwsys@@YAXXZ)

Can you teach me? I feel like I have some blockages concerning CMake that I donā€™t grasp.

I am now down to last compilation error :

> itkDirectory.obj : error LNK2019: unresolved external symbol "public: bool __cdecl itksys::Directory::Load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)" (?Load@Directory@itksys@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAV34@@Z) referenced in function "public: bool __cdecl itk::Directory::Load(char const *)" (?Load@Directory@itk@@QEAA_NPEBD@Z)

It seems that the path for itksys is not added in the linker setting for additional dependencies:

When I add this path directly the compilation is working:

1>Target Link:
1>     Creating library G:/programming/cplusplusplus/CTK/build/CTK-build/bin/Debug/CTKmbilog.lib and object G:/programming/cplusplusplus/CTK/build/CTK-build/bin/Debug/CTKmbilog.exp
1>  CTKmbilog.vcxproj -> G:\programming\cplusplusplus\CTK\build\CTK-build\bin\Debug\CTKmbilog.dll
1>Target AppLocalFromInstalled:
1>  'pwsh.exe' is not recognized as an internal or external command,
1>  operable program or batch file.
1>  The command "pwsh.exe -ExecutionPolicy Bypass -noprofile -File "G:\vcpkg\scripts\buildsystems\msbuild\applocal.ps1" "G:\programming\cplusplusplus\CTK\build\CTK-build\bin\Debug\CTKmbilog.dll" "G:\vcpkg\scripts\buildsystems\msbuild\..\..\..\installed\x64-windows\debug\bin" "CTKmbilog.dir\Debug\CTKmbilog.tlog\CTKmbilog.write.1u.tlog" "CTKmbilog.dir\Debug\vcpkg.applocal.log"" exited with code 9009.
1>  G:\programming\cplusplusplus\CTK\build\CTK-build\bin\Debug\ITKCommon-5.1.dll
1>Target _CopyFilesMarkedCopyLocal:
1>  Touching "G:\programming\cplusplusplus\CTK\build\CTK-build\Libs\mbilog\CTKmbilog.dir\Debug\CTKmbilog.vcxproj.CopyComplete".
1>Target GetCopyToOutputDirectoryItems:
1>  Target _GetCopyToOutputDirectoryItemsFromTransitiveProjectReferences:
1>    Target GetCopyToOutputDirectoryItems:
1>      Target _GetCopyToOutputDirectoryItemsFromTransitiveProjectReferences:
1>Target FinalizeBuildStatus:
1>  Deleting file "CTKmbilog.dir\Debug\CTKmbilog.tlog\unsuccessfulbuild".
1>  Touching "CTKmbilog.dir\Debug\CTKmbilog.tlog\CTKmbilog.lastbuildstate".

itk::Directory::Load function is calling itksys::Directory::Load. I think you got rid of namespace renaming, so the function which exists is KWSys::Directory::Load.

I very much doubt that this is the last error.

This is the actual stand:

https://github.com/al-sabr/CTK/blob/ctk-blueberry-port-from-mitk/Libs/mbilog/itkDirectory.h
https://github.com/al-sabr/CTK/blob/ctk-blueberry-port-from-mitk/Libs/mbilog/itkDirectory.cxx

Trust me it is the last error!

And the namespace renaming is there : CTK/CMakeLists.txt at ae175e65e82857383c4b91b35d8eb9f68ecfe572 Ā· al-sabr/CTK Ā· GitHub

At this point my lack of CMake & C++ knowledge makes me want to give up lol!

These 2 lines were the solution for the compilation problem:

I still feel it is a nasty hack but for the moment it works as expected.

1 Like

I am glad I was wrong. If you make a ā€œreleaseā€, it would be good if you posted that here. So far, f528e0a is the latest and greatest.

There is one problem if I change from Debug to Release or MinSizeRel the build is not working because the ${CMAKE_BUILD_TYPE_INIT} is always set to Debug when I launch the VS solution.

Also CMAKE_BUILD_TYPE is always empty so I donā€™t know how to make this work.

CMAKE_BUILD_TYPE is irrelevant for VS. Take a look at CMAKE_CONFIGURATION_TYPES.

CMAKE_CONFIGURATION_TYPES is giving this Debug;Release;MinSizeRel;RelWithDebInfo

Not the current CONFIGURATION_TYPE

When I am trying to compile in Release mode I get this error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(408,5): error MSB8013: This project doesn't contain the Configuration and Platform combination of Release|x64. [G:\programming\cpp\CTK\build\CTK-build\ZERO_CHECK.vcxproj]

What does this mean?

Maybe one of the libraries involved is single-configuration only? Try making a clean build, and put only Release into CMAKE_CONFIGURATION_TYPES (instead of the default Debug;Release;MinSizeRel;RelWithDebInfo).