Can't install the Vulkan SDK from tarball on Fedora Linux - c++

I tried to install the Vulkan SDK from the tarball from the LunarG website (version 1.3.224.1) on Fedora 37 beta (I also tried it on Nobara Linux 36) and kept getting these errors.
In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = Json::Value::ValueHolder]’,
inlined from ‘void Json::Value::swapPayload(Json::Value&)’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:2967:12,
inlined from ‘bool Json::Reader::readValue()’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:433:31:
/usr/include/c++/12/bits/move.h:205:7: error: ‘v.Json::Value::value_’ may be used uninitialized [-Werror=maybe-uninitialized]
205 | __a = _GLIBCXX_MOVE(__b);
| ^~~
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp: In member function ‘bool Json::Reader::readValue()’:
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:432:11: note: ‘v’ declared here
432 | Value v;
| ^
In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = Json::Value::ValueHolder]’,
inlined from ‘void Json::Value::swapPayload(Json::Value&)’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:2967:12,
inlined from ‘bool Json::Reader::readValue()’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:446:33:
/usr/include/c++/12/bits/move.h:205:7: error: ‘v.Json::Value::value_’ may be used uninitialized [-Werror=maybe-uninitialized]
205 | __a = _GLIBCXX_MOVE(__b);
| ^~~
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp: In member function ‘bool Json::Reader::readValue()’:
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:445:13: note: ‘v’ declared here
445 | Value v;
| ^
In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = Json::Value::ValueHolder]’,
inlined from ‘void Json::Value::swapPayload(Json::Value&)’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:2967:12,
inlined from ‘bool Json::OurReader::readValue()’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:1355:31:
/usr/include/c++/12/bits/move.h:205:7: error: ‘v.Json::Value::value_’ may be used uninitialized [-Werror=maybe-uninitialized]
205 | __a = _GLIBCXX_MOVE(__b);
| ^~~
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp: In member function ‘bool Json::OurReader::readValue()’:
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:1354:11: note: ‘v’ declared here
1354 | Value v;
| ^
In function ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = Json::Value::ValueHolder]’,
inlined from ‘void Json::Value::swapPayload(Json::Value&)’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:2967:12,
inlined from ‘bool Json::OurReader::readValue()’ at /home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:1392:33:
/usr/include/c++/12/bits/move.h:205:7: error: ‘v.Json::Value::value_’ may be used uninitialized [-Werror=maybe-uninitialized]
205 | __a = _GLIBCXX_MOVE(__b);
| ^~~
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp: In member function ‘bool Json::OurReader::readValue()’:
/home/said/vulkan/1.3.224.1/source/VulkanTools/submodules/jsoncpp/dist/jsoncpp.cpp:1391:13: note: ‘v’ declared here
1391 | Value v;
| ^
I tried going through the CMake files to try to disable the -Werror=maybe-uninitialized option but I'm not familiar with CMake so couldn't find a way to do that. I also tried going through the C++ source code itself and trying to fix it that way but still could not fix the issue.
Thank you very much.

Related

How to define an object in the header file and initialize it in the source file

I have an object qp that is defined as
#include <proxsuite/proxqp/dense/dense.hpp>
namespace fr3_ros {
class WaypointController : public controller_interface::MultiInterfaceController<franka_hw::FrankaModelInterface,
hardware_interface::EffortJointInterface,
franka_hw::FrankaStateInterface> {
...
private:
proxsuite::proxqp::isize dim = 14;
proxsuite::proxqp::isize n_eq = 7;
proxsuite::proxqp::isize n_in = 0;
proxsuite::proxqp::dense::QP<double> qp(dim, n_eq, n_in);
...
}
From the documetation here controller_interface::MultiInterfaceController has the constructor
MultiInterfaceController (bool allow_optional_interfaces=false)
Since I did not define a new constructor, that would be the only constructor WaypointController has.
However, if I put this in the header file it would give me an error when compiling:
In file included from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:1:
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:113:43: error: ‘dim’ is not a type
113 | proxsuite::proxqp::dense::QP<double> qp(dim, n_eq, n_in);
| ^~~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:113:48: error: ‘n_eq’ is not a type
113 | proxsuite::proxqp::dense::QP<double> qp(dim, n_eq, n_in);
| ^~~~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:113:54: error: ‘n_in’ is not a type
113 | proxsuite::proxqp::dense::QP<double> qp(dim, n_eq, n_in);
| ^~~~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp: In member function ‘virtual void fr3_ros::WaypointController::update(const ros::Time&, const ros::Duration&)’:
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:225:5: error: invalid use of member function ‘proxsuite::proxqp::dense::QP<double> fr3_ros::WaypointController::qp(int, int, int)’ (did you forget the ‘()’ ?)
225 | qp.update(qp_H, qp_g, qp_A, qp_b, std::nullopt, std::nullopt, std::nullopt);
| ^~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:227:5: error: invalid use of member function ‘proxsuite::proxqp::dense::QP<double> fr3_ros::WaypointController::qp(int, int, int)’ (did you forget the ‘()’ ?)
227 | qp.init(qp_H, qp_g, qp_A, qp_b, std::nullopt, std::nullopt, std::nullopt);
| ^~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:230:3: error: invalid use of member function ‘proxsuite::proxqp::dense::QP<double> fr3_ros::WaypointController::qp(int, int, int)’ (did you forget the ‘()’ ?)
230 | qp.solve();
| ^~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:232:13: error: invalid use of member function ‘proxsuite::proxqp::dense::QP<double> fr3_ros::WaypointController::qp(int, int, int)’ (did you forget the ‘()’ ?)
232 | torques = qp.results.x.bottomLeftCorner(7, 1);
| ^~
I also tried separating the declaration and definition, in the header file I have
proxsuite::proxqp::isize dim = 14;
proxsuite::proxqp::isize n_eq = 7;
proxsuite::proxqp::isize n_in = 0;
proxsuite::proxqp::dense::QP<double> qp;
and in the source file I have
qp = proxsuite::proxqp::dense::QP<double>(dim, n_eq, n_in);
this gives me another error
In file included from /opt/ros/noetic/include/class_loader/class_loader_core.hpp:45,
from /opt/ros/noetic/include/class_loader/class_loader.hpp:46,
from /opt/ros/noetic/include/pluginlib/class_list_macros.hpp:40,
from /opt/ros/noetic/include/pluginlib/class_list_macros.h:35,
from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:13:
/opt/ros/noetic/include/class_loader/meta_object.hpp: In instantiation of ‘B* class_loader::impl::MetaObject<C, B>::create() const [with C = fr3_ros::WaypointController; B = controller_interface::ControllerBase]’:
/opt/ros/noetic/include/class_loader/meta_object.hpp:196:7: required from here
/opt/ros/noetic/include/class_loader/meta_object.hpp:198:12: error: use of deleted function ‘fr3_ros::WaypointController::WaypointController()’
198 | return new C;
| ^~~~~
In file included from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:1:
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:36:7: note: ‘fr3_ros::WaypointController::WaypointController()’ is implicitly deleted because the default definition would be ill-formed:
36 | class WaypointController : public controller_interface::MultiInterfaceController<franka_hw::FrankaModelInterface,
| ^~~~~~~~~~~~~~~~~~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:36:7: error: no matching function for call to ‘proxsuite::proxqp::dense::QP<double>::QP()’
In file included from /home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/dense.hpp:8,
from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:31,
from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:1:
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:94:3: note: candidate: ‘proxsuite::proxqp::dense::QP<T>::QP(proxsuite::linalg::veg::isize, proxsuite::linalg::veg::isize, proxsuite::linalg::veg::isize) [with T = double; proxsuite::linalg::veg::isize = long int]’
94 | QP(isize _dim, isize _n_eq, isize _n_in)
| ^~
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:94:3: note: candidate expects 3 arguments, 0 provided
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate: ‘proxsuite::proxqp::dense::QP<double>::QP(const proxsuite::proxqp::dense::QP<double>&)’
81 | struct QP
| ^~
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate expects 1 argument, 0 provided
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate: ‘proxsuite::proxqp::dense::QP<double>::QP(proxsuite::proxqp::dense::QP<double>&&)’
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate expects 1 argument, 0 provided
If I add extern in the header file, I get the error
In file included from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:1:
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:113:3: error: storage class specified for ‘qp’
113 | extern proxsuite::proxqp::dense::QP<double> qp;
| ^~~~~~
In file included from /opt/ros/noetic/include/class_loader/class_loader_core.hpp:45,
from /opt/ros/noetic/include/class_loader/class_loader.hpp:46,
from /opt/ros/noetic/include/pluginlib/class_list_macros.hpp:40,
from /opt/ros/noetic/include/pluginlib/class_list_macros.h:35,
from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:13:
/opt/ros/noetic/include/class_loader/meta_object.hpp: In instantiation of ‘B* class_loader::impl::MetaObject<C, B>::create() const [with C = fr3_ros::WaypointController; B = controller_interface::ControllerBase]’:
/opt/ros/noetic/include/class_loader/meta_object.hpp:196:7: required from here
/opt/ros/noetic/include/class_loader/meta_object.hpp:198:12: error: use of deleted function ‘fr3_ros::WaypointController::WaypointController()’
198 | return new C;
| ^~~~~
In file included from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:1:
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:36:7: note: ‘fr3_ros::WaypointController::WaypointController()’ is implicitly deleted because the default definition would be ill-formed:
36 | class WaypointController : public controller_interface::MultiInterfaceController<franka_hw::FrankaModelInterface,
| ^~~~~~~~~~~~~~~~~~
/home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:36:7: error: no matching function for call to ‘proxsuite::proxqp::dense::QP<double>::QP()’
In file included from /home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/dense.hpp:8,
from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/include/fr3_ros/waypoint_controller.h:31,
from /home/bolun/bolun_ws/src/fr3_ros/fr3_ros/src/waypoint_controller.cpp:1:
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:94:3: note: candidate: ‘proxsuite::proxqp::dense::QP<T>::QP(proxsuite::linalg::veg::isize, proxsuite::linalg::veg::isize, proxsuite::linalg::veg::isize) [with T = double; proxsuite::linalg::veg::isize = long int]’
94 | QP(isize _dim, isize _n_eq, isize _n_in)
| ^~
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:94:3: note: candidate expects 3 arguments, 0 provided
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate: ‘proxsuite::proxqp::dense::QP<double>::QP(const proxsuite::proxqp::dense::QP<double>&)’
81 | struct QP
| ^~
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate expects 1 argument, 0 provided
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate: ‘proxsuite::proxqp::dense::QP<double>::QP(proxsuite::proxqp::dense::QP<double>&&)’
/home/bolun/miniconda3/envs/fr3_env/include/proxsuite/proxqp/dense/wrapper.hpp:81:8: note: candidate expects 1 argument, 0 provided
Is it possible for someone to help me understand what is the issue here? Is the a universal issue in C++ or is it just this package?
Thanks in advance!
If I were to intialize qp using a member initialize list, should it look like:
public:
WaypointController()
: dim(14), neq(7), n_in(0), qp(dim, n_eq, n_in)
{
}
The error message you're getting is not particularly helpful here, but let me explain it anyways, so you understand what's going on.
C++ believes that you're trying to declare a function, not define a variable.
proxsuite::proxqp::dense::QP<double> qp(dim, n_eq, n_in);
The return type is proxsuite::proxqp::dense::QP<double>, the function's name is qp, and it takes 3 parameters, of types dim, n_eq, and n_in.
The fact that this is not what you intended in entirely irrelevant.
Knowing this, your error messages make a lot more sense.
The solution to this is to declare the field in the header file, like so:
proxsuite::proxqp::dense::QP<double> qp;
And then to you need to initialize qp in your constructor. Use a member initialization list for this.

Error compiling libtorch with C++ on windows

I get the following Error due to some headers from the libtorch library (DynamicCast.h, different functions) when i try to compile a simple test program:
PS C:\Users\a\Desktop\MachineLearningDemos\build> cmake --build . --config Release
[ 50%] Building CXX object CMakeFiles/MinEx.dir/MinEx.cpp.obj
In file included from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DeviceType.h:8,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/Device.h:3,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/ATen/core/TensorBody.h:11,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/ATen/core/Tensor.h:3,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/ATen/Tensor.h:3,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/torch/csrc/autograd/function_hook.h:3,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/torch/csrc/autograd/cpp_hook.h:2,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/torch/csrc/autograd/variable.h:6,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/torch/csrc/autograd/autograd.h:3,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/torch/csrc/api/include/torch/autograd.h:3,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/torch/csrc/api/include/torch/all.h:7,
from C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/torch/csrc/api/include/torch/torch.h:3,
from C:/Users/Potzkai/Desktop/MachineLearningDemos/MinEx.cpp:1:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘dest_t c10::fetch_and_cast(c10::ScalarType, const void*) [with dest_t = c10::qint8]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘void c10::cast_and_store(c10::ScalarType, void*, src_t) [with src_t = c10::qint8]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘dest_t c10::fetch_and_cast(c10::ScalarType, const void*) [with dest_t = c10::quint8]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘void c10::cast_and_store(c10::ScalarType, void*, src_t) [with src_t = c10::quint8]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘dest_t c10::fetch_and_cast(c10::ScalarType, const void*) [with dest_t = c10::qint32]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘void c10::cast_and_store(c10::ScalarType, void*, src_t) [with src_t = c10::qint32]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘dest_t c10::fetch_and_cast(c10::ScalarType, const void*) [with dest_t = c10::quint4x2]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘void c10::cast_and_store(c10::ScalarType, void*, src_t) [with src_t = c10::quint4x2]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘dest_t c10::fetch_and_cast(c10::ScalarType, const void*) [with dest_t = c10::quint2x4]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h: In function ‘void c10::cast_and_store(c10::ScalarType, void*, src_t) [with src_t = c10::quint2x4]’:
C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/include/c10/core/DynamicCast.h:112:1: error: ‘__assert_fail’ was not declared in this scope; did you mean ‘__assert_func’?
112 | AT_FORALL_QINT_TYPES(DEFINE_UNCASTABLE)
| ^~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/MinEx.dir/build.make:77: CMakeFiles/MinEx.dir/MinEx.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/MinEx.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
THe setup is as follows: libtorch cpu version for windows downloaded from the pytorch homepage. gnu 11.3.0 as compiler. The Following Code shall be compiled:
#include <torch/torch.h>
#include <iostream>
int main() {
//torch::Tensor tensor = torch::rand({2, 3});
//std::cout << tensor << std::endl;
return 0;
}
the following CMakeLists.txt is used:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(MinEx)
set(CMAKE_PREFIX_PATH "C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu/share/cmake/Torch")
set(TORCH_DIR "C:/Users/a/Desktop/MachineLearningDemos/libtorch_cpu")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(MinEx MinEx.cpp)
target_link_libraries(MinEx "${TORCH_LIBRARIES}")
set_property(TARGET MinEx PROPERTY CXX_STANDARD 14)
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET MinEx
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:MinEx>)
endif (MSVC)
i compile with cmake --build . --config Release and then this error occurs.
Has anyone got an idea, where this comes from? (I tried to follow the example from https://pytorch.org/cppdocs/installing.html)
I checked if G++/make/cmake is working correctly (reinstalled everything) and if the libraries are the right ones. As soon as I try to include <torch/torch.h> the error occurs.

note: ‘Entity_c::Entity_c(const Entity_c&)’ is implicitly deleted because the default definition would be ill-formed:

I know this question have been already asked and answered, but even with that, I cannot figure it out
In file included from /usr/include/c++/9.2.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from /usr/include/c++/9.2.0/bits/allocator.h:46,
from /usr/include/c++/9.2.0/list:61,
from src/composants/List/List.hpp:14,
from src/composants/List/List.cpp:8:
/usr/include/c++/9.2.0/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Entity_c; _Args = {const Entity_c&}; _Tp = std::_List_node<Entity_c>]’:
/usr/include/c++/9.2.0/bits/alloc_traits.h:482:2: required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Entity_c; _Args = {const Entity_c&}; _Tp = std::_List_node<Entity_c>; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<std::_List_node<Entity_c> >]’
/usr/include/c++/9.2.0/bits/stl_list.h:633:33: required from ‘std::__cxx11::list<_Tp, _Alloc>::_Node* std::__cxx11::list<_Tp, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const Entity_c&}; _Tp = Entity_c; _Alloc = std::allocator<Entity_c>; std::__cxx11::list<_Tp, _Alloc>::_Node = std::_List_node<Entity_c>]’
/usr/include/c++/9.2.0/bits/stl_list.h:1907:10: required from ‘void std::__cxx11::list<_Tp, _Alloc>::_M_insert(std::__cxx11::list<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {const Entity_c&}; _Tp = Entity_c; _Alloc = std::allocator<Entity_c>; std::__cxx11::list<_Tp, _Alloc>::iterator = std::_List_iterator<Entity_c>]’
/usr/include/c++/9.2.0/bits/stl_list.h:1208:9: required from ‘void std::__cxx11::list<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Entity_c; _Alloc = std::allocator<Entity_c>; std::__cxx11::list<_Tp, _Alloc>::value_type = Entity_c]’
src/composants/List/List.cpp:57:29: required from here
/usr/include/c++/9.2.0/ext/new_allocator.h:145:20: error: use of deleted function ‘Entity_c::Entity_c(const Entity_c&)’
145 | noexcept(noexcept(::new((void *)__p)
| ^~~~~~~~~~~~~~~~~~
146 | _Up(std::forward<_Args>(__args)...)))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/composants/List/List.cpp:9:
src/composants/Entity/Entity.hpp:16:7: note: ‘Entity_c::Entity_c(const Entity_c&)’ is implicitly deleted because the default definition would be ill-formed:
16 | class Entity_c {
| ^~~~~~~~
src/composants/Entity/Entity.hpp:16:7: error: use of deleted function ‘sf::Mutex::Mutex(const sf::Mutex&)’
In file included from src/composants/List/List.hpp:12,
from src/composants/List/List.cpp:8:
/usr/include/SFML/System/Mutex.hpp:47:23: note: ‘sf::Mutex::Mutex(const sf::Mutex&)’ is implicitly deleted because the default definition would be ill-formed:
47 | class SFML_SYSTEM_API Mutex : NonCopyable
| ^~~~~
/usr/include/SFML/System/Mutex.hpp:47:23: error: ‘sf::NonCopyable::NonCopyable(const sf::NonCopyable&)’ is private within this context
In file included from /usr/include/SFML/System/Thread.hpp:32,
from src/composants/List/List.hpp:11,
from src/composants/List/List.cpp:8:
/usr/include/SFML/System/NonCopyable.hpp:77:5: note: declared private here
77 | NonCopyable(const NonCopyable&);
| ^~~~~~~~~~~
In file included from src/composants/List/List.cpp:9:
src/composants/Entity/Entity.hpp:16:7: error: use of deleted function ‘sf::Mutex::Mutex(const sf::Mutex&)’
16 | class Entity_c {
I do not understand thoses errors, but I've still figured out which part of my code is throwing it :
54 void List_c::operator++(int)
55 {
56 Entity_c *entity = new Entity_c;
57 m_list.push_back(*entity);
58 }
I have to say that I don't really understand why this is throwing something like (as I understood) I'm trying to call Entity_c::Entity_c(const Entity_c&).
Entity_c is defined as follow :
16 class Entity_c {
17 public:
18 Entity_c();
19 ~Entity_c();
...
81 };
Well, it is possible that I just didn't understand that error at all, so please, feel free to show me my mistakes.
The main clues are class SFML_SYSTEM_API Mutex : NonCopyable and "use of deleted function ‘sf::Mutex::Mutex(const sf::Mutex&)" - a sf::Mutex can't be copied, and push_back does exactly that.
Since sf::Mutex can't be copied, neither can (by default) things that have one as a member.
You can make Entity_c copyable by adding a copy constructor that doesn't copy the mutex from the original but creates a new one.
(Or avoid copying - see below.)
You should also not create the object with new - you're leaking memory.
Either do this:
Entity_c entity;
m_list.push_back(entity);
or this:
m_list.push_back(Entity_c{});
or this, which does not require copying at all:
m_list.emplace_back();
(As a side note, that use of ++ is quite surprising. I doubt that you do this so often that you need very terse syntax for it - I would go with List_c::add_entity() or something like that.)

Compile header file and two .cpp files in Unix/Linux (Ubuntu)

I am trying to compile 3 files total and can not get it to. The code works in visual++. I have uploaded all 3 files in the same dir and used the following command.
g++ -o edit Album.cpp lab8.cpp
My file names are listed below
Album.cpp
Album.h
lab8.cpp
Note the code was written in visual studio C++ and compiled just fine there.
Results in the following
lab8.cpp: In function ‘std::vector read_album_file(std::string)’:
lab8.cpp:142:25: error: no matching function for call to ‘std::basic_ifstream::basic_ifstream(std::string&)’
ifstream read (filename);// the ifstream is used to read from the file
^
lab8.cpp:142:25: note: candidates are:
In file included from lab8.cpp:38:0:
/usr/include/c++/4.8/fstream:467:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits; std::ios_base::openmode = std::_Ios_Openmode]
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
^
/usr/include/c++/4.8/fstream:467:7: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const char*’
/usr/include/c++/4.8/fstream:453:7: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char; _Traits = std::char_traits]
basic_ifstream() : __istream_type(), _M_filebuf()
^
/usr/include/c++/4.8/fstream:453:7: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/4.8/fstream:427:11: note: std::basic_ifstream::basic_ifstream(const std::basic_ifstream&)
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
/usr/include/c++/4.8/fstream:427:11: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘const std::basic_ifstream&’
Look at the constructor prototype of ifstream. It takes a const char * and a optional argument, soyou need to write filename.c_str()

Compile errors with linked files in C++

Edit: I've reduced a majority of the errors with the std:: prefix on string declarations. However, there seems to be a problem with a few functions, particularly the definitions of those functions who have a string as a parameter.
Edit #2: Updated my code (I DID have the std:: prefix on my function declarations, but hadn't reflected it in my post). Please see the very bottom for errors displayed when I add the std:: prefix to string parameters in the problematic functions.
I have a header file movie.h with the following code (relevant code):
#include <string>
class Movie
{
public:
void addMovieName(std::string movie);
void addLastName(std::string nameLast);
void addFirstName(std::string nameFirst);
private:
string movieName,
directorLastName,
directorFirstName,
directorFullName;
};
And an implementation file movie.cpp like this (relevant code):
#include "movie.h"
// addFirstName, addLastName, and addMovie name all do the same things
// so I'm only including one since they all generate the same error
void Movie::addFirstName(string nameFirst)
{
directorFirstName = nameFirst.resize(10, ' ');
}
Upon compilation, I get the following errors:
g++ -c movie.cpp -o movie.o
movie.cpp:225: error: variable or field ‘addFirstName’ declared void
movie.cpp:225: error: ‘int Movie::addFirstName’ is not a static member of ‘class Movie’
movie.cpp:225: error: ‘string’ was not declared in this scope
movie.cpp:226: error: expected ‘,’ or ‘;’ before ‘{’ token
movie.cpp:240: error: variable or field ‘addLastName’ declared void
movie.cpp:240: error: ‘int Movie::addLastName’ is not a static member of ‘class Movie’
movie.cpp:240: error: ‘string’ was not declared in this scope
movie.cpp:241: error: expected ‘,’ or ‘;’ before ‘{’ token
movie.cpp:255: error: variable or field ‘addMovieName’ declared void
movie.cpp:255: error: ‘int Movie::addMovieName’ is not a static member of ‘class Movie’
movie.cpp:255: error: ‘string’ was not declared in this scope
movie.cpp:256: error: expected ‘,’ or ‘;’ before ‘{’ token
make: *** [movie.o] Error 1
Some of who have said I need to prepend std:: to the string parameters in the function definitions.
Upon doing this:
// adding std:: prefix
void Movie::addFirstName(std::string nameFirst)
{
directorFirstName = nameFirst.resize(10, ' ');
}
I get the following errors. Note that I only changed it for a single function. The first errors I don't understand, whereas the rest remain the same as before.
g++ -c movie.cpp -o movie.o
movie.cpp: In member function ‘void Movie::addFirstName(std::string)’:
movie.cpp:227: error: no match for ‘operator=’ in ‘((Movie*)this)->Movie::directorFirstName = nameFirst.std::basic_string<_CharT, _Traits, _Alloc>::resize [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](10u, 32)’
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:485: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:493: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/basic_string.h:504: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
movie.cpp: At global scope:
movie.cpp:240: error: variable or field ‘addLastName’ declared void
movie.cpp:240: error: ‘int Movie::addLastName’ is not a static member of ‘class Movie’
movie.cpp:240: error: ‘string’ was not declared in this scope
movie.cpp:241: error: expected ‘,’ or ‘;’ before ‘{’ token
movie.cpp:255: error: variable or field ‘addMovieName’ declared void
movie.cpp:255: error: ‘int Movie::addMovieName’ is not a static member of ‘class Movie’
movie.cpp:255: error: ‘string’ was not declared in this scope
movie.cpp:256: error: expected ‘,’ or ‘;’ before ‘{’ token
make: *** [movie.o] Error 1
You have not specified the correct namespace for string, string is a member of the std namespace. In this case you need to write std::string since I see no "using namespace std;" in your code.
replace:
string movieName,
directorLastName,
directorFirstName,
directorFullName;
with:
std::string movieName,
directorLastName,
directorFirstName,
directorFullName;
Why are all your private fields pointers? Storing plain ints and floats as fields is perfectly okay. Moreover, you don't need to "initialize" strings in your constructor. If you don't, their default constructors will be called automatically (strings will be empty). And why do you pad strings? Even if you need it when displaying, pad them there.
No one has answered the question yet, so I figured I'd just put it here myself since I figured it out. Basically, my solution was:
Use using std::string in header and implementation files.
Secondly, the declaration:
stringOne = stringTwo.resize(some_number, ' ');
...fails because resize() is a void returning function. Replacing that with two separate statements; namely:
stringOne = stringTwo;
stringOne.resize(/* blah */);
...solves the rest of the errors. Credit to #Jesse for mentioning this in the comments.