Trouble building NVIDIA VisionWorks (OpenVX) on Windows - build

I am attempting to install VisionWorks on Windows as described in the link named "VisionWorks 1.0 for Windows README" on this page:
https://developer.nvidia.com/embedded/visionworks
According to the README document VisionWorks is compatible with Windows with the following configuration:
OS : Windows 8 x64
OpenCV : public OpenCV 2.4.12
CUDA : NVIDIA CUDA 7.0
I am using exactly this same configuration with the following variables as described in the README (with my specific PC's paths):
[CUDA_VERSION] : 7.0
[CUDA_INSTALL_DIR] : C:\cuda\v7
[OpenCV_INSTALL_DIR] : C:\opencv
[OpenCV_VERSION] : 2412
[VisionWorks_VERSION] : 1.0
[VisionWorks_INSTALL_DIR] : C:\cuda\VisionWorks
[SAMPLES_BUILD_DIR] : C:\cuda\VisionWorks\SAMPLES_BUILD_DIR
I follow the directions in the README as seen below (Images at end of post):
Step 1:
Copy samples from [VisionWorks_INSTALL_DIR]\share\visionworks\sources to a
directory with write access [SAMPLES_BUILD_DIR].
Step 2:
Open Visual Studio's Developer Command Prompt - VS2013 x64 Native Tools
Command Prompt.
Step 3:
Go to the [SAMPLES_BUILD_DIR]:
> cd [SAMPLES_BUILD_DIR]
Step 4:
Edit the config.nmake file to insert correct paths for all prerequisite
installation directory information.
# Dependency locations
CUDA_DIR = [CUDA_INSTALL_DIR]
OPENCV_DIR = [OpenCV_INSTALL_DIR]\build
OpenCV_VERSION = [OpenCV_VERSION]
VISIONWORKS_DIR = [VisionWorks_INSTALL_DIR]
# Debug build?
dbg = 0
Step 5:
Build samples using nmake
> nmake
But when I execute the nmake command I get the following error:
C:\cuda\VisionWorks\SAMPLES_BUILD_DIR> nmake
Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.
cd nvxio && "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\ amd64\nmake.exe" / /nologo build
if NOT EXIST "obj\release" mkdir "obj\release"
cl /EHsc /O2 /MD /nologo "-DVISIONWORKS_DIR=\"C:/cuda/VisionWorks\"" -D USE_GUI=1 -DUSE_GLFW=1
-I./include -I./shaders -I../3rdparty/opengl -I../3rdpa rty/freetype/include -I../3rdparty/glfw3/include -I./src
-DUSE_OPENCV=1 -I "C:\c uda\v7\include" -I "C:\opencv\include" -I "C:\cuda\VisionWorks\include" -I "..\3 rdparty\eigen"
/Fo"obj\release\" /c src\Application.cpp src\ArgumentParser.cpp
src\ConfigParser.cpp src\OptionHandler.cpp src\Utility.cpp
Application.cpp
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(109)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(118)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(127)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(136)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all' ArgumentParser.cpp
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(109)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(118)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(127)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(136)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all' ConfigParser.cpp
./include\NVXIO/OptionHandler.hpp(109) : error C2783: 'nvxio::Range
nvxio::ra nges::all(void)' : could not deduce template argument for
'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
./include\NVXIO/OptionHandler.hpp(118) : error C2783: 'nvxio::Range
nvxio::ra nges::all(void)' : could not deduce template argument for
'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
./include\NVXIO/OptionHandler.hpp(127) : error C2783: 'nvxio::Range
nvxio::ra nges::all(void)' : could not deduce template argument for
'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
./include\NVXIO/OptionHandler.hpp(136) : error C2783: 'nvxio::Range
nvxio::ra nges::all(void)' : could not deduce template argument for
'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all' OptionHandler.cpp
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(109)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(118)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(127)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\OptionHandler.hpp(136)
: error C2783: 'nvxio::Range nvxio::ranges::all(void)' : could not
deduce te mplate argument for 'T'
c:\cuda\visionworks\samples_build_dir\nvxio\include\nvxio\Range.hpp(163)
: see declaration of 'nvxio::ranges::all' Utility.cpp Generating
Code... NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft
Visual Studio 12.0 \VC\BIN\amd64\cl.EXE"' : return code '0x2' Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2' Stop.
C:\cuda\VisionWorks\SAMPLES_BUILD_DIR>
Images showing the steps I performed
What am I doing wrong?

The issue is that there is a bug (more a feature lacking implementation) in the VS 2013 compiler. Function template parameters are only deduced based on types in the arguments, so a call with no arguments will not trigger deduction.
The rather ugly workaround for VisionWorks is to replace the template in Range.hpp
/*
* \ingroup group_nvxio_range
* \brief Creates a range that includes all points.
* \return The range.
*/
template <typename T>
inline Range<T> all() {
return { std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max(), true, true };
}
with a template with a dummy argument, and fix the uses in OptionHandler.hpp accordingly.
/*
* \ingroup group_nvxio_range
* \brief Creates a range that includes all points.
* \return The range.
*/
template <typename T>
inline Range<T> all(T dummy) {
return { std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max(), true, true };
}
so that the calls in OptionHandler.hpp looks like
static ptr real(float *result, const Range<float> &validRange = ranges::all<float>((float)1));
So this makes the code pretty fugly, and defeats somewhat the purpose of the template. This templating issue is fixed in VS 2015, but CUDA doesn´t compile in 2015, which makes more advanced use of OpenVX pointless.

Related

Official asio::co_spawn example does not compile. How do you use co_spawn with io_context?

This sample here isn't compiling:
https://www.boost.org/doc/libs/1_75_0/doc/html/boost_asio/example/cpp17/coroutines_ts/echo_server.cpp
The call to co_spawn does not recognize io_context as a valid executor.
co_spawn(io_context, listener(), detached);
Edit:
Updated the description to point to the correct sample. The issue is occurring in both boost (1.75) and standalone asio (1.24).
cl.exe version is 19.34.31937
Compiler output:
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): error C2665: 'boost::asio::any_io_executor::any_io_executor': no overloaded function could convert all the argument types
C:\Users\...\include\boost\asio\impl\any_io_executor.ipp(34,18): message : could be 'boost::asio::any_io_executor::any_io_executor(std::nullptr_t) noexcept'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : 'boost::asio::any_io_executor::any_io_executor(std::nullptr_t) noexcept': cannot convert argument 1 from 'const OtherExecutor' to 'std::nullptr_t'
with
[
OtherExecutor=boost::asio::io_context::executor_type
]
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,11): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Users\...\include\boost\asio\any_io_executor.hpp(189,3): message : or 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type) noexcept'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type) noexcept': expects 3 arguments - 1 provided
C:\Users\...\include\boost\asio\any_io_executor.hpp(167,3): message : or 'boost::asio::any_io_executor::any_io_executor(Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type)'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : Failed to specialize function template 'boost::asio::any_io_executor::any_io_executor(Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type)'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : With the following template arguments:
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : 'Executor=OtherExecutor'
C:\Users\...\include\boost\asio\any_io_executor.hpp(134,3): message : or 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type) noexcept'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type) noexcept': expects 3 arguments - 1 provided
C:\Users\...\include\boost\asio\any_io_executor.hpp(110,3): message : or 'boost::asio::any_io_executor::any_io_executor(OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type)'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : Failed to specialize function template 'boost::asio::any_io_executor::any_io_executor(OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type)'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : With the following template arguments:
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : 'OtherAnyExecutor=OtherExecutor'
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(255,10): message : while trying to match the argument list '(const OtherExecutor)'
with
[
OtherExecutor=boost::asio::io_context::executor_type
]
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(378,1): message : see reference to function template instantiation 'boost::asio::detail::initiate_co_spawn<boost::asio::any_io_executor>::initiate_co_spawn<Executor>(const OtherExecutor &)' being compiled
with
[
Executor=boost::asio::io_context::executor_type,
OtherExecutor=boost::asio::io_context::executor_type
]
C:\Users\...\include\boost\asio\impl\co_spawn.hpp(375,3): message : see reference to function template instantiation 'boost::asio::detail::initiate_co_spawn<boost::asio::any_io_executor>::initiate_co_spawn<Executor>(const OtherExecutor &)' being compiled
with
[
Executor=boost::asio::io_context::executor_type,
OtherExecutor=boost::asio::io_context::executor_type
]
C:\Users\...\Main\asio_test\asio_test.cpp(298,20): message : see reference to function template instantiation 'void boost::asio::co_spawn<boost::asio::io_context::executor_type,main::<lambda_,const boost::asio::detached_t&>(const Executor &,F &&,CompletionToken,int)' being compiled
with
[
Executor=boost::asio::io_context::executor_type,
F=main::<lambda_,
CompletionToken=const boost::asio::detached_t &
]
You can use the version from Boost 1.75.0 (Asio 1.18.1): https://www.boost.org/doc/libs/1_75_0/doc/html/boost_asio/example/cpp17/coroutines_ts/echo_server.cpp
Your link refers to standalone Asio, which refers to Asio 1.24.0 - or Boost 1.80.0. See the change history here: https://www.boost.org/doc/libs/1_80_0/doc/html/boost_asio/history.html
This was caused by incorrect compiler options in visual studio.
Conformance mode: /permissive was set.
After changing this to /permissive- the sample compiles.
https://learn.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-170

User-defined types with {fmt} library and Visual Studio 2022 (17.2.2)

I am using https://github.com/fmtlib/fmt (commit hash 7e4ad40171aa552d38cb99a5c181a0d7b150facc - at the time of this writing pretty new) with the newest Visual Studio 2022 version (17.2.2) and following this tutorial here
I want to get this working:
struct complex
{
double a;
double b;
};
template<>
struct fmt::formatter<complex>
{
template<typename ParseContext>
constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
template<typename FormatContext>
auto format(complex const& number, FormatContext& ctx) {
return format_to(ctx.out(), "{0} +i{1}", number.a, number.b);
}
};
// ...
// somewhere in main
complex number{1, 2};
std::string message = fmt::format("The number is {}.\n", number);
I get the error message:
ERROR: G:/dev/piper/devertexwahn/flatland/tests/third_party/BUILD.bazel:42:8: Compiling flatland/tests/third_party/fmt_test.cpp failed: (Exit 2): cl.exe failed: error executing command C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 44 arguments skipped)
flatland/tests/third_party/fmt_test.cpp(53): error C2668: 'std::format_to': ambiguous call to overloaded function
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\format(3046): note: could be '_OutputIt std::format_to<OutputIt,const double&,const double&>(_OutputIt,const std::_Basic_format_string<char,const double &,const double &>,const double &,const double &)' [found using argument-dependent lookup]
with
[
_OutputIt=fmt::v8::appender,
OutputIt=fmt::v8::appender
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(3195): note: or 'OutputIt fmt::v8::format_to<OutputIt,const double&,const double&,0>(OutputIt,fmt::v8::basic_format_string<char,const double &,const double &>,const double &,const double &)'
with
[
OutputIt=fmt::v8::appender
]
flatland/tests/third_party/fmt_test.cpp(52): note: while trying to match the argument list '(OutputIt, const char [10], const double, const double)'
with
[
OutputIt=fmt::v8::appender
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(713): note: see reference to function template instantiation 'auto fmt::v8::formatter<complex,char,void>::format<Context>(const complex &,FormatContext &)' being compiled
with
[
Context=fmt::v8::format_context,
FormatContext=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1457): note: see reference to function template instantiation 'bool fmt::v8::detail::has_const_formatter<U,Context>(void)' being compiled
with
[
U=complex,
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1486): note: see reference to class template instantiation 'fmt::v8::detail::arg_mapper<Context>::formattable<const complex &,complex>' being compiled
with
[
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1697): note: see reference to alias template instantiation 'fmt::v8::detail::mapped_type_constant<complex,Context>' being compiled
with
[
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1858): note: see reference to function template instantiation 'unsigned __int64 fmt::v8::detail::encode_types<Context,complex,>(void)' being compiled
with
[
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(3167): note: see reference to class template instantiation 'fmt::v8::format_arg_store<fmt::v8::format_context,complex>' being compiled
flatland/tests/third_party/fmt_test.cpp(59): note: see reference to function template instantiation 'std::string fmt::v8::format<complex&>(fmt::v8::basic_format_string<char,complex &>,complex &)' being compiled
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1696): error C2062: type 'unknown-type' unexpected
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1696): error C2144: syntax error: 'unknown-type' should be preceded by '('
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1697): error C2039: 'value': is not a member of '`global namespace''
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1855): error C3615: constexpr function 'fmt::v8::detail::encode_types' cannot result in a constant expression
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1858): note: failure was caused by control reaching the end of a constexpr function
Target //flatland/tests/third_party:fmt_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
The code seems to work with GCC9 on Ubuntu 20.04 and with Apple CLang on macOS. Any ideas what I am doing wrong here?
The error is caused by the std::format_to function introduced in C++20. To fix it, qualify your calls to fmt::format_to. For example, instead of
return format_to(ctx.out(), "{0} +i{1}", number.a, number.b);
do this instead:
return fmt::format_to(ctx.out(), "{0} +i{1}", number.a, number.b);
See this issue for more info: format conflict with Visual Studio 2022 17.2.0.

Creating boost::thread with an std::shared_ptr object instance

I have the following two code segments. The first block compiles and works as expected. However the second block does not compile.
My question is, given the code below what is the correct syntax when trying to create a thread based on an instance of an object that is being proxied by a shared_ptr?
#include <iostream>
#include <new>
#include <memory>
#include <boost/thread.hpp>
struct foo
{
void boo() {}
};
int main()
{
//This works
{
foo* fptr = new foo;
boost::thread t(&foo::boo,fptr);
t.join();
delete fptr;
}
//This doesn't work
{
std::shared_ptr<foo> fptr(new foo);
boost::thread t(&foo::boo,fptr);
t.join();
}
return 0;
}
The compiler error:
Error 5 error C2784: 'T *boost::get_pointer(T *)' : could not deduce template argument for 'T *' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 3 error C2784: 'T *boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce template argument for 'const std::auto_ptr<_Ty> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 4 error C2784: 'T *boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce template argument for 'const std::auto_ptr<_Ty> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 8 error C2784: 'T *boost::get_pointer(const boost::shared_ptr<X> &)' : could not deduce template argument for 'const boost::shared_ptr<X> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 9 error C2784: 'T *boost::get_pointer(const boost::shared_ptr<X> &)' : could not deduce template argument for 'const boost::shared_ptr<X> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 1 error C2784: 'T *boost::get_pointer(const boost::scoped_ptr<T> &)' : could not deduce template argument for 'const boost::scoped_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 2 error C2784: 'T *boost::get_pointer(const boost::scoped_ptr<T> &)' : could not deduce template argument for 'const boost::scoped_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 6 error C2784: 'T *boost::get_pointer(const boost::reference_wrapper<T> &)' : could not deduce template argument for 'const boost::reference_wrapper<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 7 error C2784: 'T *boost::get_pointer(const boost::reference_wrapper<T> &)' : could not deduce template argument for 'const boost::reference_wrapper<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 10 error C2784: 'T *boost::get_pointer(const boost::intrusive_ptr<T> &)' : could not deduce template argument for 'const boost::intrusive_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
Error 11 error C2784: 'T *boost::get_pointer(const boost::intrusive_ptr<T> &)' : could not deduce template argument for 'const boost::intrusive_ptr<T> &' from 'std::tr1::shared_ptr<_Ty>' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest
The problem is that boost::thread relies on boost::mem_fn to handle member functions, and boost::mem_fn (or at least the version you are using) doesn't know how to use a std::shared_ptr to invoke a member function as it expects you to use boost::shared_ptr or one of the myriad of other smart pointer types in your error listing.
The raw pointer works because boost::mem_fn already has that overload. The solutions are to use boost::shared_ptr or std::mem_fn. The latter works because std::mem_fn knows how to interact with std::shared_ptr
boost::thread t(std::mem_fn(&foo::boo), fptr);
An alternative to Dave S's answer is to define this (before <boost/mem_fn.hpp> gets included):
namespace boost
{
template<typename T>
inline T*
get_pointer(const std::shared_ptr<T>& p)
{ return p.get(); }
}
That "teaches" boost::mem_fn to obtain a raw pointer from a std::shared_ptr.
In C++11 std::mem_fn is required to work with any pointer-like type, simply by dereferencing it i.e. *fptr, but boost::mem_fn instead uses *boost::get_pointer(fptr). I don't know if it's fixed in the latest version of Boost, but I would argue that it should use SFINAE to detect whether get_pointer will work, and should just dereference it otherwise.

compile errors log4cxx with __stdcall and Boost 1.47.0

I'll be very pleased if you help.
My IDE is VS2010.
I'm using boost 1.47.0, especially boost::asio.
After some days of developing I decided to add log4cxx.
log4cxx needs to change calling convention to __stdcall
I surprisingly got lots of compiling error. They are ~ 70 errors.
I've googled a bit and found these:
#define BOOST_BIND_ENABLE_STDCALL
#define BOOST_MEM_FN_ENABLE_STDCALL
It helps. Now there are just ~10 errors.
Here there are:
1>ClCompile:
1> main.cpp
1>D:\Development\lib\boost_1_47_0\boost/detail/interlocked.hpp(61): error C2373: '_InterlockedCompareExchange' : redefinition; different type modifiers
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\intrin.h(214) : see declaration of '_InterlockedCompareExchange'
1>D:\Development\lib\boost_1_47_0\boost/detail/interlocked.hpp(62): error C2373: '_InterlockedExchange' : redefinition; different type modifiers
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\intrin.h(192) : see declaration of '_InterlockedExchange'
1>D:\Development\lib\boost_1_47_0\boost/detail/interlocked.hpp(63): error C2373: '_InterlockedExchangeAdd' : redefinition; different type modifiers
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\intrin.h(204) : see declaration of '_InterlockedExchangeAdd'
1>D:\Development\lib\boost_1_47_0\boost/smart_ptr/detail/sp_counted_base_w32.hpp(92): error C2446: '==' : no conversion from 'long' to 'long (__stdcall *)(volatile long *,long,long)'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>D:\Development\lib\boost_1_47_0\boost/smart_ptr/detail/sp_counted_base_w32.hpp(92): error C2040: '==' : 'long (__stdcall *)(volatile long *,long,long)' differs in levels of indirection from 'long'
1>D:\Development\lib\boost_1_47_0\boost/smart_ptr/detail/sp_counted_base_w32.hpp(92): error C3861: '_InterlockedCompareExchange': identifier not found
1>D:\Development\lib\boost_1_47_0\boost/smart_ptr/detail/spinlock_w32.hpp(62): error C3861: '_InterlockedExchange': identifier not found
1>D:\Development\lib\boost_1_47_0\boost/smart_ptr/detail/spinlock_w32.hpp(62): error C2440: 'initializing' : cannot convert from 'long (__stdcall *)(volatile long *,long)' to 'long'
1> There is no context in which this conversion is possible
1>D:\Development\lib\boost_1_47_0\boost/asio/detail/impl/signal_set_service.ipp(74): error C2664: 'signal' : cannot convert parameter 2 from 'void (__stdcall *)(int)' to 'void (__cdecl *)(int)'
1> None of the functions with this name in scope match the target type
1>D:\Development\lib\boost_1_47_0\boost/asio/detail/impl/signal_set_service.ipp(246): error C2664: 'signal' : cannot convert parameter 2 from 'void (__stdcall *)(int)' to 'void (__cdecl *)(int)'
1> None of the functions with this name in scope match the target type
1>main.cpp(20): warning C4007: 'main' : must be '__cdecl'
How can I solve them?
Any little ideas or hints?
You also need
#define BOOST_USE_WINDOWS_H
and possibly /Gz (__stdcall)
If your code looks something like:
#include "log4cxx/logger.h"
#include "log4cxx/basicconfigurator.h"
#include "log4cxx/helpers/exception.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
int main()
{
//stuff
}
and you compile with -llog4cxx then you should be fine.

boost threadpool

I'm trying to create a threadpool with the boost threadpool library, but on defining it I keep getting lots of error about template params being wrong.
I'm probably doing something fundamentally wrong, but I'm not seeing it?
//Threadpool
typedef boost::threadpool::thread_pool<
boost::threadpool::task_func,
boost::threadpool::fifo_scheduler<tsk>,
boost::threadpool::static_size<boost::threadpool::fifo_pool>,
boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
> pool;
ERRORS:
------ Build started: Project: Trial, Configuration: Debug Win32 ------
Compiling...
Trial.cpp
error C2923: 'boost::threadpool::fifo_scheduler' : 'tsk' is invalid as template argument '#1', type expected
see declaration of 'tsk'
error C3200: 'boost::threadpool::fifo_pool' : invalid template argument for template parameter 'SizePolicy', expected a class template
error C3200: 'boost::threadpool::resize_controller<Pool>' : invalid template argument for template parameter 'SizePolicyController', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
error C3200: 'boost::threadpool::wait_for_active_tasks<Pool>' : invalid template argument for template parameter 'ShutdownPolicy', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
error C3200: 'boost::threadpool::fifo_pool' : invalid template argument for template parameter 'SizePolicy', expected a class template
see reference to class template instantiation 'boost::threadpool::thread_pool<Task,SchedulingPolicy,SizePolicy,SizePolicyController,ShutdownPolicy>' being compiled
with
[
Task=boost::threadpool::task_func,
SchedulingPolicy=boost::threadpool::fifo_scheduler,
SizePolicy=boost::threadpool::fifo_pool,
SizePolicyController=boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
ShutdownPolicy=boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(79) : error C3200: 'boost::threadpool::resize_controller<Pool>' : invalid template argument for template parameter 'SizePolicyController', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(79) : error C3200: 'boost::threadpool::wait_for_active_tasks<Pool>' : invalid template argument for template parameter 'ShutdownPolicy', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(91) : error C2059: syntax error : '<'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(91) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(92) : error C2059: syntax error : '<'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(92) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(111) : error C2146: syntax error : missing ';' before identifier 'size_controller'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(111) : error C2501: 'boost::threadpool::thread_pool<Task,SchedulingPolicy,SizePolicy,SizePolicyController,ShutdownPolicy>::size_controller_type' : missing storage-class or type specifiers
with
[
Task=boost::threadpool::task_func,
SchedulingPolicy=boost::threadpool::fifo_scheduler,
SizePolicy=boost::threadpool::fifo_pool,
SizePolicyController=boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
ShutdownPolicy=boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(112) : warning C4183: 'size_controller': missing return type; assumed to be a member function returning 'int'
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
According to your comment, tsk is a variable. You can't pass runtime expressions (such as a variable) as template parameters. Templates are entirely compile-time.
For this specific problem, you just need to do this:
typedef boost::threadpool::thread_pool<> pool;
void taskfunc();
// later on...
pool my_pool;
my_pool.schedule(&taskfunc);
boost::threadpool::task_func is just a boost::function0<void> — any 0-arg void function pointer can convert to that type.