I can compile and run my program just fine with a two step process. First compile main without linking g++ -std=c++11 -I/opt/googleapis/gens -c -o main.o main.cpp then link with object files in an archive g++ main.o googleapis.ar 'pkg-config --libs grpc++ grpc' -lgrpc++_reflection -lprotobuf -lpthread -ldl. This works pretty well. I've been trying to do the same thing in CMake but nothing I try seems to work. I thought adding the object files to add_executable would work.
cmake_minimum_required(VERSION 3.6)
project(api)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(PkgConfig REQUIRED)
pkg_check_modules(GRPC++ REQUIRED grpc++)
pkg_check_modules(GRPC REQUIRED grpc)
pkg_check_modules(PROTOBUF REQUIRED protobuf)
include_directories(
${GRPC++_INCLUDE_DIRS}
${GRPC_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIRS}
/opt/googleapis/gens
)
link_directories(
${GRPC++_LIBRARY_DIRS}
${GRPC_LIBRARY_DIRS}
${PROTOBUF_LIBRARY_DIRS}
)
set(
GRPC_LIBRARIES
${GRPC++_LIBRARIES}
${GRPC_LIBRARIES}
${PROTBUF_LIBRARIES}
pthread
dl
protobuf
grpc++_reflection
)
file(GLOB MYFILES /opt/googleapi/gens/*.o)
set(SOURCE_FILES
parse_arguments.cc
parse_arguments.h
streaming_transcribe.cc
streaming_transcribe_singlethread.cc
transcribe.cc)
add_executable(api ${SOURCE_FILES} ${MYFILES})
target_link_libraries(api ${GRPC_LIBRARIES})
Aucun commentaire:
Enregistrer un commentaire