generating .pb.h files with cmake? #3265
-
TAG: stable SICP ARM Mac 12.3 (21E230)? What did you do?
In the top level set(FETCHCONTENT_QUIET OFF)
include(FetchContent)
FetchContent_Declare(
ortools
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG stable
)
set(BUILD_SHARED_LIBS ON)
set(BUILD_DEPS ON)
set(BUILD_SAMPLES OFF)
set(BUILD_EXAMPLES OFF)
FetchContent_MakeAvailable(ortools)
add_definitions(-DORTOOLS) Because of this structure, I need to include the or-tools header files in the static libraries, and then link the or-tools library against the dynamic library. Trying to link or-tools against both the static and dynamic libraries produces the following error: ERROR: Something is wrong with flag 'flagfile' in file 'Users/username/project-root/cmake-build-debug/ortools-download/ortools_project-prefix/src/ortools_project-build/_deps/absl-src/absl/flags/parse.cc'. One possibility: file 'Users/username/project-root/cmake-build-debug/ortools-download/ortools_project-prefix/src/ortools_project-build/_deps/absl-src/absl/flags/parse.cc' is being linked both statically and dynamically into this executable. e.g. some files listed as srcs to a test and also listed as srcs of some shared lib deps of the same test. Therefore, in the include_directories(${ortools_SOURCE_DIR})
include_directories(${absl_SOURCE_DIR})
... and instead of linking each static library to add_library(${dynamiclib} SHARED ${SOURCE_FILES_SRC})
target_link_libraries(${dynamiclib} ${staticlib1} ${staticlib2} ortools::ortools) This seems to be working so far, but I get stuck because I don't know how to generate the /Users/username/project/cmake-build-debug/_deps/ortools-src/ortools/linear_solver/linear_solver.h:159:10: fatal error: 'ortools/linear_solver/linear_solver.pb.h' file not found Is there a way to generate these files with cmake so that I can use |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
These file are generated by CMake using protoc Lines 146 to 199 in 49b6301 and they should be located in Line 183 in 49b6301 so I suspect an issue in the target_include_directories() of ortools::ortools target
dev Note: Lines 92 to 94 in 49b6301 link between Lines 216 to 220 in 49b6301 |
Beta Was this translation helpful? Give feedback.
-
upon reflexion, I think the issue is the you may try to add half off topic: I have difficulty to exactly understand why |
Beta Was this translation helpful? Give feedback.
-
Yeah I'm not really sure what I'm doing incorrectly. I changed my code so that I'm only calling set(FETCHCONTENT_QUIET OFF)
include(FetchContent)
FetchContent_Declare(
ortools
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG stable
)
set(BUILD_SHARED_LIBS ON)
set(BUILD_DEPS ON)
set(BUILD_SAMPLES OFF)
set(BUILD_EXAMPLES OFF)
FetchContent_MakeAvailable(ortools)
add_definitions(-DORTOOLS)
include_directories(${ortools_SOURCE_DIR})
include_directories(${ortools_BINARY_DIR})
include_directories(${absl_SOURCE_DIR})
include_directories(${protobuf_SOURCE_DIR}/../src) Then I'm building a bunch of static libraries, none of which are linked to ortools, but some of which include headers from ortools. Then I link all those static libraries together into a shared library and to ortools:
Everything compiles, but when I go to run the program immediately crashes with the error: ERROR: Something is wrong with flag 'flagfile' in file 'Users/connorriley/dial-a-ride-dispatcher/cmake-build-debug/_deps/absl-src/absl/flags/parse.cc'. One possibility: file 'Users/connorriley/dial-a-ride-dispatcher/cmake-build-debug/_deps/absl-src/absl/flags/parse.cc' is being linked both statically and dynamically into this executable. e.g. some files listed as srcs to a test and also listed as srcs of some shared lib deps of the same test. The executable I'm running is linked as such:
I'm really out of my skill set in terms of what I should be doing to try to debug this. Any suggestions you have would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
Update, I got my code compiling, I still don't really understand what was going wrong. The only thing I changed from above is instead of having set(BUILD_SHARED_LIBS ON) I set it to set(BUILD_SHARED_LIBS OFF) The thing that clued me in to this might being the issue was the discussion here: abseil/abseil-cpp#125 "Unfortunately, Abseil has not been designed with use in dynamic libraries in mind (https://abseil.io/about/compatibility) and I don't know of a way to fix this issue in a way that's portable across all of the platforms that Abseil supports." I'm not sure if that discussion is relevant, but if anyone else comes across this I figured I'd leave it here. |
Beta Was this translation helpful? Give feedback.
-
Hi, I was following along with your solution and noticed this:
This will result in an incorrect path, because the
Just wanted to add this in case anyone else gets caught up by the same thing. |
Beta Was this translation helpful? Give feedback.
Update, I got my code compiling, I still don't really understand what was going wrong. The only thing I changed from above is instead of having
I set it to
The thing that clued me in to this might being the issue was the discussion here: abseil/abseil-cpp#125
which one of the maintainers of absl says:
"Unfortunately, Abseil has not been designed with use in dynamic libraries in mind (https://abseil.io/about/compatibility) and I don't know of a way to fix this issue in a way that's portable across all of the platforms that Abseil supports."
I'm not sure if that discussion is relevant, but if anyone else comes across this I figure…