CMake cannot generate protocolbuf headers and source files on Windows - c++

I am trying to compile a .proto file on Windows using CMake (version 3.23.1). To this aim, I am using documentations that can be found here and here. But at the end, the .cc and .h files are not generated. Here is my CMakeLists.txt file:
project(test_proto)
cmake_minimum_required(VERSION 3.23)
set(Protobuf_DIR "C:/grpc/debug/cmake")
set(gRPC_DIR "C:/grpc/debug/lib/cmake/grpc")
set(ZLIB_ROOT "C:/zlib/debug")
set(c-ares_DIR "C:/grpc/debug/lib/cmake/c-ares")
find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
set(PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/proto/server.proto)
add_library(test_proto ${PROTO_FILES})
target_link_libraries(test_proto
PUBLIC protobuf::libprotobuf
PUBLIC gRPC::grpc
PUBLIC gRPC::grpc++
)
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tmp")
set(PROTO_IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/proto")
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)
message(STATUS " The value of grpc cpp location is: ${grpc_cpp_plugin_location}")
protobuf_generate(
TARGET test_proto
LANGUAGE cpp
OUT_VAR PROTO_GENERATED_FILES
IMPORT_DIRS ${PROTO_IMPORT_DIRS}
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
protobuf_generate(
TARGET test_proto
OUT_VAR PROTO_GENERATED_FILES
LANGUAGE grpc
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}"
IMPORT_DIRS ${PROTO_IMPORT_DIRS}
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
message(STATUS " The generated files are located in: ${PROTO_GENERATED_FILES}")
After running the above CMake file using this command:
cmake.exe -D CMAKE_BUILD_TYPE=Debug -G "Visual Studio 16 2019" -S D:\cmake-test -B D:\cmake-test
I am getting this output:
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.29.30137.0
-- The CXX compiler identification is MSVC 19.29.30137.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: c:/VS/MVS16117/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - 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: c:/VS/MVS16117/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: C:/zlib/debug/lib/zlibd.lib (found version "1.2.11")
-- Found OpenSSL: optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MDd.lib (found version "3.0.3")
-- The value of grpc cpp location is: C:/grpc/debug/bin/grpc_cpp_plugin.exe
-- The generated files are located in: D:/cmake-test/tmp/proto/server.grpc.pb.h;D:/cmake-test/tmp/proto/server.grpc.pb.cc;D:/cmake-test/tmp/proto/serverPLUGIN;D:/cmake-test/tmp/proto/serverprotoc-gen-grpc=C:/data/tools/grpc/v1.15.1-2/win64/release/bin/grpc_cpp_plugin.exe
-- Configuring done
-- Generating done
-- Build files have been written to: D:/cmake-test
without any errors. But the .h and .cc files are not generated. Any ideas?

Related

Change Compiler VsCode

I am new in c++
The cmakelist.txt file dont give me a Makefile
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22000.
-- The C compiler identification is MSVC 19.29.30140.0
-- The CXX compiler identification is MSVC 19.29.30140.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - 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: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/JohnSmith/Documents/Hello/build
I dont know how to change the compiler to G++
this is the cmake
cmake_minimum_required(VERSION 3.0)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
project(HelLo)
add_executable(Hello main.cpp hello.cpp)
I am on windows , Thanks for help
(I can compile with g++ and gcc just cmakefile dont work )
First, make sure you've installed gcc/g++ under Windows (either CygWin or MinGW). Remove the set commands from your CMakelists.txt. Then in a CygWin/MinGW shell use the following command to generate the Makefile:
CC=gcc CXX=c++ cmake ..
cmake -G "Unix Makefiles" ..

Windows not able to find FLEX_LIBRARIES

When using this CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(project_c)
set(CMAKE_CXX_STANDARD 11)
set(project_name project_c)
find_package(BISON)
find_package(FLEX)
BISON_TARGET(parser parser.y ${CMAKE_SOURCE_DIR}/parser.cpp)
FLEX_TARGET(lexer lexer.l ${CMAKE_SOURCE_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(lexer parser)
add_executable(${project_name} ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS})
target_include_directories(${project_name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${project_name} ${FLEX_LIBRARIES})
CMake complains about
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
FL_LIBRARY (ADVANCED)
linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c
I've tried to copy the winflex folder inside the project folder but that won't help anyway. This proposed solution isn't working.
This is the complete CMake log
"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\asant\workspace\CLionProjects\project_c
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found BISON: C:/Program Files (x86)/win_flex_bison-2.5.23/win_bison.exe (found version "3.7.1")
-- Found FLEX: C:/Program Files (x86)/win_flex_bison-2.5.23/win_flex.exe (found version "2.6.4")
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
FL_LIBRARY (ADVANCED)
linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
[Failed to reload]

Unable to generate executable file using compiler

I am trying to compile my source code using riscv64-unknown-elf-g++ compiler into a binary file but I am getting this warning and unable to generate exec file:
warning for library: libofdm.a the table of contents is empty (no object file members in the library define global symbols)
referring to this issue before:
Can't make my c++ file into a library with compiler
as suggested in the above answer the same toolchain is used to compile the object file to create the library. Even though I am getting the error. Below I am attaching the whole command line used to compile.
Last login: Thu Jul 9 12:50:56 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
(base) k:~ cd /Users/yuli/Documents/version3/cpp/
(base) k:~ ls
CMakeLists.txt src test
(base) k:~ mkdir build_riscv
(base) k:~ cd build_riscv
(base) k:~ cmake ..
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compiling RISCV
CMAKE_CXX_COMPILER: /usr/local/opt/riscv-gnu-toolchain/bin/riscv64-unknown-elf-g++
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yuli/Documents/version3/cpp/build_riscv
(base) k:~ make
Scanning dependencies of target ofdm
[ 33%] Building CXX object CMakeFiles/ofdm.dir/src/transmitter.cpp.o
[ 66%] Building CXX object CMakeFiles/ofdm.dir/src/configuration.cpp.o
[100%] Linking CXX static library libofdm.a
warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: warning for library: libofdm.a the table of contents is empty (no object file members in the library define global symbols)
[100%] Built target ofdm
(base) k:~
and FYI I am using mac machine. I am Specifying this because I saw in a post with "clang warnings macOS #3331".
clang warnings macOS #3331
CMakeLists.txt as follows:
cmake_minimum_required(VERSION 3.13)
project(ofdmchain)
set(CMAKE_CXX_COMPILER "/usr/local/opt/riscv-gnu-toolchain/bin/riscv64-unknown-elf-g++")
add_definitions(-DCOMPILES_ON_PC -Wall -Wextra)
configure_file(${CMAKE_SOURCE_DIR}/src/config.hpp.in ${CMAKE_BINARY_DIR}/config.hpp)
if("${CMAKE_CXX_COMPILER}" MATCHES ".*riscv64-unknown-elf-g\\+\\+")
message(STATUS "Compiling RISCV")
SET(RISCV 1)
else()
message(STATUS "Compiling X86")
SET(RISCV 0)
endif()
message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
add_library(ofdm
src/transmitter.cpp
src/configuration.cpp
src/ofdm.hpp
src/datatypes.hpp
)
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/../reference_matlab)
target_include_directories(ofdm PRIVATE ${CMAKE_SOURCE_DIR}/src/)
if (NOT ${RISCV})
add_executable(unit_tests
test/catch_main.cpp
test/test_sanity.cpp
test/test_utilities.cpp
test/test_transmitter.cpp
)
target_include_directories(unit_tests PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(unit_tests PUBLIC ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(unit_tests ofdm)
endif()

Running cmake in a different build directory on Windows

I run CMake using cmake .. in order to make it output all the generated files in a different directory. This runs fine on Ubuntu, but breaks on Windows 10 when I try to run it. Running cmake . from the root project directory seems to work fine on both platforms. The output of cmake .. on Windows is:
PS D:\Development\cpp\hello-vulkan\build> cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.16299.0 to target Windows 10.0.17134.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
The CMakeLists.txt is specified here:
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
cmake_minimum_required(VERSION 3.10)
project(hello_vulkan)
# Download and setup GLFW
set(GLFW_DIR ${PROJECT_SOURCE_DIR}/lib/glfw)
set(GLFW_BINARY_DIR ${GLFW_DIR}/bin)
ExternalProject_Add(
glfw
PREFIX ${GLFW_DIR}
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.2.1
INSTALL_DIR ${GLFW_BINARY_DIR}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GLFW_BINARY_DIR}
)
# Link Vulkan and GLFW
set(VULKAN_DIR ${PROJECT_SOURCE_DIR}/lib/vulkan)
include_directories(${VULKAN_DIR}/include)
link_directories(
${VULKAN_DIR}/lib
${GLFW_BINARY_DIR}
)
# Setup project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build/)
set(SOURCES source/main.cpp)
add_executable(hello_vulkan ${SOURCES})
add_dependencies(hello_vulkan glfw)
Any ideas what to do for it to work when running from a different directory on Windows?
Edit:
Here is the output from cmake .. on Ubuntu:
cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/d/Development/cpp/hello-vulkan/build

Setting up Project with Clion and SFML works, but only the first time

So, i set up my Cloin/SFML project like this : configure SFML for clion (windows)
and added the SFML_ROOT variable, and then it works exactly once, and every time i try too run it after the first, i get this error(gam is the project name, it is set correctly in the CMakeLists.txt file):
mingw32-make.exe: *** No rule to make target 'gam'. Stop.
How do i get it to work more than once?(It might be something as stupid as me clicking the wrong button to run this thing. I´m new to Clion and cmake)
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(gam)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(gam ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(gam ${SFML_LIBRARIES})
endif()
output of CMake when project is first initialized:
"C:\Program Files\JetBrains\CLion 2018.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\programierzeug\c++\test
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe
-- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/programierzeug/c++/test/cmake-build-debug
[Finished]
output of CMake when reloading project:
"C:\Program Files\JetBrains\CLion 2018.2.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\programierzeug\c++\test
-- Configuring done
-- Generating done
-- Build files have been written to: D:/programierzeug/c++/test/cmake-build-debug
[Finished]