I actually had the rule but after comparing my Makefile with the one in the 
examples directory I removed it hoping that would fix the issue.

Date: Thu, 28 Feb 2013 15:46:55 +0800
Subject: Re: [protobuf] Linker error
From: xiaof...@google.com
To: farhan1...@hotmail.com
CC: protobuf@googlegroups.com



On Thu, Feb 28, 2013 at 5:01 AM, Mohammad Husain <farhan1...@hotmail.com> wrote:

I am having a bizarre linker problem with the simple program I wrote with 
protobuf. When I run the make command I see tons of linker errors like the 
following:

user.pb.o:(.rodata._ZTIN4misc4UserE[_ZTIN4misc4UserE]+0x10): undefined 
reference to `typeinfo for google::protobuf::Message'

user.pb.o:(.rodata._ZTIN4misc13User_FullNameE[_ZTIN4misc13User_FullNameE]+0x0): 
undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
user.pb.o:(.rodata._ZTIN4misc13User_FullNameE[_ZTIN4misc13User_FullNameE]+0x10):
 undefined reference to `typeinfo for google::protobuf::Message'

user.pb.o:(.eh_frame+0x38b): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
make: *** [hello_protobuf] Error 1

However, the C++ example in the protobuf package builds and runs fine. Here is 
the output of the pkgconfig command:


$ pkg-config --cflags --libs protobuf
-pthread -I/usr/local/include  -pthread -L/usr/local/lib -lprotobuf -lz 
-lpthread  
$ protoc --version
libprotoc 2.4.1
I am using version 2.4.1. I believe something is wrong with my Makefile. Can 
anyone help?


I tried to attach the source and Makefile but probably attachment is disabled 
in the group. Here are my file contents:

<user.proto>
package misc;

message User {
    required string username = 1;

    required int32 id = 2;
    optional string email = 3;

    message FullName {
        required string firstName = 1;
        optional string middleName = 2;
        required string lastName = 3;
    }


    optional FullName fullName = 4;;
}
</user.proto>

<hello_protobuf.cpp>
#include <iostream>
#include "user.pb.h"

int main(int argc, char **argv) {
    misc::User u;


    u.set_username("username");
    u.set_id(1);

    std::cout << "Username: " << u.username() << " and ID: " << u.id() << 
std::endl;


    return 0;
}
</hello_protobuf.cpp>

<Makefile>
all: hello_protobuf

CC = g++
DEBUG = -g
LIBS = `pkg-config --cflags --libs protobuf`
CFLAGS = -Wall $(DEBUG)
LFLAGS = -Wall $(DEBUG) $(LIBS)


protoc_middleman: user.proto
    protoc --cpp_out=. user.proto
    @touch protoc_middleman

OBJS = hello_protobuf.o user.pb.o
These .o files are not compiled with appropriate flags. You need to add a rule 
for them, something like:
%.o: %.cc  $(CC) $(CFLAGS) $< -o $@ 
hello_protobuf: $(OBJS) protoc_middleman

    pkg-config --cflags protobuf  # fails if protobuf is not installed
    $(CC) $(LFLAGS) $(OBJS) -o hello_protobuf

clean:
    \rm *.o hello_protobuf
</Makefile>





-- 

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.

To post to this group, send email to protobuf@googlegroups.com.

Visit this group at http://groups.google.com/group/protobuf?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.

 

 


                                          

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


Reply via email to