2012-05-01 5 views
10

ich grep für andere Themen zusammenstellen, aber sie nicht mir helfen = (. Auf meinem Arbeits Server, ich habe keine sudo privilegies, so dass ich installieren PB mitKann nicht Beispiel von Google Protokoll Puffer

./configure prefix =/home/username/local

Dann erstellen i-Quelldateien mit "Person" Beispiel und es erfolgreich mit Protoc kompilieren.

ich habe keine pkg-info = (. ich versuche, um es mit

zu kompilieren

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

und haben dann eine Milliarde simular Fehler dh

person.pb.cc:(.text+0x4cf): undefined reference to `google :: protobuf :: internal :: kEmptyString‘

ich denke, dass es ist ein Problem beim Verknüpfen, aber wie löst man es?

echo $ LD_LIBRARY_PATH /home/username/local/lib

in main.cpp:

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

Dank.

Antwort

19

Setzen Sie die Bibliothek am Ende:

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

von 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. 

verwenden Sie auch -pthread statt -lpthread als -pthread Flaggen für Prepr gesetzt werden ocessor und Linker.

+0

WOW !!! Es ist brilliant! Vielen Dank! – ZhekakehZ

+0

du hast mir wirklich eine Menge Zeit erspart! Vielen Dank! –

2

Bibliothek verbindet Fahnen gehen am Ende der Argumente der Compiler:

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

Verwandte Themen