strange errors while using Wt::Http:Response
Added by Shayan Javani almost 9 years ago
I get strange errors below when I compile the codes attached:
In file included from server.cpp:2:0:
serveFactorial.cpp: In member function 'virtual void serveFactorial::handleRequest(const Wt::Http::Request&, Wt::Http::Response&)':
serveFactorial.cpp:37:11: error: invalid use of incomplete type 'class Wt::Http::Response'
response.setMimeType("text/plain");
^
In file included from /usr/include/Wt/WObject:11:0,
from /usr/include/Wt/WApplication:25,
from /usr/include/Wt/WServer:10,
from server.cpp:1:
/usr/include/Wt/WGlobal:275:11: note: forward declaration of 'class Wt::Http::Response'
class Response;
^
In file included from server.cpp:2:0:
serveFactorial.cpp:41:40: error: 'stod' was not declared in this scope
double N=stod(request.queryString());
^
serveFactorial.cpp:45:15: error: invalid use of incomplete type 'class Wt::Http::Response'
response.out()<<--1;
^
In file included from /usr/include/Wt/WObject:11:0,
from /usr/include/Wt/WApplication:25,
from /usr/include/Wt/WServer:10,
from server.cpp:1:
/usr/include/Wt/WGlobal:275:11: note: forward declaration of 'class Wt::Http::Response'
class Response;
^
In file included from server.cpp:2:0:
serveFactorial.cpp:49:15: error: invalid use of incomplete type 'class Wt::Http::Response'
response.out()<<factorial(N);
^
In file included from /usr/include/Wt/WObject:11:0,
from /usr/include/Wt/WApplication:25,
from /usr/include/Wt/WServer:10,
from server.cpp:1:
/usr/include/Wt/WGlobal:275:11: note: forward declaration of 'class Wt::Http::Response'
class Response;
^
In file included from server.cpp:2:0:
serveFactorial.cpp:55:13: error: invalid use of incomplete type 'class Wt::Http::Response'
response.out() << false;
^
In file included from /usr/include/Wt/WObject:11:0,
from /usr/include/Wt/WApplication:25,
from /usr/include/Wt/WServer:10,
from server.cpp:1:
/usr/include/Wt/WGlobal:275:11: note: forward declaration of 'class Wt::Http::Response'
class Response;
^
I have no idea what these errors mean. Can anyone help?
Thanks
P.S.
I know what the error about stod means, but its weird that I'm getting this error. I've included cstdlib and I'm using namespace std.
| server.cpp (274 Bytes) server.cpp | |||
| serveFactorial.cpp (738 Bytes) serveFactorial.cpp |
Replies (4)
RE: strange errors while using Wt::Http:Response - Added by Wim Dumon almost 9 years ago
Hey,
'invalid use of incomplete type XXX' means that the compiler knows that XXX is a type, but that it does not know the details about it. C has a mechanism called 'forward declaration' that causes this. A forward declaration is enough to declare pointers and references to the type, but not much more than that.
In Wt, we will use forward declarations wherever possible (this has a compile time advantage). As user of the library, you need to include the header file that contains the full declaration when you start using the type. For Wt::Http::Response, you'll need to #include
'stod' is not a function that I know; do you mean strtod()?
Wim.
RE: strange errors while using Wt::Http:Response - Added by Shayan Javani almost 9 years ago
I got rid of the errors, thanks.
But now I'm getting something new!
This is my new code:
void serveFactorial::handleRequest(const Http::Request& request, Http::Response& response){
response.setMimeType("text/plain");
try{
double N=strtod(request.queryString().c_str(),NULL);
if(N<0){
response.out()<<-1;
} else {
response.out()<<factorial(N);
}
} catch (const invalid_argument&){
response.out() << false;
}
}
And this is what I get now:
/usr/bin/ld: /tmp/ccFT2pAV.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
//usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Which, again, I have no idea what it means!
RE: strange errors while using Wt::Http:Response - Added by Shayan Javani almost 9 years ago
It was fixed by adding -lboost_system flag to g. I appreciate it if someone could explain it.
RE: strange errors while using Wt::Http:Response - Added by Wim Dumon almost 9 years ago
I'm not very familiar with that error, it's a bit bizar. The linker indeed seems to know in what file the symbol is, but doesn't use it because it was not specified on the command line. It hints you to add it to the command line.
This is not Wt specific; without much research (and thus not knowing what is exactly happening here), this stackoverflow question handles the topic:
https://stackoverflow.com/questions/19901934/strange-linking-error-dso-missing-from-command-line
Wim.