Can't compile example from google protocol buffers

后端 未结 3 1169
囚心锁ツ
囚心锁ツ 2020-12-16 16:31

I grep for other topics, but they dont help me =(. On my working server, i have no sudo privilegies, so i install PB with

./configure --prefix=/home/u

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 17:09

    Put the library at the end:

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

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

    Also, use -pthread instead of -lpthread as -pthread may set flags for preprocessor and linker.

提交回复
热议问题