aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

C++ linker failure due to missing C function decoration declaration #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. insert generated files in a C++ project
2. from a foo.cpp source file, include the generated xx.pb.h
3. in this cpp file, use the tYyy_fields structure

What is the expected output?
Link should succeed.

What do you see instead?
error LNK2001: external symbol not found "struct _pb_field_t const * const 
tYyy_fields" (?tYyy_fields@@3QBU_pb_field_t@@B)

What version of the product are you using? On what operating system?
Visual Studio 2005 on a Win7

Please provide any additional information below.
This error is due to function decoration error when compiling foo.cpp.
To avoid this, you can maybe add the following in the generated xx.pb.h to 
force a "C" style decoration.
    #ifdef __cplusplus
        extern "C"
        {
    #endif
            /* Struct field encoding specification for nanopb */
            extern const pb_field_t tJointState_fields[3];
            /* ... */
    #ifdef __cplusplus
        extern "C"
        {
    #endif

This would be an enhancement as another solution is to use in the foo.cpp file 
the following lines:
extern "C"
{
    #include "xx.pb.h"
}

Original issue reported on code.google.com by cea.max....@gmail.com on 17 Oct 2012 at 4:30

GoogleCodeExporter commented 9 years ago
Yeah, I haven't been quite whether to add the externs to the headers.

The latter solution works fine, but I guess it might be easier to use if you 
didn't need to do that manually.

Original comment by Petteri.Aimonen on 17 Oct 2012 at 4:38

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 3aaa4ad8c290.

Original comment by Petteri.Aimonen on 29 Oct 2012 at 5:17

GoogleCodeExporter commented 9 years ago
I forgot to ask the same kind of protection around the different functions of 
pb_encode and pb_decode...
I hope you guess it would be nice to have them also.
Sorry for this late comment.

Original comment by cea.max....@gmail.com on 29 Oct 2012 at 5:21

GoogleCodeExporter commented 9 years ago
Yeah it is included. Only pb.h I didn't add the externs, because it doesn't 
contain any functions.

If you can test the 0.1.7 beta in the downloads section it would be very useful.

Original comment by Petteri.Aimonen on 29 Oct 2012 at 5:43

GoogleCodeExporter commented 9 years ago
Fixed in nanopb-0.1.7

Original comment by Petteri.Aimonen on 12 Nov 2012 at 7:33