2012-04-04 26 views
16

我试图让我做它提升它的方法相同:如何通过Linux上的cmake链接谷歌protobuf库?

find_package(Boost COMPONENTS system filesystem REQUIRED)              
find_package(ProtocolBuffers)                     

## Compiler flags                        
if(CMAKE_COMPILER_IS_GNUCXX)                     
    set(CMAKE_CXX_FLAGS "-O2")                    
    set(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -lrt -lpthread")             
endif()                          

target_link_libraries(complex                     
    ${Boost_FILESYSTEM_LIBRARY}                     
    ${Boost_SYSTEM_LIBRARY}                      
    ${PROTOBUF_LIBRARY}                       
) 

(GOOGLE了它的地方),但得到了坏输出:

CMake Warning at complex/CMakeLists.txt:18 (find_package): 
    Could not find module FindProtocolBuffers.cmake or a configuration file for 
    package ProtocolBuffers. 

    Adjust CMAKE_MODULE_PATH to find FindProtocolBuffers.cmake or set 
    ProtocolBuffers_DIR to the directory containing a CMake configuration file 
    for ProtocolBuffers. The file will have one of the following names: 

    ProtocolBuffersConfig.cmake 
    protocolbuffers-config.cmake 

我如何用cmake的链接呢?或者我甚至可以使用cmake编译.proto文件?

回答

25

你可以尝试的CMake的FindProtobuf模块:

include(FindProtobuf) 
find_package(Protobuf REQUIRED) 
include_directories(${PROTOBUF_INCLUDE_DIR}) 
... 
target_link_libraries(complex 
    ${Boost_FILESYSTEM_LIBRARY} 
    ${Boost_SYSTEM_LIBRARY} 
    ${PROTOBUF_LIBRARY} 
) 


如需进一步信息,运行

cmake --help-module FindProtobuf 
+2

谢谢你这个答案。您可以使用'$ {Boost_LIBRARIES}'而不是'$ {Boost_FILESYSTEM_LIBRARY}'和'$ {Boost_SYSTEM_LIBRARY}'。 – 2015-07-28 03:35:15