2012-05-01 14 views
10

tôi grep cho chủ đề khác, nhưng họ không giúp tôi = (. Trên máy chủ làm việc của tôi, tôi không có privilegies sudo, vì vậy tôi cài đặt PB vớiKhông thể biên dịch ví dụ từ bộ đệm giao thức google

./configure --prefix =/home/username/local

Sau đó, tôi tạo ra file nguồn với "người" dụ và thành công biên dịch nó với protoc.

tôi không có pkg-info = (. tôi cố gắng để biên dịch với

g ++ -I/home/username/local/include -L/home/username/local/lib -lprotobuf -lpthread main.cpp person.pb.cc

và sau đó có một tỷ lỗi simular tức

person.pb.cc:(.text+0x4cf): tài liệu tham khảo không xác định để 'google :: protobuf :: nội :: kEmptyString'

tôi nghĩ, rằng nó là một vấn đề với liên kết, nhưng làm thế nào để giải quyết nó?

echo $ LD_LIBRARY_PATH /home/username/local/lib

trong main.cpp:

#include "person.pb.h" 
... 

Cảm ơn.

Trả lời

19

Đặt thư viện ở cuối:

g ++ -I/home/username/local/include -L/home/username/local/lib main.cpp person.pb.cc -lprotobuf -pthread

Từ GCC Link Options:

 
-llibrary 
-l library 
    Search the library named library when linking. 
    (The second alternative with the library as a separate argument 
    is only for POSIX compliance and is not recommended.) 

    It makes a difference where in the command you write this option; 
    the linker searches and processes libraries and object files in the 
    order they are specified. 
    Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but 
    before bar.o. If bar.o refers to functions in `z', those functions 
    may not be loaded. 

Ngoài ra, sử dụng -pthread thay vì -lpthread như -pthread thể đặt cờ cho prepr ocessor và linker.

+0

WOW !!! Nó thật tuyệt vời! Cảm ơn bạn! – ZhekakehZ

+0

bạn thực sự đã cứu tôi rất nhiều thời gian! Cảm ơn bạn! –

2

Thư viện liên kết cờ đi vào cuối những lập luận của trình biên dịch:

g ++ -I/home/username/local/include -L/home/username/local/lib main.cpp person.pb .cc -lprotobuf -lpthread