Issue 357 in protobuf: error messages while compiling a c++ program that uses .proto file.

1,724 views
Skip to first unread message

prot...@googlecode.com

unread,
Dec 22, 2011, 5:59:12 AM12/22/11
to prot...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 357 by cauverys...@gmail.com: error messages while compiling a
c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

What steps will reproduce the problem?
1. g++ searchinc.cpp


What is the expected output? What do you see instead?
It is expected to compile. Instead I get a number of errors as shown below:

searchinc.cpp:2:18: error: ‘google’ has not been declared
searchinc.cpp:2:26: error: ‘protobuf’ is not a namespace-name
searchinc.cpp:2:34: error: expected namespace-name before ‘;’ token
searchinc.cpp:5:1: error: ‘protobuf’ does not name a type
searchinc.cpp:6:1: error: ‘protobuf’ does not name a type
searchinc.cpp:7:1: error: ‘SearchService’ does not name a type
searchinc.cpp: In function ‘void DoSearch()’:
searchinc.cpp:14:3: error: ‘channel’ was not declared in this scope
searchinc.cpp:14:17: error: expected type-specifier before ‘MyRpcChannel’
searchinc.cpp:14:17: error: expected ‘;’ before ‘MyRpcChannel’
searchinc.cpp:15:3: error: ‘controller’ was not declared in this scope
searchinc.cpp:15:20: error: expected type-specifier before ‘MyRpcController’
searchinc.cpp:15:20: error: expected ‘;’ before ‘MyRpcController’
searchinc.cpp:19:3: error: ‘service’ was not declared in this scope
searchinc.cpp:19:17: error: expected type-specifier before ‘SearchService’
searchinc.cpp:19:17: error: expected ‘;’ before ‘SearchService’
searchinc.cpp:25:50: error: ‘protobuf’ has not been declared
searchinc.cpp:25:73: error: ‘Done’ was not declared in this scope
searchinc.cpp: In function ‘void Done()’:
searchinc.cpp:29:10: error: ‘service’ was not declared in this scope
searchinc.cpp:30:10: error: ‘channel’ was not declared in this scope
searchinc.cpp:31:10: error: ‘controller’ was not declared in this scope


Please use labels and text to provide additional information.

I have downloaded and installed the protoc compiler. It is installed in
/usr/local/bin.
I can also find the libprotobuf and libprotobuf-lite libraries in
/usr/local/lib.
The .proto file compiled successfully and produced pb.h and pb.cc files.
I have used an example provided in this very site.
I am new to linux as well as protobufs. I am attaching all the files.


Attachments:
search.pb.cc 31.0 KB
search.pb.h 19.8 KB
search.proto 374 bytes
searchinc.cpp 864 bytes

prot...@googlecode.com

unread,
Dec 22, 2011, 4:33:08 PM12/22/11
to prot...@googlegroups.com

Comment #1 on issue 357 by hea...@gmail.com: error messages while compiling
a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

You can't "using" a namespace that doesn't exist. This is a standard C++
issue. There's no way the namespace "google::protobuf" could have been
defined before you included even a single header file!

prot...@googlecode.com

unread,
Dec 23, 2011, 3:52:17 AM12/23/11
to prot...@googlegroups.com

Comment #2 on issue 357 by cauverys...@gmail.com: error messages while
compiling a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

hi,
thanks for your reply.
Now i have used the namespace after .pb.h:
#include "search.pb.h"
using namespace google::protobuf

I get the errors:
~/Desktop/proto/search$ g++ searchinc.cpp
searchinc.cpp:8:1: error: ‘protobuf’ does not name a type
searchinc.cpp:9:1: error: ‘protobuf’ does not name a type
searchinc.cpp:10:1: error: ‘SearchService’ does not name a type
searchinc.cpp: In function ‘void DoSearch()’:
searchinc.cpp:17:3: error: ‘channel’ was not declared in this scope
searchinc.cpp:17:17: error: expected type-specifier before ‘MyRpcChannel’
searchinc.cpp:17:17: error: expected ‘;’ before ‘MyRpcChannel’
searchinc.cpp:18:3: error: ‘controller’ was not declared in this scope
searchinc.cpp:18:20: error: expected type-specifier before ‘MyRpcController’
searchinc.cpp:18:20: error: expected ‘;’ before ‘MyRpcController’
searchinc.cpp:22:3: error: ‘service’ was not declared in this scope
searchinc.cpp:22:17: error: expected type-specifier before ‘SearchService’
searchinc.cpp:22:17: error: expected ‘;’ before ‘SearchService’
searchinc.cpp:28:50: error: ‘protobuf’ has not been declared
searchinc.cpp:28:73: error: ‘Done’ was not declared in this scope
searchinc.cpp: In function ‘void Done()’:
searchinc.cpp:32:10: error: ‘service’ was not declared in this scope
searchinc.cpp:33:10: error: ‘channel’ was not declared in this scope
searchinc.cpp:34:10: error: ‘controller’ was not declared in this scope

Am i wrong in linking with the header files?


Tom Swirly

unread,
Dec 23, 2011, 9:42:45 AM12/23/11
to prot...@googlegroups.com
I hate to say this - but these are pretty basic C++ errors that have nothing whatsoever to do with protocol buffers.  When you ask a question like, "Am i wrong in linking with the header files?" when "linking" isn't even a reasonable think to do with header files, you show that you don't know the language properly.

First, you aren't even giving us your source code, so we just have to guess - but more importantly, this isn't a C++ tutorial list, and using the protocol buffer bug database when there's no actual bug in sight is simply a waste of resources.






--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.




--
     /t

http://radio.swirly.com - art music radio 24/7 366/1000

prot...@googlecode.com

unread,
Dec 23, 2011, 9:40:25 PM12/23/11
to prot...@googlegroups.com

Comment #3 on issue 357 by hea...@gmail.com: error messages while compiling
a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

This is also a standard C++ semantic issue. The statement "using namespace
Foo::Bar" causes everything inside the namespace "Foo::Bar" to be visible
without qualification. It does *not* make "Bar" itself visible without
qualificiation. If you want to keep "protobuf::", you need "using namespace
google", not "using namespace google::protobuf". Otherwise keep "using
namespace google::protobuf" and refer to "RpcChannel",
not "protobuf::RpcChannel" (and so on).

prot...@googlecode.com

unread,
Dec 26, 2011, 12:28:16 AM12/26/11
to prot...@googlegroups.com

Comment #4 on issue 357 by cauverys...@gmail.com: error messages while
compiling a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

hi,

I retained using namespace google::protobuf and used "RpcChannel" instead
of "protobuf::RpcChannel". But I got the same errors as above.
However, I tried " #include <google/protobuf/service.h>
using namespace google::protobuf; " , and i got rid of the "RpcChannel does
not name a type " error.

I still get a lot of other errors.

$ g++ searchinc.cpp
searchinc.cpp:8:1: error: ‘SearchService’ does not name a type
searchinc.cpp: In function ‘void DoSearch()’:
searchinc.cpp:15:17: error: expected type-specifier before ‘MyRpcChannel’
searchinc.cpp:15:17: error: cannot convert ‘int*’ to
‘google::protobuf::RpcChannel*’ in assignment
searchinc.cpp:15:17: error: expected ‘;’ before ‘MyRpcChannel’
searchinc.cpp:16:20: error: expected type-specifier before ‘MyRpcController’
searchinc.cpp:16:20: error: cannot convert ‘int*’ to
‘google::protobuf::RpcController*’ in assignment
searchinc.cpp:16:20: error: expected ‘;’ before ‘MyRpcController’
searchinc.cpp:20:3: error: ‘service’ was not declared in this scope
searchinc.cpp:20:17: error: expected type-specifier before ‘SearchService’
searchinc.cpp:20:17: error: expected ‘;’ before ‘SearchService’
searchinc.cpp:26:50: error: ‘protobuf’ has not been declared
searchinc.cpp:26:73: error: ‘Done’ was not declared in this scope
searchinc.cpp: In function ‘void Done()’:
searchinc.cpp:30:10: error: ‘service’ was not declared in this scope

Is there a header I missed to include for "service" ??


Eyal Farago

unread,
Dec 26, 2011, 4:18:22 AM12/26/11
to prot...@googlegroups.com, codesite...@google.com
as mentioned before, these are all standard C++ semantics issues,
I'm not sure I completely understand what you're doing as you didn't send your code, but one thing I can do is to advice you against using the 'using namespace' approach.
If I were you, I'd start with a fresh empty c++ file, add an #include toone of the generated *.pb.h files and see that it compiles fine, then I'd add a function deceleration that takes/returns one of your generated type using fully qualified names.
once you get this to compile, you can attempt relaxing the fully qualified names and adding 'using namespace' statements.

Eyal.

Eyal Farago

unread,
Dec 26, 2011, 4:18:23 AM12/26/11
to prot...@googlegroups.com, codesite...@google.com

prot...@googlecode.com

unread,
Dec 26, 2011, 7:19:24 PM12/26/11
to prot...@googlegroups.com

Comment #5 on issue 357 by hea...@gmail.com: error messages while compiling
a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

See
<http://code.google.com/apis/protocolbuffers/docs/reference/cpp-generated.html#service>.
By default implementations of RPC services are not generated because the
implementations should be tied to the specific RPC protocol in use, which
protobuf does not know.

prot...@googlecode.com

unread,
Dec 27, 2011, 1:31:19 AM12/27/11
to prot...@googlegroups.com

Comment #6 on issue 357 by cauverys...@gmail.com: error messages while
compiling a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

Hi,
Thanks a lot for your help. I was trying out a very simple example in which
I am trying to set and retrieve a variable in a message.
I get the following error.

$ g++ simpleprog.cpp
/tmp/cc7ulNxs.o: In function `main':
simpleprog.cpp:(.text+0x1d): undefined reference to `num::num()'
collect2: ld returned 1 exit status

I am attaching my files.
Maybe something is wrong with my c++ coding. I apologize for these
clarifications that might seem basic. Can you please help me out.

Attachments:
simpleprog.proto 44 bytes
simpleprog.pb.h 4.3 KB
simpleprog.pb.cc.txt 8.6 KB
simpleprog.cpp 223 bytes

prot...@googlecode.com

unread,
Dec 27, 2011, 3:45:18 AM12/27/11
to prot...@googlegroups.com

Comment #7 on issue 357 by tom.ritc...@gmail.com: error messages while
compiling a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

Again, these are completely basic C++ errors that have nothing to do with
protocol buffers at all.

Reporting these as a bug is abusing the bug system!

(In this case, your issue is that you aren't compiling and linking the code
in simpleprog.pb.cc so when it links it doesn't find the code for the class
num.)

Please find some C++ mailing list or board to ask these questions. Thank
you.

prot...@googlecode.com

unread,
Dec 27, 2011, 3:54:23 AM12/27/11
to prot...@googlegroups.com

Comment #8 on issue 357 by cauverys...@gmail.com: error messages while
compiling a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

thank you.. sorry for raising these issues here.

prot...@googlecode.com

unread,
Dec 3, 2012, 6:05:18 PM12/3/12
to prot...@googlegroups.com
Updates:
Status: Invalid

Comment #9 on issue 357 by xiaof...@google.com: error messages while
compiling a c++ program that uses .proto file.
http://code.google.com/p/protobuf/issues/detail?id=357

(No comment was entered for this change.)

Reply all
Reply to author
Forward
0 new messages