Using Boost Parameter with operator() - c++

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

Related

rapidjson error: expected unqualified-id before 'bool' when building for Linux using Bazel

I'm compiling some C++ code that compiles fine for Android and iOS but fails under Linux. I've searched around and it looks like this kind of crash shows up when the implementer does something wrong; such as, using a reserved word. However I fail to see what I am doing wrong based on the error I'm getting.
In file included from external/rapidjson_artifact/include/rapidjson/document.h:20:0,
from src/main/cc/com/mycompany/serialization/JsonSerializer.h:4,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com
/mycompany/model/common/Vector2d.h:13,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/FastVector2d.h:10,
from src/main/cc/com/mycompany/api/gestures/primitives/CalculatedElementPosition.h:7,
from src/main/cc/com/mycompany/api/gestures/primitives/PointerInteraction.h:7,
from src/main/cc/com/mycompany/api/gestures/native/NativeUserInteractionHandler.h:10,
from src/main/cc/com/mycompany/linux/api/gestures/UserInteractionHandler.h:4,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:13,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/reader.h:189:15: error: expected unqualified-id before 'bool'
bool Bool(bool) { return static_cast<Override&>(*this).Default(); }
^~~~
external/rapidjson_artifact/include/rapidjson/reader.h:189:15: error: expected ')' before 'bool'
In file included from /usr/include/GL/glx.h:30:0,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:7,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/reader.h: In member function 'void rapidjson::GenericReader<SourceEncoding, TargetEncoding, StackAllocator>::ParseTrue(InputStream&, Handler&)':
external/rapidjson_artifact/include/rapidjson/reader.h:623:26: error: expected unqualified-id before 'int'
if (!handler.Bool(true))
^
external/rapidjson_artifact/include/rapidjson/reader.h:623:26: error: expected ')' before 'int'
external/rapidjson_artifact/include/rapidjson/reader.h: In member function 'void rapidjson::GenericReader<SourceEncoding, TargetEncoding, StackAllocator>::ParseFalse(InputStream&, Handler&)':
external/rapidjson_artifact/include/rapidjson/reader.h:636:26: error: expected unqualified-id before 'int'
if (!handler.Bool(false))
^
external/rapidjson_artifact/include/rapidjson/reader.h:636:26: error: expected ')' before 'int'
external/rapidjson_artifact/include/rapidjson/document.h: In member function 'bool rapidjson::GenericValue<Encoding, Allocator>::Accept(Handler&) const':
external/rapidjson_artifact/include/rapidjson/document.h:1539:44: error: expected unqualified-id before 'int'
case kFalseType: return handler.Bool(false);
^
external/rapidjson_artifact/include/rapidjson/document.h:1539:44: error: expected ';' before 'int'
external/rapidjson_artifact/include/rapidjson/document.h:1540:44: error: expected unqualified-id before 'int'
case kTrueType: return handler.Bool(true);
^
external/rapidjson_artifact/include/rapidjson/document.h:1540:44: error: expected ';' before 'int'
In file included from src/main/cc/com/mycompany/serialization/JsonSerializer.h:4:0,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/Vector2d.h:13,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/FastVector2d.h:10,
from src/main/cc/com/mycompany/api/gestures/primitives/CalculatedElementPosition.h:7,
from src/main/cc/com/mycompany/api/gestures/primitives/PointerInteraction.h:7,
from src/main/cc/com/mycompany/api/gestures/native/NativeUserInteractionHandler.h:10,
from src/main/cc/com/mycompany/linux/api/gestures/UserInteractionHandler.h:4,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:13,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/document.h: At global scope:
external/rapidjson_artifact/include/rapidjson/document.h:2028:15: error: expected unqualified-id before 'bool'
bool Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
^~~~
external/rapidjson_artifact/include/rapidjson/document.h:2028:15: error: expected ')' before 'bool'
In file included from src/main/cc/com/mycompany/serialization/JsonSerializer.h:6:0,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/Vector2d.h:13,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/FastVector2d.h:10,
from src/main/cc/com/mycompany/api/gestures/primitives/CalculatedElementPosition.h:7,
from src/main/cc/com/mycompany/api/gestures/primitives/PointerInteraction.h:7,
from src/main/cc/com/mycompany/api/gestures/native/NativeUserInteractionHandler.h:10,
from src/main/cc/com/mycompany/linux/api/gestures/UserInteractionHandler.h:4,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:13,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/writer.h:109:15: error: expected unqualified-id before 'bool'
bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return WriteBool(b); }
^~~~
external/rapidjson_artifact/include/rapidjson/writer.h:109:15: error: expected ')' before 'bool'
All the errors point to rapidjson but I highly doubt that is the problem. It is probably something I'm doing wrong.
Can someone suggest what I should look for to find the root cause?

Compiling a quickfix program

I am trying to use the quickfix library to connect to a broker using the FIX protocol. I just built the library using the documentation they provide and use their sample code right now
#include "quickfix/FileStore.h"
#include "quickfix/FileLog.h"
#include "quickfix/SocketAcceptor.h"
#include "quickfix/Session.h"
#include "quickfix/SessionSettings.h"
#include "quickfix/Application.h"
int main( int argc, char** argv )
{
try
{
if(argc < 2) return 1;
std::string fileName = argv[1];
FIX::SessionSettings settings(fileName);
MyApplication application;
FIX::FileStoreFactory storeFactory(settings);
FIX::FileLogFactory logFactory(settings);
FIX::SocketAcceptor acceptor
(application, storeFactory, settings, logFactory /*optional*/);
acceptor.start();
// while( condition == true ) { do something; }
acceptor.stop();
return 0;
}
catch(FIX::ConfigError& e)
{
std::cout << e.what();
return 1;
}
}
However, when I try to compile it with:
g++ fix.cpp -fexceptions -finline-functions -lquickfix -lpthread -lxml2
I get a bunch of errors:
In file included from /usr/local/include/quickfix/Session.h:34:0,
from fix.cpp:6:
/usr/local/include/quickfix/DataDictionaryProvider.h:54:72: error: ‘ptr::shared_ptr’ has not been declared
void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:54:82: error: expected ‘,’ or ‘...’ before ‘<’ token
void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:55:70: error: ‘ptr::shared_ptr’ has not been declared
void addApplicationDataDictionary(const ApplVerID& applVerID, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:55:80: error: expected ‘,’ or ‘...’ before ‘<’ token
void addApplicationDataDictionary(const ApplVerID& applVerID, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:63:25: error: ‘shared_ptr’ is not a member of ‘ptr’
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_transportDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:63:25: error: ‘shared_ptr’ is not a member of ‘ptr’
/usr/local/include/quickfix/DataDictionaryProvider.h:63:55: error: template argument 2 is invalid
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_transportDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:63:55: error: template argument 4 is invalid
/usr/local/include/quickfix/DataDictionaryProvider.h:63:57: error: expected unqualified-id before ‘>’ token
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_transportDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:64:25: error: ‘shared_ptr’ is not a member of ‘ptr’
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_applicationDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:64:25: error: ‘shared_ptr’ is not a member of ‘ptr’
/usr/local/include/quickfix/DataDictionaryProvider.h:64:55: error: template argument 2 is invalid
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_applicationDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:64:55: error: template argument 4 is invalid
/usr/local/include/quickfix/DataDictionaryProvider.h:64:57: error: expected unqualified-id before ‘>’ token
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_applicationDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h: In member function ‘void FIX::DataDictionaryProvider::addTransportDataDictionary(const FIX::BeginString&, const string&)’:
/usr/local/include/quickfix/DataDictionaryProvider.h:58:45: error: ‘shared_ptr’ is not a member of ‘ptr’
{ addTransportDataDictionary(beginString, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
/usr/local/include/quickfix/DataDictionaryProvider.h:58:75: error: expected primary-expression before ‘>’ token
{ addTransportDataDictionary(beginString, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
/usr/local/include/quickfix/DataDictionaryProvider.h: In member function ‘void FIX::DataDictionaryProvider::addApplicationDataDictionary(const FIX::ApplVerID&, const string&)’:
/usr/local/include/quickfix/DataDictionaryProvider.h:60:45: error: ‘shared_ptr’ is not a member of ‘ptr’
{ addApplicationDataDictionary(applVerID, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
/usr/local/include/quickfix/DataDictionaryProvider.h:60:75: error: expected primary-expression before ‘>’ token
{ addApplicationDataDictionary(applVerID, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
fix.cpp: In function ‘int main(int, char**)’:
fix.cpp:19:5: error: ‘MyApplication’ was not declared in this scope
MyApplication application;
^
fix.cpp:19:19: error: expected ‘;’ before ‘application’
MyApplication application;
^
fix.cpp:23:8: error: ‘application’ was not declared in this scope
(application, storeFactory, settings, logFactory /*optional*/);
^
root#luis:/home/luis/tradingbot/bot4# In file included from /usr/local/include/quickfix/Session.h:34:0,
In: command not found
root#luis:/home/luis/tradingbot/bot4# from fix.cpp:6:
from: can't read /var/mail/fix.cpp:6:
root#luis:/home/luis/tradingbot/bot4# /usr/local/include/quickfix/DataDictionaryProvider.h:54:72: error: ‘ptr::shared_ptr’ has not been declared
bash: /usr/local/include/quickfix/DataDictionaryProvider.h:54:72:: No such file or directory
root#luis:/home/luis/tradingbot/bot4# void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
bash: syntax error near unexpected token `('
root#luis:/home/luis/tradingbot/bot4# ^
^: command not found
root#luis:/home/luis/tradingbot/bot4# /usr/local/include/quickfix/DataDictionaryProvider.h:54:82: error: expected ‘,’ or ‘...’ before ‘<’ token
bash: ’: No such file or directory
root#luis:/home/luis/tradingbot/bot4# void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
bash: syntax error near unexpected token `('
root#luis:/home/luis/tradingbot/bot4# ^
^: command not found
root#luis:/home/luis/tradingbot/bot4# /usr/local/include/quickfix/DataDictionaryProvider.h:55:70: error: ‘ptr::shared_ptr’ has not been declared
bash: /usr/local/include/quickfix/DataDictionaryProvider.h:55:70:: No such file or directory
What am I doing wrong?
You need to provide an implementation of the MyApplication class and compile with the appropriate C++11 flags.
Your MyApplication object typically needs to derive from the FIX::Application class which is a pure virtual class and will require you to implement a series of methods such as onLogon(...) and toApp(...)
If you want to just get your code to compile as a first step you can try using the FIX::NullApplication class (defined in quickfix/Application.h) as your starting application object.
The quickfix library must be compiled with this pre-processor directive HAVE_STD_UNIQUE_PTR
Your application must provide an implementation for the MyApplication class and that implementation must inherit from FIX::Application

CppCMS build constructor & declaration

From http://cppcms.com/wikipp/en/page/cppcms_1x_forms,
According to this,
A declaration introduces one or more names into a program.....
Therefore, classes, structures, enumerated types, and other
user-defined types can be declared for each compilation unit
AFAIK, constructor should be in myapp.cpp, while declaration should be in content.h. So I put
There are 5 fields on the form. In CppCMS, the form built using 3 codes (the 4th codes are restriction for the fields)
1st codes:
name.message("Your Name");
sex.message("Sex");
marital.message("Marital Status");
age.message("Your Age");
submit.value("Send");
2nd codes:
add(name);
add(sex);
add(marital);
add(age);
add(submit);
3rd codes:
sex.add("Male","male");
sex.add("Female","female");
marital.add("Single","single");
marital.add("Married","married");
marital.add("Divorced","divorced");
4th codes, are restriction for the fields:
name.non_empty();
age.range(0,120);
I'm quite confused which one should be declaration
------------------added
I've tried add all above codes in myapp.cpp like below:
class myapp : public cppcms::application {
public:
myapp(cppcms::service &srv) : cppcms::application(srv)
{
dispatcher().assign("",&myapp::info_form,this);
mapper().assign("");
}
void info_form()
{
name.message("Your Name");
sex.message("Sex");
marital.message("Marital Status");
age.message("Your Age");
submit.value("Send");
add(name);
add(sex);
add(marital);
add(age);
add(submit);
sex.add("Male","male");
sex.add("Female","female");
marital.add("Single","single");
marital.add("Married","married");
marital.add("Divorced","divorced");
name.non_empty();
age.range(0,120);
}
};
But it still giving error:
myapp.cpp: In member function ‘void myapp::info_form()’:
myapp.cpp:20:9: error: ‘name’ was not declared in this scope
myapp.cpp:21:9: error: ‘sex’ was not declared in this scope
myapp.cpp:22:9: error: ‘marital’ was not declared in this scope
myapp.cpp:23:9: error: ‘age’ was not declared in this scope
myapp.cpp:24:9: error: ‘submit’ was not declared in this scope
myapp.cpp:24:9: note: suggested alternative:
/usr/local/include/cppcms/form.h:1574:20: note: ‘cppcms::widgets::submit’
myapp.cpp: At global scope:
myapp.cpp:43:37: error: no ‘void myapp::main(std::string)’ member function declared in class ‘myapp’
my_skin.tmpl:4:2: error: expected unqualified-id before ‘if’
my_skin.tmpl:8:3: error: expected unqualified-id before ‘else’
my_skin.tmpl:12:8: error: expected constructor, destructor, or type conversion before ‘<<’ token
my_skin.tmpl:13:2: error: expected unqualified-id before ‘{’ token

Generating functions with macros in C++

I have the following macro that is intended to generate functions in the current scope or namespace:
#define MAKE_FUNC(FNAME) \
template <typename T> \
T ##FNAME## (const T& t) \
{\
return t; \
}
MAKE_FUNC(foo)
MAKE_FUNC(boo)
int main()
{
foo(1);
boo(2);
}
The following is the error message when compiling the above code:
prog.cpp:8:1: error: pasting "Tfoo" and "(" does not give a valid preprocessing token
prog.cpp:9:1: error: pasting "Tboo" and "(" does not give a valid preprocessing token
prog.cpp:8: error: ISO C++ forbids declaration of ‘Tfoo’ with no type
prog.cpp:9: error: ISO C++ forbids declaration of ‘Tboo’ with no type
prog.cpp: In function ‘int main()’:
prog.cpp:13: error: ‘foo’ was not declared in this scope
prog.cpp:14: error: ‘boo’ was not declared in this scope
http://ideone.com/paiu1
It seems like the concatenation has fail, is there anyway around this problem?
You want
T FNAME (const T& t) \
## concatenates, you don't want to concatenate.

GCC 4.1.2 compilation error for stl_vector.h

I am getting the following error for STL files on GCC 4.1.2. And the same code works properly without any compilation errors on GCC 3.4.6.
I am including some built-in headers in my code that in turn include these STL files. Hence, I cannot modify the header files.
I compile it using the following:
gcc -I/grid/0/gs/java/jdk64/current/include -I/grid/0/gs/java/jdk64/current/include/linux -I/grid/0/tmp/direct/include/ydmg/ ydmg.cpp -I/grid/0/tmp/direct/include/ -o libydmg.so
Do I need to include some other parameter while compiling?
Could the compiler version be the cause of this problem?
The error is as follows:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:157: error: expected type-specifier
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:157: error: expected `>'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:157: error: expected unqualified-id before â>â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:932: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:932: error: âbool ytl::std::operator==(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:932: error: âbool ytl::std::operator==(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator==(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:933: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:933: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:934: error: âequalâ is not a member of âytl::stdâ
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:949: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:949: error: âbool ytl::std::operator<(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:949: error: âbool ytl::std::operator<(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator<(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:950: error: âlexicographical_compareâ is not a member of âytl::stdâ
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:950: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:951: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:956: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:956: error: âbool ytl::std::operator!=(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:956: error: âbool ytl::std::operator!=(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator!=(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:957: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:957: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:962: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:962: error: âbool ytl::std::operator>(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:962: error: âbool ytl::std::operator>(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator>(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:963: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:963: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:968: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:968: error: âbool ytl::std::operator<=(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:968: error: âbool ytl::std::operator<=(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator<=(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:969: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:969: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:974: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:974: error: âbool ytl::std::operator>=(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:974: error: âbool ytl::std::operator>=(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator>=(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:975: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:975: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: variable or field âswapâ declared void
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: âytl::std::swapâ declared as an âinlineâ variable
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: template declaration of âint ytl::std::swapâ
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: âvectorâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â,â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â>â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: âvectorâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â,â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â>â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:110: error: expected template-name before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:110: error: expected `{' before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:110: error: expected unqualified-id before â<â token
Any help would be appreciated.
Here is the C++ code.
I am calling the methods from ydmg and yut libraries using JNI.
This code is working perfectly fine on gcc 3.4.6. Its gives errors on gcc 4.1.2.
#include <stdio.h>
#include "ydmg/bd.h"
#include <jni.h>
#include "yut/string.h"
extern "C" int getAge();
JNIEXPORT jint JNICALL Java_ydmgBd_getAge(JNIEnv *, jobject)
{
ydmgBd bdObject;
yutString s = bdObject.getKeys();
printf("\ngetKeys() returns the key as : %s",s.c_str());
yutHash user;
yutString value = "abc";
yutString key ="login";
user.set(key,value);
ydmgBd bd1(user);
bool val = bd1.save(user);
if(val){
printf("\ntrue");
}else {
printf("\nfalse");
}
int age = bd1.getAge();
printf("\nAge : %d ",age);
printf("\nhi");
return 1;
}
int main(){
return 0;
}
If you compile cpp code with gcc and not with g++, you must link with -lstdc++, so that option is definitely missing.
However, the problem already occurs at the parsing step, so my suggestion is to check the namespaces... e.g. have a look at the error output:
...
ytl::std::operator!=
...
std should not be in your personal ytl namespace. You are doing something wrong with your includes.
One of your header files is almost certainly including:
#include <vector>
Before that line, add:
#undef max
And I believe your compiles will start working. This is happening b/c you are also using the C std library, which for some functions uses macros, and in this case, causes the preprocessor to freak out. I've seen this same error on Linux, and undefining that symbol was all i needed to get things compiling again.