How to include generated headers? (created in ${PROJECT_BINARY_DIR})

Answered

I've been struggling getting CLion to scan the binary output area for headers generated from Protobuf .proto files. cmake doesn't have a problem as I've added the ${PROJECT_BINARY_DIR}/protobuf to the include path using INCLUDE_DIRECTORIES. But CLion seems to ignore it. I've also tried explicitly marking the directory under PROJECT_BINARY_DIR as 'Project Sources and Headers' but that doesn't seem to override the default exclusion of all directories under the build area.

1
6 comments
Avatar
Permanently deleted user

To be clear, the problem I'm seeing in CLion is the generated Protobuf headers are labeled as "Cannot find 'some_code.pb.h'" and anything referencing code in the headers is red in the IDE. The project compiles without issue.

0

Hello!

I tested the use of Protobuf with the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.9) 

project(untitled1)

set(CMAKE_CXX_STANDARD 11)

find_package(Protobuf REQUIRED)

include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS new.proto)

add_executable(untitled1 main.cpp new.proto ${PROTO_SRCS} ${PROTO_HDRS})

target_link_libraries(untitled1 ${PROTOBUF_LIBRARY})

The files generated after Run | Build were successfully indexed by CLion. 

Could you please try such simple project or https://github.com/prograholic/blog/tree/master/protobuf_tests - are the generated files indexed and found successfully by CLion?

 

 

2
Avatar
Permanently deleted user

I tried using CMAKE_CURRENT_BINARY_DIR instead of PROJECT_BINARY_DIR and I also tried invalidating the cache (with File->Invalidate Caches/Restart) but still no luck. However, when I switched from my release build to debug it did find the generated header files. I've switched back to release and it's still finding the headers in the debug binary output area. Kind of odd, but at least it works now. Thanks.

1

Just in case:

If you want to reset the CMake cache, you need to do Tools | CMake | Reset Cache and Reload Project.

If you want to reset the CLion cache, you need to do File | Invalidate Caches/Restart.

1
Avatar
Permanently deleted user

Hi Anna,

Does the CMake construct also work when CMake refers to ToolChain configured to remote m/c? I have downloaded protobuf plugin and can see "Protobuf Support" in preferences. What I don't understand is how to configure "Custom Include Path"? I really want to maximize use of this plugin while doing remote

Thanks, Vijay

0

I also have the same problem in the header file in CLion 2024.1 (Build #CL-241.14494.288, built on April 5, 2024). And the problem solved when i switched debug and release configuration and back!

0

Please sign in to leave a comment.