jrock
jrock

Reputation: 245

CMake differences between linking when target is a library vs executable

The following correctly links the executable to the protobuffer.

protobuf_generate_cpp(proto_srcs proto_hdrs simple.proto
add_executable(executable a.cc "${proto_srcs}")
target_link_libraries(executable "${PROTOBUF_LIBRARIES}")

The following does not correctly link the libraries.

protobuf_generate_cpp(proto_srcs proto_hdrs simple.proto
add_library(proto_lib "${proto_srcs}")
target_link_libraries(proto_lib "${PROTOBUF_LIBRARIES}")
...
target_link_libraries(some_executable proto_lib)

The issue appears to be in the handling of debug vs optimized libraries. In the first this is properly handled, while in the second it attempts to link to the debug/optimized library string, error follows.

ld: library not found for -loptimized;/usr/local/lib/libprotobuf.dylib;debug;/usr/local/lib/libprotobuf.dylib

I've tried playing with the quoting of arguments and changing the type of library being created, but I'm at a loss. Anyone know what I'm doing wrong?

Upvotes: 1

Views: 886

Answers (1)

arrowd
arrowd

Reputation: 34411

Remove doublequotes around ${PROTOBUF_LIBRARIES}, they make CMake treat list variable as plain string.

Upvotes: 4

Related Questions