Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake protobuf_generate is missing cpp_out directory #12450

Closed
scharri opened this issue Apr 12, 2023 · 4 comments
Closed

CMake protobuf_generate is missing cpp_out directory #12450

scharri opened this issue Apr 12, 2023 · 4 comments

Comments

@scharri
Copy link

scharri commented Apr 12, 2023

What version of protobuf and what language are you using?
v22.2

What operating system (Linux, Windows, ...) and version?
Debian 11

What runtime / compiler are you using (e.g., python version or gcc version)
GCC 12.2.0

What did you do?
Steps to reproduce the behavior:

  1. Clone repository, checkout v22.2, build and install it.
  2. Go into protobuf/example folder, create dir build and go into it.
  3. Call cmake ../ and make
  4. See error

What did you expect to see
I expect that addressbook.proto is compiled by the protoc and resulted .pb.c and .pb.h are available to build add_person.cc

What did you see instead?
When protoc is running on addressbook.proto you get the output: cpp_out: No such file or directory and off course building add_preson.cc fails because addressbook.pb.h is not available.

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

cmake ../
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.13")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/stefan/sources/motionConnect/protobuf/examples/build
❯ make
[ 12%] Running cpp protocol buffer compiler on addressbook.proto
make[2]: cpp_out: No such file or directory
[ 25%] Building CXX object CMakeFiles/add_person_cpp.dir/add_person.cc.o
/home/stefan/sources/motionConnect/protobuf/examples/add_person.cc:9:10: fatal error: addressbook.pb.h: No such file or directory
9 | #include "addressbook.pb.h"
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/add_person_cpp.dir/build.make:83: CMakeFiles/add_person_cpp.dir/add_person.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/add_person_cpp.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Anything else we should know about your project / environment

@scharri scharri added the untriaged auto added to all issues by default when created. label Apr 12, 2023
@scharri
Copy link
Author

scharri commented Apr 12, 2023

I tried to investigate this issue further and in my opinion there is an error in the custom command of protobuf-generate.cmake starting at line 138.

add_custom_command(
      OUTPUT ${_generated_srcs}
      COMMAND ${protobuf_PROTOC_EXE}
      ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
      DEPENDS ${_abs_file} ${protobuf_PROTOC_EXE} ${protobuf_generate_DEPENDENCIES}
      COMMENT ${_comment}
      VERBATIM )

In my opinion --${protobuf_generate_LANGUAGE}_out has to be followed by = and the ${protobuf_generate_PROTOC_OUT_DIR}.
I found also that ${_protobuf_include_path} contains a semicolon after -I before PATH.

@fowles fowles added packaging & distribution 22.x and removed untriaged auto added to all issues by default when created. labels Apr 17, 2023
@deannagarcia
Copy link
Member

Thanks for looking into this! Would you be willing to send us a PR with this fix?

@hector-pelletier
Copy link

I believe the problem is actually the variable protobuf_PROTOC_EXEC not being set when running add_custom_command. Hence the command becomes cpp_out which is of course not recognized.

For what it is worth, I made it work for myself by

  • running cmake with the flag protobuf_MODULE_COMPATIBLE set, which ensures that Protobuf_PROTOC_EXECUTABLE contains the path to the protobuf compiler
  • in protobuf-generate.cmake, replacing the occurences of protobuf_PROTOC_EXEC by the variable mentioned above
    This allowed me to compile the examples and my own projects.

I have not investigated further to understand why the protobuf compiler variable was not set, as I am not extremely competent on cmake. But I thought this might help someone.

copybara-service bot pushed a commit that referenced this issue Apr 19, 2023
This should fix #12374, #12375, and #12450. The `protobuf_PROTOC_EXEC` variable
is not defined, and I think `protobuf::protoc` is what we should be using
instead.

PiperOrigin-RevId: 525572684
copybara-service bot pushed a commit that referenced this issue Apr 19, 2023
This should fix #12374, #12375, and #12450. The `protobuf_PROTOC_EXEC` variable
is not defined, and I think `protobuf::protoc` is what we should be using
instead.

PiperOrigin-RevId: 525572684
copybara-service bot pushed a commit that referenced this issue Apr 20, 2023
This should fix #12374, #12375, and #12450. The `protobuf_PROTOC_EXEC` variable
is not defined, and I think `protobuf::protoc` is what we should be using
instead.

PiperOrigin-RevId: 525591320
@acozzette
Copy link
Member

This should be fixed in b302597.

copybara-service bot pushed a commit that referenced this issue Apr 21, 2023
…tory

I confirmed that this test would catch the problem from #12450.

PiperOrigin-RevId: 525865658
copybara-service bot pushed a commit that referenced this issue Apr 21, 2023
…tory

I confirmed that this test would catch the problem from #12450.

PiperOrigin-RevId: 525865658
copybara-service bot pushed a commit that referenced this issue Apr 21, 2023
…tory

I confirmed that this test would catch the problem from #12450.

PiperOrigin-RevId: 525865658
copybara-service bot pushed a commit that referenced this issue Apr 21, 2023
…tory

I confirmed that this test would catch the problem from #12450.

PiperOrigin-RevId: 526165526
mkruskal-google pushed a commit that referenced this issue May 4, 2023
This should fix #12374, #12375, and #12450. The `protobuf_PROTOC_EXEC` variable
is not defined, and I think `protobuf::protoc` is what we should be using
instead.

PiperOrigin-RevId: 525591320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants