C++ Compilation Issue, template argument 2 is invalid - c++

I have a rather large code base. It is all here https://github.com/mpkuse/nap/tree/master-desktop/src
It is actually a ros package which has to be compiled with catkin_make
which is an layer over cmake.
My code base compiles fine on my ubuntu-desktop (gcc version 5.4.0).
However, as I move it to Nvidia-TX2, I get very long error list. A snippet of it as below. The class Node is defined in Node.h and included in other classes.
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:73:68: error: template argument 2 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:73:68: error: template argument 1 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:73:68: error: template argument 2 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:73:56: error: invalid use of template-name ‘std::vector’ without an argument list
LocalBundle( const nap::NapMsg::ConstPtr& msg, const vector<Node*>& global_nodes, const PinholeCamera& camera );
^
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:73:62: error: expected ‘,’ or ‘...’ before ‘<’ token
LocalBundle( const nap::NapMsg::ConstPtr& msg, const vector<Node*>& global_nodes, const PinholeCamera& camera );
^
In file included from /home/nvidia/catkin_ws/src/nap/src/DataManager.h:82:0,
from /home/nvidia/catkin_ws/src/nap/src/DataManager_rviz_visualization.cpp:1:
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:127:45: error: template argument 1 is invalid
int find_indexof_node( const vector<Node*>& global_nodes, ros::Time stamp );
^
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:127:45: error: template argument 2 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:127:45: error: template argument 1 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:127:45: error: template argument 2 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:127:45: error: template argument 1 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:127:45: error: template argument 2 is invalid
/home/nvidia/catkin_ws/src/nap/src/LocalBundle.h:127:45: error: template argument 1 is invalid
What is going on here? Any suggestions?
I tried to isolate the problem. Here is what I did, I completely removed the classes LocalBundle and Corvus. They were being used in DataManager_core.cpp/place_recog_callback(). Also removed corresponding cmake entries. Now the code can compile.
I tried adding a dummy class Suse
// Suse.h
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
class Suse
{
public:
Suse();
void sayHi();
};
;
// Suse.cpp
#include "Suse.h"
Suse::Suse()
{
}
void Suse::sayHi()
{
cout << "Hi from Suse\n";
}
Then tried to use this class in exact same place (ie. in place_recog_callback()) like:
Suse sy = Suse();
sy.sayHi();
Also added Suse.cpp in cmake compile list and included Suse.h in DataManager.h.
With this it compiles successfully.
However, as I include opencv in Suse.h something like:
// //opencv
#include <opencv2/core/core.hpp>
using namespace cv;
I get a long error message, first few lines of which look similar to original error.
[ 81%] Building CXX object nap/CMakeFiles/pose_graph_opt_node.dir/src/DataManager_core.cpp.o
[ 83%] Building CXX object nap/CMakeFiles/pose_graph_opt_node.dir/src/DataManager_rviz_visualization.cpp.o
[ 85%] Building CXX object nap/CMakeFiles/pose_graph_opt_node.dir/src/pose_graph_opt_node.cpp.o
[ 87%] Building CXX object nap/CMakeFiles/pose_graph_opt_node.dir/src/DataManager_utils.cpp.o
[ 88%] Building CXX object nap/CMakeFiles/pose_graph_opt_node.dir/src/Suse.cpp.o
In file included from /home/nvidia/catkin_ws/src/nap/src/DataManager_core.cpp:1:0:
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:171:21: error: template argument 1 is invalid
const vector<Node*>& getNodesRef() { return nNodes; }
^
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:171:21: error: template argument 2 is invalid
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:185:15: error: template argument 1 is invalid
vector<Node*> nNodes; //list of notes
^
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:185:15: error: template argument 2 is invalid
In file included from /home/nvidia/catkin_ws/src/nap/src/DataManager_rviz_visualization.cpp:1:0:
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:171:21: error: template argument 1 is invalid
const vector<Node*>& getNodesRef() { return nNodes; }
^
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:171:21: error: template argument 2 is invalid
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:185:15: error: template argument 1 is invalid
vector<Node*> nNodes; //list of notes
^
/home/nvidia/catkin_ws/src/nap/src/DataManager.h:185:15: error: template argument 2 is invalid

Related

Using Boost Parameter with operator()

I would like to use Boost Parameter together with an overloaded call operator (operator()):
#include <string>
#include <boost/parameter/keyword.hpp>
#include <boost/parameter/preprocessor.hpp>
struct add_argument_tag
{
struct name_;
struct descr_;
};
static inline boost::parameter::keyword<add_argument_tag::name_>& name = boost::parameter::keyword<add_argument_tag::name_>::get();
static inline boost::parameter::keyword<add_argument_tag::descr_>& descr = boost::parameter::keyword<add_argument_tag::descr_>::get();
struct config
{
BOOST_PARAMETER_MEMBER_FUNCTION(
(config),
operator(),
add_argument_tag,
(required (name_, (std::string const&)))
(optional
(descr_, (std::string const&), "")
)
)
{
return *this;
}
};
int main()
{
config my_config;
my_config
("foo")
("bar", descr = "some description");
}
Unfortunately it doesn't work:
In file included from /usr/include/boost/mpl/aux_/integral_wrapper.hpp:22,
from /usr/include/boost/mpl/int.hpp:20,
from /usr/include/boost/mpl/lambda_fwd.hpp:23,
from /usr/include/boost/mpl/aux_/na_spec.hpp:18,
from /usr/include/boost/mpl/identity.hpp:17,
from /usr/include/boost/parameter/aux_/unwrap_cv_reference.hpp:11,
from /usr/include/boost/parameter/keyword.hpp:9,
from /.../main.cpp:2:
/.../main.cpp:18:18: error: expected unqualified-id before ')' token
operator(),
^
/.../main.cpp:18:18: error: expected unqualified-id before ')' token
operator(),
^
/.../main.cpp:18:18: error: expected unqualified-id before ')' token
operator(),
^
/.../main.cpp:16:5: error: expected nested-name-specifier before 'boost_param_result_24operator'
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /.../main.cpp:3:
/.../main.cpp:16:5: error: expected initializer before '<' token
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/boost/mpl/aux_/integral_wrapper.hpp:22,
from /usr/include/boost/mpl/int.hpp:20,
from /usr/include/boost/mpl/lambda_fwd.hpp:23,
from /usr/include/boost/mpl/aux_/na_spec.hpp:18,
from /usr/include/boost/mpl/identity.hpp:17,
from /usr/include/boost/parameter/aux_/unwrap_cv_reference.hpp:11,
from /usr/include/boost/parameter/keyword.hpp:9,
from /.../main.cpp:2:
/.../main.cpp:16:5: error: expected nested-name-specifier before 'boost_param_result_24operator'
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /.../main.cpp:3:
/.../main.cpp:16:5: error: expected initializer before '<' token
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.../main.cpp:16:5: error: 'boost_param_default_24operator' declared as function returning a function
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.../main.cpp:16:5: error: 'boost_param_default_24operator' declared as function returning a function
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/boost/mpl/aux_/integral_wrapper.hpp:22,
from /usr/include/boost/mpl/int.hpp:20,
from /usr/include/boost/mpl/lambda_fwd.hpp:23,
from /usr/include/boost/mpl/aux_/na_spec.hpp:18,
from /usr/include/boost/mpl/identity.hpp:17,
from /usr/include/boost/parameter/aux_/unwrap_cv_reference.hpp:11,
from /usr/include/boost/parameter/keyword.hpp:9,
from /.../main.cpp:2:
/.../main.cpp:16:5: error: expected nested-name-specifier before 'boost_param_result_24operator'
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /.../main.cpp:3:
/.../main.cpp:16:5: error: expected initializer before '<' token
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.../main.cpp:16:5: error: 'boost_param_default_24operator' declared as function returning a function
BOOST_PARAMETER_MEMBER_FUNCTION(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.../main.cpp: In function 'int main()':
/.../main.cpp:34:15: error: no match for call to '(config) (const char [4])'
("foo")
^
make[3]: *** [CMakeFiles/BoostParameterProblem.dir/build.make:63: CMakeFiles/BoostParameterProblem.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/BoostParameterProblem.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/BoostParameterProblem.dir/rule] Error 2
make: *** [Makefile:118: BoostParameterProblem] Error 2
I can easily work around this problem by having a properly named function instead of operator(), but I would really like to use operator() here... :)
I'm guessing the reason is how Boost Parameter uses macros and meta-programming to construct helper functions etc., and that using operator overloading functions are simply not possible.
Is there anyone that have made something like this work? Is it even possible?
Boost Parameter does do a lot of string concatenation stuff, thus your operator() will be concatenated to an invalid name.
One way to workaround is to delegate the operator() to its implementation. Change your macro part to define a normal function, then perfect forwarding all arguments and the final result:
struct config
{
BOOST_PARAMETER_MEMBER_FUNCTION(
(config),
myope,
add_argument_tag,
(required (name_, (std::string const&)))
(optional
(descr_, (std::string const&), "")
)
)
{
std::cout << name_ << " " << descr_ << "\n";
return *this;
}
template<class... Args>
decltype(auto) operator() (Args&& ...args) {
return myope(std::forward<Args>(args)...);
}
};
Live Demo

opencv - cmake mingw32-make error [duplicate]

opencv installation using mingw32-make command in windows 10 platform, then likely end up in getting the below error.
Windows version : 10
OpenCv:3.2.0
Please suggest me in installing.
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In constructor 'testing::internal::Mutex::Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8829:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
critical_section_(new CRITICAL_SECTION) {
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8830:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In destructor 'testing::internal::Mutex::~Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8840:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
::DeleteCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Lock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8848:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
::EnterCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Unlock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8858:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
::LeaveCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8879:27: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
critical_section_ = new CRITICAL_SECTION;
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8880:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
modules\ts\CMakeFiles\opencv_ts.dir\build.make:237: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj' failed
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj] Error 1
CMakeFiles\Makefile2:5379: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/all' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
I also faced the same problem while trying to build OpenCV 3.2.0 using mingw32 on Windows10. I searched a bit to find a fix on Github for similar problem. It said the problem was:
MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two separate (equivalent) structs, instead of using typedef
So, you have to add another typedef GTEST_CRITICAL_SECTION for _CRITICAL_SECTION and _RTL_CRITICAL_SECTION and use this typedef for either case.
Here is what to do :
Edit "ts_gtest.h" which is inside "opencv\sources\modules\ts\include\opencv2\ts\"
Replace this line (probably line 723)
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
struct _RTL_CRITICAL_SECTION;
with
#if GTEST_OS_WINDOWS_MINGW
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#else
// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif
Replace this line (probably on line 3060 before your edit - line number would have changed as you modified first part)
_RTL_CRITICAL_SECTION* critical_section_;
with
GTEST_CRITICAL_SECTION* critical_section_;
These two changes should fix your above error.
It was fixed by using TDM-gcc mingw compiler.

Is this a bug in the boost library

I'm compiling a project with autotools and am using g++ in version gcc version 5.3.1 and boost version 1_63. After aclocal, autoconf, autoheader, automake --add-missing, I ran configure with some options, which succedded and build make a Makefile. Running make fails and gives me the error (excerpt):
In file included from /usr/local/include/boost/ratio/ratio.hpp:46:0,
from /usr/local/include/boost/chrono/duration.hpp:41,
from /usr/local/include/boost/chrono/time_point.hpp:33,
from /usr/local/include/boost/thread/lock_types.hpp:22,
from /usr/local/include/boost/thread/pthread/mutex.hpp:16,
from /usr/local/include/boost/thread/mutex.hpp:16,
from src/cosupport-initializer/cpp/BasicInitializer.cpp:39:
/usr/local/include/boost/integer_traits.hpp:83:46: error: 'CHAR_MIN' was not declared in this scope
public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:83:56: error: 'CHAR_MAX' was not declared in this scope
public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:83:64: error: template argument 2 is invalid
public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:83:64: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:89:53: error: 'SCHAR_MIN' was not declared in this scope
public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:89:64: error: 'SCHAR_MAX' was not declared in this scope
public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:89:73: error: template argument 2 is invalid
public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:89:73: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:95:58: error: 'UCHAR_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:95:67: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
^
/usr/local/include/boost/integer_traits.hpp:131:47: error: 'SHRT_MIN' was not declared in this scope
public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:131:57: error: 'SHRT_MAX' was not declared in this scope
public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:131:65: error: template argument 2 is invalid
public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:131:65: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:137:59: error: 'USHRT_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned short, 0, USHRT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:137:68: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned short, 0, USHRT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:143:45: error: 'INT_MIN' was not declared in this scope
public detail::integer_traits_base<int, INT_MIN, INT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:143:54: error: 'INT_MAX' was not declared in this scope
public detail::integer_traits_base<int, INT_MIN, INT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:143:61: error: template argument 2 is invalid
public detail::integer_traits_base<int, INT_MIN, INT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:143:61: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:149:57: error: 'UINT_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned int, 0, UINT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:149:65: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned int, 0, UINT_MAX>
^
/usr/local/include/boost/integer_traits.hpp:155:46: error: 'LONG_MIN' was not declared in this scope
public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
^
/usr/local/include/boost/integer_traits.hpp:155:56: error: 'LONG_MAX' was not declared in this scope
public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
^
/usr/local/include/boost/integer_traits.hpp:155:64: error: template argument 2 is invalid
public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
^
/usr/local/include/boost/integer_traits.hpp:155:64: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:161:58: error: 'ULONG_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
^
/usr/local/include/boost/integer_traits.hpp:161:67: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
This means e.g. that in /usr/local/include/boost/integer_traits.hpp on line 83, the constructor initialization fails:
template<>
class integer_traits<char>
: public std::numeric_limits<char>,
public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
{ };
This means in the file /usr/local/include/boost/integer_traits.hpp and headers included in it, there's no definition of CHAR_MIN. So this is a bug in boost? Or what am I missing here?
UPDATE
The relevant code excerpts. Before the move:
#include <CoSupport/compatibility-glue/nullptr.h>
#include <CoSupport/Initializer/BasicInitializer.hpp>
#include <boost/thread/mutex.hpp>
#include <cassert>
namespace CoSupport {
...
}
After the move:
#include <boost/thread/mutex.hpp>
#include <CoSupport/compatibility-glue/nullptr.h>
#include <CoSupport/Initializer/BasicInitializer.hpp>
#include <cassert>
namespace CoSupport {
...
}
This means in the file /usr/local/include/boost/integer_traits.hpp and headers included in it, there's no definition of CHAR_MIN
Which is as it should be - CHAR_MIN is defined in <climits>.
So this is a bug in boost? Or what am I missing here?
With 99% certainty, this is not a bug in boost. You probably have some include files of your own, in your project's include directories, masking climits or limits.h, or possibly another file which interger_traits.hpp includes and itself includes climits or limits.h.

How to compile a program from .cpp files and a makefile

I recently downloaded a program. A patient specific survival prediction CLI, http://pssp.srv.ualberta.ca/
The readme included states:
"1 Compilation
The code should compile on Linux without any modification. To compile, just type ’make’. There should
be 2 executables after compilation, mtlr train and mtlr test."
I download an extracted the folder to my location, when I go into the directory and type make I get:
x#x-laptop:/pssp_source$ make
g++ -c -O3 DenseVector.cpp -o DenseVector.o
In file included from DenseVector.cpp:1:0:
DenseVector.h:9:2: error: ‘size_t’ does not name a type
size_t m_dim;
^
DenseVector.h:18:21: error: expected ‘)’ before ‘n’
DenseVector(size_t n);
^
DenseVector.h:26:33: error: ‘size_t’ does not name a type
double const& operator[](const size_t i) const
^
DenseVector.h:26:40: error: ISO C++ forbids declaration of ‘i’ with no type [-fpermissive]
double const& operator[](const size_t i) const
^
DenseVector.h:31:27: error: ‘size_t’ does not name a type
double& operator[](const size_t i)
^
DenseVector.h:31:34: error: ISO C++ forbids declaration of ‘i’ with no type [-fpermissive]
double& operator[](const size_t i)
^
DenseVector.h:38:2: error: ‘size_t’ does not name a type
size_t dim() const
^
DenseVector.h: In member function ‘void DenseVector::push_back(double)’:
DenseVector.h:23:3: error: ‘m_dim’ was not declared in this scope
m_dim++;
^
DenseVector.cpp: At global scope:
DenseVector.cpp:6:1: error: prototype for ‘DenseVector::DenseVector(size_t)’ does not match any in class ‘DenseVector’
DenseVector::DenseVector(size_t n): m_dim(n)
^
In file included from DenseVector.cpp:1:0:
DenseVector.h:5:7: error: candidates are: DenseVector::DenseVector(const DenseVector&)
class DenseVector
^
DenseVector.h:12:2: error: DenseVector::DenseVector()
DenseVector(void);
^
DenseVector.cpp: In constructor ‘DenseVector::DenseVector()’:
DenseVector.cpp:16:2: error: class ‘DenseVector’ does not have any field named ‘m_dim’
:m_dim(0)
^
DenseVector.cpp: In member function ‘void DenseVector::clear()’:
DenseVector.cpp:27:22: error: ‘m_dim’ was not declared in this scope
for (size_t i=0; i<m_dim; i++)
^
In file included from /usr/include/c++/4.8/cassert:43:0,
from DenseVector.cpp:3:
DenseVector.cpp: In function ‘double sprod_nn(const DenseVector&, const DenseVector&)’:
DenseVector.cpp:37:11: error: ‘const class DenseVector’ has no member named ‘dim’
assert(a.dim() == b.dim());
^
DenseVector.cpp:37:22: error: ‘const class DenseVector’ has no member named ‘dim’
assert(a.dim() == b.dim());
^
DenseVector.cpp:38:15: error: ‘const class DenseVector’ has no member named ‘dim’
size_t n = a.dim();
^
In file included from /usr/include/c++/4.8/cassert:43:0,
from DenseVector.cpp:3:
DenseVector.cpp: In function ‘void multadd_nn(DenseVector&, const DenseVector&, double)’:
DenseVector.cpp:49:11: error: ‘class DenseVector’ has no member named ‘dim’
assert(w.dim()==a.dim());
^
DenseVector.cpp:49:20: error: ‘const class DenseVector’ has no member named ‘dim’
assert(w.dim()==a.dim());
^
DenseVector.cpp:50:15: error: ‘class DenseVector’ has no member named ‘dim’
size_t n = w.dim();
^
DenseVector.cpp: In function ‘void smult_n(DenseVector&, double)’:
DenseVector.cpp:62:15: error: ‘class DenseVector’ has no member named ‘dim’
size_t n = w.dim();
^
make: *** [DenseVector.o] Error 1
The contents of the folder look like:
x#x-laptop:/pssp_source$ ls
common.cpp data_type_api.h DenseVector.h Main.cpp Makefile Sparm.cpp Sparm.o SparseVector.h test_model.mltr Util.h
common.h DenseVector.cpp example_data Main.o readme.pdf Sparm.h SparseVector.cpp Test.cpp test_model.mlty
I looked up the basic packages needed for compiling c++ code, as well as basics on how to run it and none have gotten me past this issue. It looks as if it has a problem with size_t not having a type.
The start of DenseVector.cpp is :
#include "DenseVector.h"
#include <cassert>
#include <iostream>
DenseVector::DenseVector(size_t n): m_dim(n)
{
m_dvector.reserve(n);
for (size_t i=0; i<n; i++)
{
m_dvector.push_back(0);
}
}
I have never compiled code like this before, so I am probably missing something obvious. If its needed I am running ubuntu 14.04, g++ version is
4.8.4.
Thanks
It sounds like the README lied. Probably it happened to work with a different version of the standard library.
Try adding
#include <stddef.h>
near the top of DenseVector.h.
Open the file DenseVector.h in the root directory of the program and modify it, inserting
#pragma once
#include <vector>
#include <cstddef> // <--- Add this line to the file
class DenseVector
{
protected:
// ...
Save it and try again!
I don't think you are using the correct version of C; I think you need C11. Instead of using the -03 flag, use -11 or -std=c11. Then recompile it.

Compiler errors with Poco::Logger on Linux - function declaration treated as macro

I've been trying to build executable that uses Poco::Application class as its basis, but compiler is giving following errors pointing to Poco code.
In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:152:59: error: macro "log" passed 3 arguments, but takes just 1
In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:427:58: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:428:86: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:601:72: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:100: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:621:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:627:42: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:633:33: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:639:45: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:645:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:651:42: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:657:32: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:663:44: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:669:31: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:675:43: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:681:36: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:687:48: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:693:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:699:42: error: macro "log" passed 4 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:705:30: error: macro "log" passed 2 arguments, but takes just 1
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:711:42: error: macro "log" passed 4 arguments, but takes just 1
In file included from /home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:44:0,
from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48,
from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Channel.h:75:15: error: expected unqualified-id before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Channel.h:75:15: error: expected ‘)’ before ‘__extension__’
In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:145:7: error: expected unqualified-id before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:145:7: error: expected ‘)’ before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:149:7: error: expected unqualified-id before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:149:7: error: expected ‘)’ before ‘__extension__’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:152:7: error: variable or field ‘log’ declared void
In file included from /home/mie/Poco/poco-1.4.6p4/Util/include/Poco/Util/Application.h:48:0,
from /home/mie/myproject/src/main.cpp:15:
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:427:7: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:428:7: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:601:21: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:601:21: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:603:2: error: expected primary-expression before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:603:2: error: expected ‘}’ before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:13: error: ‘Logger’ has not been declared
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:21: error: variable or field ‘log’ declared void
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:610:21: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:612:2: error: expected primary-expression before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:612:2: error: expected ‘}’ before ‘if’
/home/mie/Poco/poco-1.4.6p4/Foundation/include/Poco/Logger.h:616:1: error: expected declaration before ‘}’ token
make[2]: *** [CMakeFiles/app.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/app.dir/all] Error 2
Here I'm including latest version of Poco (1.4.6p4) from my home directory, but I've tried 1.4.2p1-2.el6 from CentOS 6.5 repositories with same result. On OS X I didn't have this problem (I believe the library version there was 1.4.2).
If I look what's in Poco/Logger.h on line 152, where the first error points to, it seems to be a function declaration rather than macro as the error states.
//
// Logger.h
//
// $Id: //poco/1.4/Foundation/include/Poco/Logger.h#5 $
//
// Library: Foundation
// Package: Logging
// Module: Logger
//
// Definition of the Logger class.
... (comment continues)
#ifndef Foundation_Logger_INCLUDED
#define Foundation_Logger_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/Channel.h"
#include "Poco/Message.h"
#include "Poco/Format.h"
#include <map>
#include <vector>
#include <cstddef>
namespace Poco {
class Exception;
class Foundation_API Logger: public Channel
/// Logger is a special Channel that acts as the main
/// entry point into the logging framework.
... (comment continues)
{
public:
... (other declarations)
void log(const Exception& exc, const char* file, int line); <= line 152
/// Logs the given exception with priority PRIO_ERROR.
///
/// File must be a static string, such as the value of
/// the __FILE__ macro. The string is not copied
/// internally for performance reasons.
... (and so on)
So why is my compiler treating this function declaration as a reference to macro?
As a side note, there was a weird error earlier in the build process that I just commented out. Maybe these are related. I tried to use fmod function from tgmath.h in an inline function and compiler gave this error six times for one line of code:
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
/.../header.h:418: error: ”void*” is not a pointer-to-object type
And this is the code in a header file that triggered the error:
inline void ProgressCounter::createTimeString(
std::string& timeString,
const long long& elapsedTotalS)
{
short elapsedH = (short)elapsedTotalS / 3600;
//short elapsedS = 0;
short elapsedS = fmod(elapsedTotalS, 60); <= error here
short elapsedM = 0;
//short elapsedM = fmod(elapsedTotalS - elapsedS, 3600) / 60;
char timeCString[10];
snprintf(timeCString, 10, "%02u:%02u:%02u", elapsedH, elapsedM, elapsedS);
timeString = timeCString;
}
The header tgmath.h is included and the code compiled without problems on OS X. I don't understand where the void* in the error refers to.
I've been using GCC 4.4.7 on CentOS 6.5 and GCC 4.4.6.3-1ubuntu5 on Ubuntu 12.04.
<math.h> and <tgmath.h> define a lot of macros, including a log macro which conflicts with anything with the same name.
In C++ code, you should rather include <cmath> or <ctgmath> where the type-generic macros are replaced by C++ function overloads.
PS: at least for gcc, <ctgmath> seems to require C++11 support, so you'll have to add "-std=c++0x" or "-std=c++11" to the compilation options.
Try including your POCO libraries first and see if that helps. I had a problem just a few days ago in VS 2010 on Windows in which a lot of Windows APIs suddenly became undefined when I had #included the POCO libraries last. Moving them ahead of other #includes fixed the problem.
Having fixed it, I did not do deep analysis of exactly what item had caused the problem.