Building gRPC C++ with CMake on Linux - c++

I'm trying to build gRPC (cpp) using CMake, but running into errors. I am able to successfully build gRPC with make per the instructions on the gRPC cpp page. Using make is deprecated, but CMake isn't working for me.
After following the instructions for downloading, cloning etc., I go to the "Building with CMake", where it says for Linux/Unix, do this:
$ mkdir -p cmake/build
$ cd cmake/build
$ cmake ../..
$ make
For me, it fails at the 3rd line (cmake). The following is the output:
$ cmake ../..
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.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
CMake Error at CMakeLists.txt:138 (include):
include could not find load file:
cmake/zlib.cmake
< repeats above error for the following .cmake files: cares, protobuf, ssl, gflags, benchmark, address_sorting and nanopb>
Those files (cmake/<package name>.cmake) don't exist in the cmake/ directory on my system. I'm not sure what in the CMakeLists.txt file would cause them to appear there.
Researching this issue, I tried various combinations of cmake options such as -DBUILD_SHARED_LIBS=ON, -DgRPC_INSTALL=ON, and -DgRPC<package_name>_PROVIDER=package for each of the fails listed above. I always get the same errors. Finally, I tried running the run_distrib_test_cmake.sh script. It eventually failed the same way.
Any ideas?

The third party CMake files (e.g. cmake/zlib.cmake) do exist in the GitHub repository you cloned (see here). Please be sure your repository finished cloning completely, to include all of the submodules, per the gRPC build documentation:
Run from grpc directory after cloning the repo with --recursive or updating submodules.
$ mkdir -p cmake/build
$ cd cmake/build
$ cmake ../..
$ make
So be sure everything is cloned with:
git checkout --recurse-submodules
or
git submodule update --recursive

As #squareskittles points out, the cmake directory is part of the clone. I probably inadvertently deleted and re-created it.
Other than this, the only other thing I had to do which was not mentioned for Linux builds, was to install golang (sudo apt-get install golang). This was mentioned as a prerequisite for Windows, but I think it should more accurately be described as a prerequisite for CMake builds, as it seems to be necessary for Linux, CMake builds.

Related

CMake toolchain not finding standard C/C++ includes or libraries

I'm trying to write my CMakeLists.txt files in a way that can be compiled with and without toolchain support, but I am running into compile and linker issues where common C/C++ libraries aren't getting found or linked.
After reading CMake toolchain documentation the only configuration option I could see that would control how the standard libraries are found is the CMAKE_SYSROOT variable.
I happen to be using a TI toolchain so I specify a path set(CMAKE_SYSROOT "C:/ti/ccs1031/ccs/tools/compiler/ti-cgt-arm_20.2.4.LTS")
When I compile without specifying a toolchain file everything works fine and I get the compiled target for the host system.
> cmake -E make_directory build && \
> cmake -E chdir build cmake .. && \
> cmake --build build --config Debug
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/src/cmake-toolchain-example/build
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule C:/src/cmake-toolchain-example/CMakeLists.txt
example.vcxproj -> C:\src\cmake-toolchain-example\build\Debug\example.exe
Building Custom Rule C:/src/cmake-toolchain-example/CMakeLists.txt
However, when I try compiling with the toolchain that uses the TI toolchain I get errors related to standard library.
> cmake -E make_directory ../build && \
> cmake -E chdir ../build cmake -G "Eclipse CDT4 - Ninja" --toolchain cmake/Toolchains/ti-cgt-toolchain.cmake ../cmake-toolchain-example && \
> cmake --build ../build --config Debug
-- Using toolchain file: cmake/Toolchains/ti-cgt-toolchain.cmake
-- Using toolchain file: C:/src/cmake-toolchain-example/cmake/Toolchains/ti-cgt-toolchain.cmake
-- The C compiler identification is TI 20.2.4
-- The CXX compiler identification is TI 20.2.4
-- Found Eclipse version 4.14 ()
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - failed
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - failed
-- Configuring done
-- Generating done
-- Build files have been written to: C:/src/build
[1/2] Building CXX object CMakeFiles\example.dir\main.cpp.obj
FAILED: CMakeFiles/example.dir/main.cpp.obj
C:\ti\ccs1031\ccs\tools\compiler\ti-cgt-arm_20.2.4.LTS\bin\armcl.exe --compile_only --cpp_file=C:\src\cmake-toolchain-example\main.cpp --preproc_with_compile --preproc_dependency=CMakeFiles\example.dir\main.cpp.obj.d --output_file=CMakeFiles\example.dir\main.cpp.obj
"C:\src\cmake-toolchain-example\main.cpp", line 1: fatal error: could not open source file "iostream" (no directories in search list)
1 catastrophic error detected in the compilation of "C:\src\cmake-toolchain-example\main.cpp".
Compilation terminated.
>> Compilation failure
ninja: build stopped: subcommand failed.
I think I am missing something obvious when it comes to crosscompiling that is automatically handled when using the default CMake generators.
When using toolchain files, does one have to manually add the include/, lib/, etc to their respective CMake variables?
I guess I was under the impression that the CMAKE_SYSROOT along with other CMake variables such as CMAKE_SYSTEM_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_SYSTEM_INCLUDE_PATH, etc use some sane defaults that work for most toolchains.
The standard C/C++ includes for my toolchain are located at C:\ti\ccs1031\ccs\tools\compiler\ti-cgt-arm_20.2.4.LTS\include and there is a libc.a that is available at C:\ti\ccs1031\ccs\tools\compiler\ti-cgt-arm_20.2.4.LTS\lib.
However, since I don't have to specify that standard stuff in my CMakeLists.txt when not using a toolchain file I would like to not specify it when I am using a toolchain file.
What else is needed in the toolchain file to help resolve C/C++ standard library issues like this?
I will provide a simple git repo to demonstrate this issue located here.
EDIT:
I came across this e2e forum post that was pretty helpful.

Building the AWS SDK from source on Amazon Linux 2

I am trying to follow up suggestion from aws-lamba-cpp to reduce complexity in building my application.
If you choose to build on the same Amazon Linux version used by
lambda, you can avoid packaging the C runtime in your zip file.
After reading:
Building the SDK from source on EC2
Here is what I tried:
% docker run -it amazonlinux:latest /bin/bash
$ cd /tmp/
$ yum -y install libcurl-devel openssl-devel libuuid-devel cmake3 wget tar gzip make gcc-c++
$ wget https://github.com/aws/aws-sdk-cpp/archive/refs/tags/1.9.9.tar.gz
$ tar xfz 1.9.9.tar.gz
$ cd aws-sdk-cpp-1.9.9/
$ mkdir build
$ cd build
$ cmake3 .. -DBUILD_ONLY=s3 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=ON
-- TARGET_ARCH not specified; inferring host OS to be platform compilation target
-- Building AWS libraries as shared objects
-- Generating linux build config
-- Building project version: 1.9.9
-- The CXX compiler identification is GNU 7.3.1
-- 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
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.7")
-- Zlib library: /usr/lib64/libz.so
-- Encryption: Openssl
-- Found OpenSSL: /usr/lib64/libcrypto.so (found version "1.0.2k")
-- Openssl include directory: /usr/include
-- Openssl library: /usr/lib64/libssl.so;/usr/lib64/libcrypto.so
-- Http client: Curl
-- Found CURL: /usr/lib64/libcurl.so (found version "7.61.1")
-- Curl include directory: /usr/include
-- Curl library: /usr/lib64/libcurl.so
-- Performing Test HAVE_ATOMICS_WITHOUT_LIBATOMIC
-- Performing Test HAVE_ATOMICS_WITHOUT_LIBATOMIC - Success
CMake Error at CMakeLists.txt:184 (include):
include could not find load file:
AwsFindPackage
CMake Error at CMakeLists.txt:194 (add_subdirectory):
The source directory
/tmp/aws-sdk-cpp-1.9.9/crt/aws-crt-cpp
does not contain a CMakeLists.txt file.
-- Add s3-crt:s3 to C2J_SPECIAL_NAME_LIST
-- Considering s3
-- Looking for pathconf
-- Looking for pathconf - found
-- Looking for umask
-- Looking for umask - found
-- The C compiler identification is GNU 7.3.1
-- 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
-- Updating version info to 1.9.9
-- Custom memory management enabled; stl objects now using custom allocators
-- Performing Test CURL_HAS_H2
-- Performing Test CURL_HAS_H2 - Success
-- Performing Test CURL_HAS_TLS_PROXY
-- Performing Test CURL_HAS_TLS_PROXY - Success
CMake Error at aws-cpp-sdk-core/CMakeLists.txt:496 (aws_use_package):
Unknown CMake command "aws_use_package".
-- Configuring incomplete, errors occurred!
See also "/tmp/aws-sdk-cpp-1.9.9/build/CMakeFiles/CMakeOutput.log".
See also "/tmp/aws-sdk-cpp-1.9.9/build/CMakeFiles/CMakeError.log".
What is the correct solution to build aws-sdk-cpp on an Amazon Linux 2 system ?
Something changed in the past weeks, it worked fine for me before, now I got the same error as you.
Cloning with submodules fixed it for me:
$ git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp.git
(With version 2.13 of Git and later, --recurse-submodules can be used instead of --recursive)

cmake mingw-w64: strange error when trying to build

I have installed MinGW-w64 and built a simple Hello World Program. But the second time I run cmake --build . a strange error occurs.
When the Path variable is set to C:/MinGW/bin everything is fine and works. But when I set the Path to C:/msys64/mingw64/bin this happens:
PS C:\repos\hellovs\build> cmake ../ -G Ninja
-- The CXX compiler identification is GNU 10.1.0
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.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: C:/repos/hellovs/build
PS C:\repos\hellovs\build> cmake --build ./
[2/2] Linking CXX executable HelloVS.exe
PS C:\repos\hellovs\build> cmake --build ./
ninja: error: FindFirstFileExA(c/:/msys64/mingw64/include/c++/10.1.0): ╤шэЄръёшўхёър  ю°шсър т шьхэш Їрщыр, шьхэш яряъш шыш ьхЄъх Єюьр.
HelloVS.exe compiles normally the first time the build command is run.
Apparanteley Ninja tryies to use an invalid path. Any idea about how to fix this?
Seems like invalid dependencies have been generated:
PS C:\repos\hellovs\build> ninja -t recompact
PS C:\repos\hellovs\build> ninja -t deps
CMakeFiles/HelloVS.dir/main.cpp.obj: #deps 136, deps mtime 6109023486207704 (VALID)
../main.cpp
C/:/msys64/mingw64/include/c++/10.1.0/iostream
C/:/msys64/mingw64/include/c++/10.1.0/x86_64-w64-mingw32/bits/c++config.h
C/:/msys64/mingw64/include/c++/10.1.0/x86_64-w64-mingw32/bits/os_defines.h
C/:/msys64/mingw64/include/c++/10.1.0/x86_64-w64-mingw32/bits/cpu_defines.h
C/:/msys64/mingw64/include/c++/10.1.0/pstl/pstl_config.h
C/:/msys64/mingw64/include/c++/10.1.0/ostream
...
It's a GCC bug.
MSYS2 maintainers decided to not wait for the upstream and patched it.
Run pacman -Syuu from MSYS2 shell to update your packages.

Error on compile qml-material on windows

How to compile and install the qml-material on windows7 machine ?
First of all I clone and compile extra-cmake-modules like below:
git clone git://anongit.kde.org/extra-cmake-modules
cd extra-cmake-modules
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
After that I run the Make command but with no output!(No error and no change!)
And for compile the qml-material I use the below instruction:
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
But I get error:
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: C:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/bin/gcc.exe
-- Check for working C compiler: C:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/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:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/bin/g++.exe
-- Check for working CXX compiler: C:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at C:/Users/me/Documents/Github/ecm/ECMConfig.cmake:35 (include):
include could not find load file:
C:/Users/me/share/ECM/modules//ECMUseFindModules.cmake
Call Stack (most recent call first):
CMakeLists.txt:13 (find_package)
CMake Error at CMakeLists.txt:16 (include):
include could not find load file:
KDEInstallDirs
CMake Error at CMakeLists.txt:17 (include):
include could not find load file:
KDECMakeSettings
CMake Error at CMakeLists.txt:18 (include):
include could not find load file:
KDECompilerSettings
CMake Error at tests/CMakeLists.txt:1 (include):
include could not find load file:
ECMMarkAsTest
CMake Error at tests/CMakeLists.txt:13 (ecm_mark_as_test):
Unknown CMake command "ecm_mark_as_test".
-- Configuring incomplete, errors occurred!
I was try to use QtCreator to compile ECM and also the after that the qml-material, ECM compile and build fine without any error but the qml-material show above error too!!!
thanks,
I will provide my comment as an answer for a better overview:
To use qml-material it is not really necessary to "build" the project with cmake because the project itself contains only plain qml files.
I do not know why the guys switched from qmake to cmake system.
However all you need to do is to simply copy the file structure to your local file system:
checkout the project with git clone https://github.com/papyros/qml-material.git
copy the content of qml-material/modules/Material to Qt5.5.1/5.5/mingw/qml/Material and qml-material/modules/QtQuick/Controls/Styles/Material to Qt5.5.1/5.5/mingw/qml/QtQuick/Controls/Styles/Material where mingw stands for your Qt platform. Could also be gcc4.9 or something like this.
That`s all.

How to build flatbuffers on OSX?

I'm trying to build flatbuffers on OSX but I'm not sure how to proceed exactly. According to the doc. I should run cmake -G "Xcode". I did that and got the result:
-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: Temp/flatbuffers
However from there I'm not sure what to do. I've tried to run make but got the error message make: *** No targets specified and no makefile found. Stop.. Any idea how to build it?
When you ran cmake, you generated a project for the Xcode IDE (downloadable from the Apple app store).
If you want to build using make, use this command instead:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
After that,
make
should work as intended.
Instead make, just run following command in the shell:
$ cmakexbuild
After it finish you will get flatc in ./Debug folder.
On OSX it's recommended to use Homebrew to install the flatbuffer schema compiler.
brew install flatbuffers
Usage: Using the schema compiler
For Mac-OSX
Make sure Xcode is already installed in your machine. If not, install it by executing command xcode-select --install.
If you need latest changes download source code from repo or to get source code for a particular version download source from here
cd flatbuffers and execute cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release
If you encounter error like
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeOutput.log".
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeError.log".
Inside the log file CMakeError.log:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
then refer this SO thread
success message is :
-- Configuring done
-- Generating done
-- Build files have been written to: <source-code-path>/standalone/flatbuffers-1.12.0
./FlatBuffers.xcodeproj or open project in xcode
Build and Run project from Xcode UI
cd Debugand you can see all the binaries present.
If you want flatc to be available globally:
ln -sf <path>/flatbuffers-1.12.0/Debug/flatc /usr/local/bin/flatc
Tried and Tested on
MacOSX: Mojave, version: 10.14.3, 10.14.6
Xcode: Version: 10.2.1(10E1001), 11.1(11A1027)
Note: Make sure you use the same version in a project for compatibility.
If you are not sure which version to pick, then you can clone the repo and go to a specific commit and build.
For e.g. For version 1.11, Commit version is bf9eb67a.
Follow the below steps to compile the flatbuffer code
Clone the Flatbuffer repo using - git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles"
make
FlatBuffers for LINUX(Ubuntu 16) install and build:
cd root project folder
yarn add flatc
cd node_modules of project
rm flatbuffers folder(if exist)
git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles" (install cmake if need)
make
cd root project folder
change path in command in package.json file from "./flatc" to "./node_modules/flatbuffers/flatc"