Skip to content
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

Build error using installed STIR library with visual studio #1483

Open
robbietuk opened this issue Jul 25, 2024 · 2 comments
Open

Build error using installed STIR library with visual studio #1483

robbietuk opened this issue Jul 25, 2024 · 2 comments

Comments

@robbietuk
Copy link
Collaborator

robbietuk commented Jul 25, 2024

I am trying to create a STIR wrapper with visual studio. I have build STIR and installed it in Program Files (x86).

Using the CMake example in examples/using_installed_STIR/demo_create_image.cxx. I am able to configure, build and run this example using CMake. Notably, CMake uses the find_package(STIR 6.0 REQUIRED CONFIG) command.

Porting over to Visual Studio. I want to compile the same file examples/using_installed_STIR/demo_create_image.cxx using Visual Studio, by including the libraries.

For this I used https://stackoverflow.com/a/23882710 as my guide. STIR is installed at C:\Program Files (x86)\STIR with bin, include, lib, share directories.

Within my STIRWrapper Visual Studio project, I set the following properties:

  • "C/C++->General->Additional Include Directories field" contains C:\Program Files (x86)\STIR\include\STIR-6.2 and C:\Program Files\boost_1_82_0
  • "Linker->General->Additional Library Directories" contains C:\Program Files (x86)\STIR\lib
  • "Linker->Input->Additional Dependencies" contains (the entire *.lib content of C:\Program Files (x86)\STIR\lib
IO.lib
iterative_OSMAPOSL.lib
Shape_buildblock.lib
data_buildblock.lib
iterative_OSSPS.lib
recon_buildblock.lib
analytic_FBP2D.lib
display.lib
listmode_buildblock.lib
scatter_buildblock.lib
analytic_FBP3DRP.lib
eval_buildblock.lib
modelling_buildblock.lib
spatial_transformation_buildblock.lib
buildblock.lib
iterative_KOSMAPOSL.lib
numerics_buildblock.lib

Error Log

I have attached the full build error log file [VSSTIRBuildErrorLog.txt](https://github.com/user-attachments/files/16384510/VSSTIRBuildErrorLog.txt) but here is what I believe to be the most important bit.
....
16:39:20:181	1>    Environment Variables passed to tool:
16:39:20:181	1>      VS_UNICODE_OUTPUT=1420
16:39:20:181	1>      SARIF_OUTPUT_PIPE=1092
16:39:20:181	1>    C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\CL.exe /c /I"C:\Program Files (x86)\STIR\include\STIR-6.2" /I"C:\Program Files\boost_1_82_0" /Zi /nologo /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /Fo"x64\Release\\" /Fd"x64\Release\vc143.pdb" /external:W3 /Gd /TP /FC /errorReport:prompt STIRWrapper.cpp
16:39:20:181	1>    Tracking command:
16:39:20:181	1>    C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Tracker.exe /d "C:\Program Files (x86)\MSBuild\15.0\FileTracker\FileTracker32.dll" /i C:\Users\Admin\source\repos\iCRcompany\XC2\STIRWrapper\x64\Release\STIRWrapper.tlog /r C:\USERS\ADMIN\SOURCE\REPOS\ICRCOMPANY\XC2\STIRWRAPPER\STIRWRAPPER.CPP /b MSBuildConsole_CancelEvent1657b85cee834ad1bed4bc82531b5c92  /c "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\CL.exe"  /c /I"C:\Program Files (x86)\STIR\include\STIR-6.2" /I"C:\Program Files\boost_1_82_0" /Zi /nologo /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /Fo"x64\Release\\" /Fd"x64\Release\vc143.pdb" /external:W3 /Gd /TP /FC /errorReport:prompt STIRWrapper.cpp
16:39:20:181	1>    STIRWrapper.cpp
16:39:21:130	1>    C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512: 'stir::NumericVectorWithOffset<stir::Array<1,elemT>,elemT>::NumericVectorWithOffset': no appropriate default constructor available
16:39:21:130	1>    C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:         with
16:39:21:130	1>    C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:         [
16:39:21:130	1>    C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:             elemT=float
16:39:21:130	1>    C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:         ]
16:39:21:171	1>    (compiling source file 'STIRWrapper.cpp')
16:39:21:171	1>        C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16):
16:39:21:171	1>        while trying to match the argument list '()'
16:39:21:171	1>        C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16):
16:39:21:171	1>        the template instantiation context (the oldest one first) is
16:39:21:171	1>            C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Shape\Shape3DWithOrientation.h(128,19):
16:39:21:171	1>            see reference to class template instantiation 'stir::Array<2,float>' being compiled
16:39:21:171	1>            C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(135,1):
16:39:21:171	1>            while compiling class template member function 'stir::Array<2,float>::~Array(void)'
16:39:21:171	1>                C:\Users\Admin\source\repos\iCRcompany\XC2\STIRWrapper\STIRWrapper.cpp(65,40):
16:39:21:171	1>                see the first reference to 'stir::Array<2,float>::~Array' in 'main'
16:39:21:171	1>            C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,5):
16:39:21:171	1>            while compiling class template member function 'stir::Array<2,float>::Array(const stir::IndexRange<2> &)'
16:39:21:171	1>                C:\Program Files (x86)\STIR\include\STIR-6.2\stir\numerics\MatrixFunction.inl(184,20):
16:39:21:171	1>                see the first reference to 'stir::Array<2,float>::Array' in 'stir::diagonal_matrix'
16:39:21:172	1>    The command exited with code 2.
16:39:21:172	1>  Done executing task "CL" -- FAILED.
16:39:21:172	1>Done building target "ClCompile" in project "STIRWrapper.vcxproj" -- FAILED.
16:39:21:172	1>
16:39:21:172	1>Done building project "STIRWrapper.vcxproj" -- FAILED.
16:39:21:172	1>
16:39:21:172	1>Build FAILED.
16:39:21:172	1>
16:39:21:172	1>C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512: 'stir::NumericVectorWithOffset<stir::Array<1,elemT>,elemT>::NumericVectorWithOffset': no appropriate default constructor available
16:39:21:172	1>C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:         with
16:39:21:172	1>C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:         [
16:39:21:172	1>C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:             elemT=float
16:39:21:172	1>C:\Program Files (x86)\STIR\include\STIR-6.2\stir\Array.inl(96,16): error C2512:         ]
16:39:21:172	1>    0 Warning(s)
16:39:21:172	1>    1 Error(s)
16:39:21:172	1>
16:39:21:172	1>Time Elapsed 00:00:01.09
16:39:21:197	========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
16:39:21:197	========== Build completed at 4:39 PM and took 01.276 seconds ==========

I believe this to be an issue with the includes as this error occurs at the build stage. Has anyone else ever encountered this issue? My guess is find_package(STIR 6.0 REQUIRED CONFIG) is doing something with the Includes that I am missing in Visual Studio. Any recommendations on how to proceed?

@robbietuk
Copy link
Collaborator Author

If I am understanding the error correctly Array is being constructed by calling the basetype with 0 arguments, which is NumericVectorWithOffset.

template <class elemT>
Array<1, elemT>::Array()
: base_type()
{}

However, NumericVectorWithOffset does not have a constructor with 0 arguments. These are the only constructors.

//! Constructor from an object of this class' base_type
inline NumericVectorWithOffset(const VectorWithOffset<T>& t);
//! Constructor from an object of this class' base_type
inline NumericVectorWithOffset(const NumericVectorWithOffset& t)
: NumericVectorWithOffset(static_cast<const base_type&>(t))
{}
//! Swap content/members of 2 objects
// implementation in .h because of templates/friends/whatever, see https://stackoverflow.com/a/61020224
friend inline void swap(NumericVectorWithOffset& first, NumericVectorWithOffset& second) // nothrow
{
swap(static_cast<base_type&>(first), static_cast<base_type&>(second));
}
//! move constructor
/*! implementation uses the copy-and-swap idiom, see e.g. https://stackoverflow.com/a/3279550 */
NumericVectorWithOffset(NumericVectorWithOffset&& other) noexcept;


However, this probably isn't the issue. More likely I am missing Includes or the STIR library is not properly supported. My current line of thinking is that

include("${CMAKE_CURRENT_LIST_DIR}/STIRTargets.cmake")

does a lot of work with Boost libraries and builds things like NumericVectorWithOffset from boost. Probably something to do with https://github.com/UCL/STIR/blob/master/src/cmake/stir_lib_target.cmake but I am so deep in the weeds of CMake and STIR's complex build and install structure. I am lost.

Any direction would be appreciated.

@KrisThielemans
Copy link
Collaborator

I'm a bit confused by this. You managed to build STIR with VS (via CMake)? But you don't manage to use it in a VS project? To me, that says you're missing some compilation flags, e.g. you need to say it has to be c++17. I suppose you can figure that out by checking what the compilation flags are when improving the STIR solution generated by CMake.

However, I'm not sure why you're following this path. It's always going to be fragile. Depending on how you built STIR, you'll need various other libraries, openmp settings, etc.

Regarding the actual error, the line referred to is actually l96, but it also calls base_type(). That default conductor should have been auto-generated to the best of my knowledge, unless it happens to be a C** version specific thing, hence my guess above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants