Hi I followed the exact step by step procedure suggested at https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html to build the cartographer package. I came to the build and install step without any problems. when i use this command "catkin_make_isolated --install --use-ninja" i get an error and i couldn't figure it out for days.
The error I get is as follows.
Base path: /home/pi/elk_ws
Source space: /home/pi/elk_ws/src
Build space: /home/pi/elk_ws/build_isolated
Devel space: /home/pi/elk_ws/devel_isolated
Install space: /home/pi/elk_ws/install_isolated
Additional make Arguments: -l4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~ traversing 15 packages in topological order:
~~ - actionlib_msgs
~~ - cartographer (plain cmake)
~~ - common_msgs
~~ - diagnostic_msgs
~~ - geometry_msgs
~~ - cartographer_ros_msgs
~~ - nav_msgs
~~ - sensor_msgs
~~ - rplidar_ros
~~ - shape_msgs
~~ - stereo_msgs
~~ - trajectory_msgs
~~ - visualization_msgs
~~ - cartographer_ros
~~ - cartographer_rviz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==> Processing catkin package: 'actionlib_msgs'
build.ninja exists, skipping explicit cmake invocation...
==> ninja build.ninja in '/home/pi/elk_ws/build_isolated/actionlib_msgs'
ninja: no work to do.
==> ninja -l4 in '/home/pi/elk_ws/build_isolated/actionlib_msgs'
[3/3] cd /home/pi/elk_ws/build_isolated/actionlib_msgs && /home/pi/elk_ws/build_isolated/actionlib_msgs/catkin_genera..._check_deps.py actionlib_msgs /home/pi/elk_ws/src/common_msgs/actionlib_msgs/msg/GoalStatus.msg actionlib_msgs/GoalID
==> ninja install in '/home/pi/elk_ws/build_isolated/actionlib_msgs'
[3/4] Install the project...
-- Install configuration: ""
-- Up-to-date: /home/pi/elk_ws/install_isolated/_setup_util.py
-- Up-to-date: /home/pi/elk_ws/install_isolated/env.sh
-- Up-to-date: /home/pi/elk_ws/install_isolated/setup.bash
-- Up-to-date: /home/pi/elk_ws/install_isolated/local_setup.bash
-- Up-to-date: /home/pi/elk_ws/install_isolated/setup.sh
-- Up-to-date: /home/pi/elk_ws/install_isolated/local_setup.sh
-- Up-to-date: /home/pi/elk_ws/install_isolated/setup.zsh
-- Up-to-date: /home/pi/elk_ws/install_isolated/local_setup.zsh
-- Up-to-date: /home/pi/elk_ws/install_isolated/.rosinstall
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/msg/GoalID.msg
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/msg/GoalStatus.msg
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/msg/GoalStatusArray.msg
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/cmake/actionlib_msgs-msg-paths.cmake
-- Up-to-date: /home/pi/elk_ws/install_isolated/include/actionlib_msgs
-- Up-to-date: /home/pi/elk_ws/install_isolated/include/actionlib_msgs/GoalStatus.h
-- Up-to-date: /home/pi/elk_ws/install_isolated/include/actionlib_msgs/GoalStatusArray.h
-- Up-to-date: /home/pi/elk_ws/install_isolated/include/actionlib_msgs/GoalID.h
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/roseus/ros/actionlib_msgs
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/roseus/ros/actionlib_msgs/msg
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/roseus/ros/actionlib_msgs/msg/GoalStatusArray.l
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/roseus/ros/actionlib_msgs/msg/GoalStatus.l
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/roseus/ros/actionlib_msgs/msg/GoalID.l
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/roseus/ros/actionlib_msgs/manifest.l
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/_package_GoalStatus.lisp
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/_package_GoalID.lisp
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/_package_GoalStatusArray.lisp
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/GoalStatusArray.lisp
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/actionlib_msgs-msg.asd
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/GoalStatus.lisp
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/_package.lisp
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/common-lisp/ros/actionlib_msgs/msg/GoalID.lisp
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/gennodejs/ros/actionlib_msgs
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/gennodejs/ros/actionlib_msgs/_index.js
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/gennodejs/ros/actionlib_msgs/msg
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/gennodejs/ros/actionlib_msgs/msg/_index.js
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/gennodejs/ros/actionlib_msgs/msg/GoalID.js
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/gennodejs/ros/actionlib_msgs/msg/GoalStatusArray.js
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/gennodejs/ros/actionlib_msgs/msg/GoalStatus.js
Listing /home/pi/elk_ws/devel_isolated/actionlib_msgs/lib/python2.7/dist-packages/actionlib_msgs ...
Listing /home/pi/elk_ws/devel_isolated/actionlib_msgs/lib/python2.7/dist-packages/actionlib_msgs/msg ...
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/__init__.py
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/__init__.py
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/_GoalStatusArray.pyc
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/_GoalID.pyc
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/_GoalID.py
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/_GoalStatus.pyc
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/_GoalStatusArray.py
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/_GoalStatus.py
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/msg/__init__.pyc
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/python2.7/dist-packages/actionlib_msgs/__init__.pyc
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/pkgconfig/actionlib_msgs.pc
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/cmake/actionlib_msgs-msg-extras.cmake
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/cmake/actionlib_msgs-extras.cmake
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/cmake/actionlib_msgsConfig.cmake
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/cmake/actionlib_msgsConfig-version.cmake
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/package.xml
-- Up-to-date: /home/pi/elk_ws/install_isolated/lib/actionlib_msgs/genaction.py
-- Up-to-date: /home/pi/elk_ws/install_isolated/share/actionlib_msgs/cmake/actionbuild.cmake
<== Finished processing package [1 of 15]: 'actionlib_msgs'
==> Processing plain cmake package: 'cartographer'
==> Building with env: '/home/pi/elk_ws/install_isolated/env.sh'
build.ninja exists, skipping explicit cmake invocation...
==> ninja build.ninja in '/home/pi/elk_ws/build_isolated/cartographer/install'
ninja: no work to do.
==> ninja -l4 in '/home/pi/elk_ws/build_isolated/cartographer/install'
[1/117] Linking CXX executable cartographer_pbstream
FAILED: cartographer_pbstream
: && /usr/bin/c++ -O3 -DNDEBUG -rdynamic CMakeFiles/cartographer_pbstream.dir/cartographer/io/pbstream_main.cc.o -o cartographer_pbstream -Wl,-rpath,/usr/local/lib: libcartographer.a /usr/lib/libceres.so.1.14.0 -lglog /usr/lib/arm-linux-gnueabihf/libgflags.so.2.2.2 -llua5.2 -lm -lboost_iostreams -lboost_regex -lglog /usr/lib/arm-linux-gnueabihf/libgflags.so.2.2.2 -lpthread -lcairo /usr/local/lib/libprotobuf.so /usr/local/lib/libabsl_leak_check.a /usr/local/lib/libabsl_hash.a /usr/local/lib/libabsl_bad_variant_access.a /usr/local/lib/libabsl_city.a /usr/local/lib/libabsl_raw_hash_set.a /usr/local/lib/libabsl_bad_optional_access.a /usr/local/lib/libabsl_hashtablez_sampler.a /usr/local/lib/libabsl_str_format_internal.a /usr/local/lib/libabsl_synchronization.a /usr/local/lib/libabsl_stacktrace.a /usr/local/lib/libabsl_graphcycles_internal.a /usr/local/lib/libabsl_symbolize.a /usr/local/lib/libabsl_malloc_internal.a /usr/local/lib/libabsl_debugging_internal.a /usr/local/lib/libabsl_demangle_internal.a /usr/local/lib/libabsl_time.a /usr/local/lib/libabsl_strings.a /usr/local/lib/libabsl_strings_internal.a /usr/local/lib/libabsl_throw_delegate.a /usr/local/lib/libabsl_base.a /usr/local/lib/libabsl_dynamic_annotations.a /usr/local/lib/libabsl_spinlock_wait.a -pthread /usr/local/lib/libabsl_int128.a /usr/local/lib/libabsl_civil_time.a /usr/local/lib/libabsl_time_zone.a -lpthread && :
/usr/bin/ld: /usr/local/lib/libabsl_spinlock_wait.a(spinlock_wait.cc.o): undefined reference to symbol '__atomic_load_8##LIBATOMIC_1.0'
/usr/bin/ld: //lib/arm-linux-gnueabihf/libatomic.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
[6/117] Building CXX object CMakeFiles/cartographer.mapping.internal.3d.scan_matching.real_time_correlative_scan_matcher_3d_test.dir/cartographer/mapping/internal/3d/scan_matching/real_time_correlative_scan_matcher_3d_test.cc.o
ninja: build stopped: subcommand failed.
<== Failed to process package 'cartographer':
Command '['/home/pi/elk_ws/install_isolated/env.sh', 'ninja', '-l4']' returned non-zero exit status 1
Reproduce this error by running:
==> cd /home/pi/elk_ws/build_isolated/cartographer && /home/pi/elk_ws/install_isolated/env.sh ninja -l4
Command failed, exiting.
any help would be great. i am using raspberrypi 4b and rasbian buster OS. I installed ROS kinetic.
You can change the cartographer CMakeLists.txt to force the link flag and include the necessary libraries.
In src/cartographer/CMakeLists.txt and _src/cartographer_ros/cartographer_ros/CMakeLists.txt add the link set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic") to where the other flags are set.
Related
I have installed ROS noetic on raspian buster but it get gives error when this command is implemented as per the procedure mentioned in
http://wiki.ros.org/noetic/Installation/Source
./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release
It succesfully goes till 61 ros packages and gives a cmake error at 'rosconsole'
The error goes like this
==> Processing catkin package: 'rosconsole'
==> Building with env: '/home/pi/ros_catkin_ws/install_isolated/env.sh'
==> cmake /home/pi/ros_catkin_ws/src/rosconsole -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/rosconsole -DCMAKE_INSTALL_PREFIX=/home/pi/ros_catkin_ws/install_isolated -DCMAKE_BUILD_TYPE=Release-DPYTHON_EXECUTABLE=/usr/bin/python3 -G Unix Makefiles in '/home/pi/ros_catkin_ws/build_isolated/rosconsole'
-- Using CATKIN_DEVEL_PREFIX: /home/pi/ros_catkin_ws/devel_isolated/rosconsole
-- Using CMAKE_PREFIX_PATH: /home/pi/ros_catkin_ws/install_isolated
-- This workspace overlays: /home/pi/ros_catkin_ws/install_isolated
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.7.3", minimum required is "3")
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using Debian Python package layout
-- Using empy: /usr/lib/python3/dist-packages/em.py
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/pi/ros_catkin_ws/build_isolated/rosconsole/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python3 (found version "3.7.3")
-- Using Python nosetests: /usr/bin/nosetests3
-- catkin 0.8.10
-- BUILD_SHARED_LIBS is on
-- rosconsole backend: print
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:
LOG4CXX_LIBRARIES
linked by target "rosconsole-thread_test" in directory /home/pi/ros_catkin_ws/src/rosconsole
linked by target "rosconsole-utest" in directory /home/pi/ros_catkin_ws/src/rosconsole
-- Configuring incomplete, errors occurred!
See also "/home/pi/ros_catkin_ws/build_isolated/rosconsole/CMakeFiles/CMakeOutput.log".
See also "/home/pi/ros_catkin_ws/build_isolated/rosconsole/CMakeFiles/CMakeError.log".
<== Failed to process package 'rosconsole':
Command '['/home/pi/ros_catkin_ws/install_isolated/env.sh', 'cmake', '/home/pi/ros_catkin_ws/src/rosconsole', '-DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/rosconsole', '-DCMAKE_INSTALL_PREFIX=/home/pi/ros_catkin_ws/install_isolated', '-DCMAKE_BUILD_TYPE=Release-DPYTHON_EXECUTABLE=/usr/bin/python3', '-G', 'Unix Makefiles']' returned non-zero exit status 1.
Reproduce this error by running:
==> cd /home/pi/ros_catkin_ws/build_isolated/rosconsole && /home/pi/ros_catkin_ws/install_isolated/env.sh cmake /home/pi/ros_catkin_ws/src/rosconsole -DCATKIN_DEVEL_PREFIX=/home/pi/ros_catkin_ws/devel_isolated/rosconsole -DCMAKE_INSTALL_PREFIX=/home/pi/ros_catkin_ws/install_isolated -DCMAKE_BUILD_TYPE=Release-DPYTHON_EXECUTABLE=/usr/bin/python3 -G 'Unix Makefiles'
Command failed, exiting.
Tried every possible thing, cant resolve the issue.
In addition to this, rospy package is successfully installed and sourced but cant be imported. Is there any way i can import rospy, I am a total beginner. any help is appreciated. Rospy succussed installation log is as follows
==> Processing catkin package: 'rospy'
==> Building with env: '/home/pi/ros_catkin_ws/install_isolated/env.sh'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/pi/ros_catkin_ws/build_isolated/rospy'
==> make -j4 -l4 in '/home/pi/ros_catkin_ws/build_isolated/rospy'
==> make install in '/home/pi/ros_catkin_ws/build_isolated/rospy'
Install the project...
-- Install configuration: "Release-DPYTHON_EXECUTABLE=/usr/bin/python3"
-- Installing: /home/pi/ros_catkin_ws/install_isolated/_setup_util.py
-- Installing: /home/pi/ros_catkin_ws/install_isolated/env.sh
-- Installing: /home/pi/ros_catkin_ws/install_isolated/setup.bash
-- Installing: /home/pi/ros_catkin_ws/install_isolated/local_setup.bash
-- Installing: /home/pi/ros_catkin_ws/install_isolated/setup.sh
-- Installing: /home/pi/ros_catkin_ws/install_isolated/local_setup.sh
-- Installing: /home/pi/ros_catkin_ws/install_isolated/setup.zsh
-- Installing: /home/pi/ros_catkin_ws/install_isolated/local_setup.zsh
-- Installing: /home/pi/ros_catkin_ws/install_isolated/.rosinstall
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/lib/pkgconfig/rospy.pc
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/share/rospy/cmake/rospyConfig.cmake
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/share/rospy/cmake/rospyConfig-version.cmake
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/share/rospy/package.xml
+ cd /home/pi/ros_catkin_ws/src/ros_comm/rospy
+ mkdir -p /home/pi/ros_catkin_ws/install_isolated/lib/python3/dist-packages
+ /usr/bin/env PYTHONPATH=/home/pi/ros_catkin_ws/install_isolated/lib/python3/dist-packages:/home/pi/ros_catkin_ws/build_isolated/rospy/lib/python3/dist-packages:/home/pi/ros_catkin_ws/install_isolated/lib/python3/dist-packages CATKIN_BINARY_DIR=/home/pi/ros_catkin_ws/build_isolated/rospy /usr/bin/python3 /home/pi/ros_catkin_ws/src/ros_comm/rospy/setup.py egg_info --egg-base /home/pi/ros_catkin_ws/build_isolated/rospy build --build-base /home/pi/ros_catkin_ws/build_isolated/rospy install --root=/ --install-layout=deb --prefix=/home/pi/ros_catkin_ws/install_isolated --install-scripts=/home/pi/ros_catkin_ws/install_isolated/bin
running egg_info
writing /home/pi/ros_catkin_ws/build_isolated/rospy/rospy.egg-info/PKG-INFO
writing dependency_links to /home/pi/ros_catkin_ws/build_isolated/rospy/rospy.egg-info/dependency_links.txt
writing top-level names to /home/pi/ros_catkin_ws/build_isolated/rospy/rospy.egg-info/top_level.txt
reading manifest file '/home/pi/ros_catkin_ws/build_isolated/rospy/rospy.egg-info/SOURCES.txt'
writing manifest file '/home/pi/ros_catkin_ws/build_isolated/rospy/rospy.egg-info/SOURCES.txt'
running build
running build_py
running build_scripts
running install
running install_lib
running install_egg_info
removing '/home/pi/ros_catkin_ws/install_isolated/lib/python3/dist-packages/rospy-1.15.15.egg-info' (and everything under it)
Copying /home/pi/ros_catkin_ws/build_isolated/rospy/rospy.egg-info to /home/pi/ros_catkin_ws/install_isolated/lib/python3/dist-packages/rospy-1.15.15.egg-info
Skipping SOURCES.txt
running install_scripts
changing mode of /home/pi/ros_catkin_ws/install_isolated/bin/rosconsole to 755
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/share/rospy/rosbuild/rospy.cmake
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/share/rospy/rosbuild/scripts/genmsg_py.py
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/share/rospy/rosbuild/scripts/gensrv_py.py
-- Up-to-date: /home/pi/ros_catkin_ws/install_isolated/share/rospy/rosbuild/scripts/genutil.py
<== Finished processing package [54 of 184]: 'rospy'
I did
sudo apt update
sudo apt upgrade
tried the procedure from scratch twice from
Everytime it get stuck on this rosconsole package. All i want is to import rospy in script as i am modifying a script which uses rospy.
I'm getting the following error in cmake
[cmake] CMake Error in CMakeLists.txt:
[cmake] IMPORTED_LOCATION not set for imported target "fmt::fmt" configuration
[cmake] "Debug".
I've installed fmtlib
$ sudo cmake --install . --config Debug
-- Installing: /usr/local/lib/libfmt.so.9.1.1
-- Installing: /usr/local/lib/libfmt.so.9
-- Installing: /usr/local/lib/libfmt.so
-- Installing: /usr/local/include/fmt/args.h
-- Installing: /usr/local/include/fmt/chrono.h
-- Installing: /usr/local/include/fmt/color.h
-- Installing: /usr/local/include/fmt/compile.h
-- Installing: /usr/local/include/fmt/core.h
-- Installing: /usr/local/include/fmt/format.h
-- Installing: /usr/local/include/fmt/format-inl.h
-- Installing: /usr/local/include/fmt/os.h
-- Installing: /usr/local/include/fmt/ostream.h
-- Installing: /usr/local/include/fmt/printf.h
-- Installing: /usr/local/include/fmt/ranges.h
-- Installing: /usr/local/include/fmt/std.h
-- Installing: /usr/local/include/fmt/xchar.h
-- Installing: /usr/local/lib/cmake/fmt/fmt-config.cmake
-- Installing: /usr/local/lib/cmake/fmt/fmt-config-version.cmake
-- Installing: /usr/local/lib/cmake/fmt/fmt-targets.cmake
-- Installing: /usr/local/lib/pkgconfig/fmt.pc
Here's my CMakeLists.txt:
cmake_minimum_required (VERSION 3.20)
project (Test)
set(CMAKE_CXX_STANDARD 23)
add_executable(main main.cpp)
find_package(fmt)
target_link_libraries(main fmt::fmt)
Reinstalling without the debug config got it working:
$ sudo cmake --install .
I'm trying to build an environment for a tool that requires spacy 1.9.0 with below commands
python3 -m venv errant_env
source errant_env/bin/activate
pip3 install -U pip wheel
pip3 install -U spacy==1.9.0
python3 -m spacy download en
and getting the following messages. How can I solve this?
Collecting spacy==1.9.0
Cache entry deserialization failed, entry ignored
Using cached https://files.pythonhosted.org/packages/63/ce/afee53c365617e5f3e58825d71421bce14949a15f7150742d2a7b8859c53/spacy-1.9.0.tar.gz
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: numpy>=1.7 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: murmurhash<0.27,>=0.26 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: cymem<1.32,>=1.30 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: preshed<2.0.0,>=1.0.0 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Collecting thinc<6.6.0,>=6.5.0 (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Using cached https://files.pythonhosted.org/packages/f7/9b/78fab962e0c8b55e3a745ebf2458708dfc7922c55eca3a9bff0233b25294/thinc-6.5.2.tar.gz
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: plac<1.0.0,>=0.9.6 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: pip<10.0.0,>=9.0.0 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: six in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: pathlib in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: ujson>=1.35 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: dill<0.3,>=0.2 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: requests<3.0.0,>=2.13.0 in ./errant_env/lib/python3.8/site-packages (from spacy==1.9.0)
Collecting regex<2017.12.1,>=2017.4.1 (from spacy==1.9.0)
Collecting ftfy<5.0.0,>=4.4.2 (from spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: wrapt in ./errant_env/lib/python3.8/site-packages (from thinc<6.6.0,>=6.5.0->spacy==1.9.0)
Requirement already up-to-date: tqdm<5.0.0,>=4.10.0 in ./errant_env/lib/python3.8/site-packages (from thinc<6.6.0,>=6.5.0->spacy==1.9.0)
Collecting cytoolz<0.9,>=0.8 (from thinc<6.6.0,>=6.5.0->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Using cached https://files.pythonhosted.org/packages/0f/e6/ccc124714dcc1bd511e64ddafb4d5d20ada2533b92e3173a4cf09e0d0831/cytoolz-0.8.2.tar.gz
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: termcolor in ./errant_env/lib/python3.8/site-packages (from thinc<6.6.0,>=6.5.0->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: urllib3<1.27,>=1.21.1 in ./errant_env/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: idna<4,>=2.5 in ./errant_env/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: certifi>=2017.4.17 in ./errant_env/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: charset-normalizer<3,>=2 in ./errant_env/lib/python3.8/site-packages (from requests<3.0.0,>=2.13.0->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: html5lib in ./errant_env/lib/python3.8/site-packages (from ftfy<5.0.0,>=4.4.2->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: wcwidth in ./errant_env/lib/python3.8/site-packages (from ftfy<5.0.0,>=4.4.2->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: toolz>=0.8.0 in ./errant_env/lib/python3.8/site-packages (from cytoolz<0.9,>=0.8->thinc<6.6.0,>=6.5.0->spacy==1.9.0)
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: webencodings in ./errant_env/lib/python3.8/site-packages (from html5lib->ftfy<5.0.0,>=4.4.2->spacy==1.9.0)
Building wheels for collected packages: spacy, thinc, cytoolz
Running setup.py bdist_wheel for spacy: started
Running setup.py bdist_wheel for spacy: finished with status 'error'
Complete output from command /project/cl-work2/yusuke/projects/context_aware_gec/errant_env/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-8i5m5103/spacy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpruswh00zpip-wheel- --python-tag cp38:
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/spacy
copying spacy/compat.py -> build/lib.linux-x86_64-3.8/spacy
copying spacy/lemmatizer.py -> build/lib.linux-x86_64-3.8/spacy
copying spacy/__init__.py -> build/lib.linux-x86_64-3.8/spacy
copying spacy/deprecated.py -> build/lib.linux-x86_64-3.8/spacy
copying spacy/__main__.py -> build/lib.linux-x86_64-3.8/spacy
...
copying spacy/tokens/__init__.pxd -> build/lib.linux-x86_64-3.8/spacy/tokens
copying spacy/tokens/token.pxd -> build/lib.linux-x86_64-3.8/spacy/tokens
copying spacy/tokens/doc.pxd -> build/lib.linux-x86_64-3.8/spacy/tokens
copying spacy/tokens/span.pxd -> build/lib.linux-x86_64-3.8/spacy/tokens
copying spacy/tests/tokenizer/sun.txt -> build/lib.linux-x86_64-3.8/spacy/tests/tokenizer
running build_ext
building 'spacy.parts_of_speech' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/spacy
gcc-11 -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -I/home/is/yusuke/.linuxbrew/opt/zlib -I/home/is/yusuke/.linuxbrew/include -I/home/is/yusuke/.linuxbrew/opt/zlib -I/home/is/yusuke/.linuxbrew/include -fPIC -I/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8 -I/tmp/pip-build-8i5m5103/spacy/include -I/project/cl-work2/yusuke/projects/context_aware_gec/errant_env/include -I/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8 -c spacy/parts_of_speech.cpp -o build/temp.linux-x86_64-3.8/spacy/parts_of_speech.o -O3 -Wno-strict-prototypes -Wno-unused-function -fopenmp
cc1plus: warning: command-line option '-Wno-strict-prototypes' is valid for C/ObjC but not for C++
c++ -pthread -shared -L/home/is/yusuke/.linuxbrew/opt/readline/lib -L/home/is/yusuke/.pyenv/versions/3.8.13/lib -L/home/is/yusuke/.linuxbrew/lib -L/home/is/yusuke/.linuxbrew/opt/readline/lib -L/home/is/yusuke/.pyenv/versions/3.8.13/lib -L/home/is/yusuke/.linuxbrew/lib build/temp.linux-x86_64-3.8/spacy/parts_of_speech.o -o build/lib.linux-x86_64-3.8/spacy/parts_of_speech.cpython-38-x86_64-linux-gnu.so -fopenmp
building 'spacy.strings' extension
gcc-11 -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -I/home/is/yusuke/.linuxbrew/opt/zlib -I/home/is/yusuke/.linuxbrew/include -I/home/is/yusuke/.linuxbrew/opt/zlib -I/home/is/yusuke/.linuxbrew/include -fPIC -I/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8 -I/tmp/pip-build-8i5m5103/spacy/include -I/project/cl-work2/yusuke/projects/context_aware_gec/errant_env/include -I/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8 -c spacy/strings.cpp -o build/temp.linux-x86_64-3.8/spacy/strings.o -O3 -Wno-strict-prototypes -Wno-unused-function -fopenmp
cc1plus: warning: command-line option '-Wno-strict-prototypes' is valid for C/ObjC but not for C++
spacy/strings.cpp: In function 'PyObject* PyInit_strings()':
spacy/strings.cpp:5025:42: warning: '_typeobject::tp_print' is deprecated [-Wdeprecated-declarations]
5025 | __pyx_type_5spacy_7strings_StringStore.tp_print = 0;
| ^~~~~~~~
In file included from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/object.h:746,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/pytime.h:6,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/Python.h:85,
from spacy/strings.cpp:4:
/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/cpython/object.h:260:30: note: declared here
260 | Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
| ^~~~~~~~
spacy/strings.cpp:5025:42: warning: '_typeobject::tp_print' is deprecated [-Wdeprecated-declarations]
5025 | __pyx_type_5spacy_7strings_StringStore.tp_print = 0;
| ^~~~~~~~
In file included from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/object.h:746,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/pytime.h:6,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/Python.h:85,
from spacy/strings.cpp:4:
/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/cpython/object.h:260:30: note: declared here
260 | Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
| ^~~~~~~~
spacy/strings.cpp:5025:42: warning: '_typeobject::tp_print' is deprecated [-Wdeprecated-declarations]
5025 | __pyx_type_5spacy_7strings_StringStore.tp_print = 0;
| ^~~~~~~~
In file included from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/object.h:746,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/pytime.h:6,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/Python.h:85,
from spacy/strings.cpp:4:
/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/cpython/object.h:260:30: note: declared here
260 | Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
| ^~~~~~~~
spacy/strings.cpp:5080:59: warning: '_typeobject::tp_print' is deprecated [-Wdeprecated-declarations]
5080 | __pyx_type_5spacy_7strings___pyx_scope_struct____iter__.tp_print = 0;
| ^~~~~~~~
In file included from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/object.h:746,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/pytime.h:6,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/Python.h:85,
from spacy/strings.cpp:4:
/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/cpython/object.h:260:30: note: declared here
260 | Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
| ^~~~~~~~
spacy/strings.cpp:5080:59: warning: '_typeobject::tp_print' is deprecated [-Wdeprecated-declarations]
5080 | __pyx_type_5spacy_7strings___pyx_scope_struct____iter__.tp_print = 0;
| ^~~~~~~~
In file included from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/object.h:746,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/pytime.h:6,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/Python.h:85,
from spacy/strings.cpp:4:
/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/cpython/object.h:260:30: note: declared here
260 | Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
| ^~~~~~~~
spacy/strings.cpp:5080:59: warning: '_typeobject::tp_print' is deprecated [-Wdeprecated-declarations]
5080 | __pyx_type_5spacy_7strings___pyx_scope_struct____iter__.tp_print = 0;
| ^~~~~~~~
In file included from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/object.h:746,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/pytime.h:6,
from /home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/Python.h:85,
from spacy/strings.cpp:4:
/home/is/yusuke/.pyenv/versions/3.8.13/include/python3.8/cpython/object.h:260:30: note: declared here
260 | Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
| ^~~~~~~~
spacy/strings.cpp: In function 'void __Pyx_ExceptionSwap(PyObject**, PyObject**, PyObject**)':
spacy/strings.cpp:7228:24: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'exc_type'; did you mean 'curexc_type'?
7228 | tmp_type = tstate->exc_type;
| ^~~~~~~~
| curexc_type
spacy/strings.cpp:7229:25: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'exc_value'; did you mean 'curexc_value'?
7229 | tmp_value = tstate->exc_value;
| ^~~~~~~~~
| curexc_value
spacy/strings.cpp:7230:22: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'exc_traceback'; did you mean 'curexc_traceback'?
7230 | tmp_tb = tstate->exc_traceback;
| ^~~~~~~~~~~~~
| curexc_traceback
spacy/strings.cpp:7231:13: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'exc_type'; did you mean 'curexc_type'?
7231 | tstate->exc_type = *type;
| ^~~~~~~~
| curexc_type
spacy/strings.cpp:7232:13: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'exc_value'; did you mean 'curexc_value'?
7232 | tstate->exc_value = *value;
| ^~~~~~~~~
| curexc_value
spacy/strings.cpp:7233:13: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'exc_traceback'; did you mean 'curexc_traceback'?
7233 | tstate->exc_traceback = *tb;
| ^~~~~~~~~~~~~
| curexc_traceback
error: command 'gcc-11' failed with exit status 1
----------------------------------------
Failed building wheel for spacy
Running setup.py clean for spacy
Running setup.py bdist_wheel for thinc: started
Because I found some advice recommending to do so, I installed with linuxbrew libxml2 and libxslt. But this didn't change the situation.
Also, I confirmed that gcc-11 exists at $HOME/.linuxbrew/bin/gcc-11 with which gcc-11.
My environments are:
Ubuntu 18.04.6
Python 3.8.13
I am trying to write a Yocto recipe for an in-house library that uses cmake to build and install itself. Running make install from the command line, the library installs the following files (headers are somewhat abridged):
-- Installing: /prefix/lib/libreflection.so
-- Installing: /prefix/lib/libreflection.a
-- Installing: /prefix/include/reflect
-- Installing: /prefix/include/reflect/type.h
-- Installing: /prefix/include/reflect/detail
-- Installing: /prefix/include/reflect/detail/type.h
-- Installing: /prefix/include/reflect/detail/property.h
-- Installing: /prefix/include/reflect/detail/iterator
-- Installing: /prefix/include/reflect/detail/iterator/range.h
-- Installing: /prefix/include/reflect/detail/accessor.h
-- Installing: /prefix/include/reflect/property.h
-- Installing: /prefix/include/reflect/register.h
-- Installing: /prefix/include/reflect/object.h
-- Installing: /prefix/lib/cmake/libreflection/libreflection-config.cmake
-- Installing: /prefix/lib/cmake/libreflection/libreflection-config-noconfig.cmake
I would like to differentiate between a binary ".so only" Yocto package (libreflection) and a development version that additionally includes the static library, header and cmake package files (libreflection-dev).
My initial recipe is as follows, but with it both libreflection and libreflection-dev package all files:
DESCRIPTION = "C++ reflection library"
SECTION = "libs"
LICENSE = "CLOSED"
SRCREV = "${AUTOREV}"
SRCBRANCH = "master"
SRC_URI = "git://gitlab.company.com/group/${PN}.git;branch=${SRCBRANCH};protocol=ssh"
inherit cmake
S = "${WORKDIR}/git"
FILES_${PN}-dev += "${libdir}/cmake"
# The following are needed because the library is unversioned.
# See https://wiki.yoctoproject.org/wiki/TipsAndTricks/Packaging_Prebuilt_Libraries#Non-versioned_Libraries
SOLIBS = ".so"
FILES_SOLIBSDEV = ""
I have tried various changes to the FILES_${PN}* variables, but none have achieved the desired effect. Generally I either end up with packaging errors, or both libreflection and libreflection-dev include all files.
How can I adjust the recipe such that libreflection includes only the .so, and libreflection-dev includes all the files?
I am new to Cmake and Gtest. I have a problem with in CMake
find_package(GMock REQUIRED)
and
target_link_libraries(runtest ${GMOCK_BOTH_LIBRARIES} pthread).
When I build the project, CMake is unable find the GMock packages.
But when I mentioned the absolute paths of library, it is working fine.
For example:
set(GMOCK_INCLUDE_DIRS /usr/local/include/gmock)
set(GMOCK_BOTH_LIBRARIES /usr/local/lib/libgmock.a /usr/local/lib/libgmock_main.a /usr/local/lib/libgtest.a /usr/local/lib/libgtest_main.a)
Now the problem is my Supervisor recommended me to find the solution to run the code using find packages only. After doing some research, I came to know that FindGMock.cmake file is missing from the Cmake modules. I added it and run code again with find_package(), but still it is not working.
Errors are undefined references to functionalities of Gmock and Gtest.
For instance :
undefined reference to `testing::Message::Message()'.
undefined reference to testing::internal::GetBoolAssertionFailureMessage.
undefined reference totesting::internal::AssertHelper::~AssertHelper()'
Like this there too many errors.
Could anyone please explain me, how to make CMake to find the GMock packages automatically?
Here's a step-by-step example of building and linking to GMock from a CMake project on Linux from scratch. Steps 0-4 cover building and installing GMock while steps 5 and beyond address the question.
These steps are fairly generic and will work with little modification for any project that provides its own CMake package.
Step 0: Create a working directory
From my home folder, I created a blank directory called test:
alex:~$ mkdir test
alex:~$ cd test
alex:~/test$ ls
Step 1: Download GMock
GMock is included in the Google Test repository, so we clone that repository.
alex:~/test$ git clone https://github.com/google/googletest
Cloning into 'googletest'...
remote: Enumerating objects: 24427, done.
remote: Counting objects: 100% (92/92), done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 24427 (delta 44), reused 72 (delta 38), pack-reused 24335
Receiving objects: 100% (24427/24427), 10.32 MiB | 2.68 MiB/s, done.
Resolving deltas: 100% (18062/18062), done.
Step 2: Configure GMock
We'll use the following command to build the googletest repository; GMock is included by default.
$ cmake -S googletest/ -B _build/googletest -DCMAKE_BUILD_TYPE=RelWithDebInfo
The -S flag sets the source directory to the root of the Google Test repository we just cloned. This tells CMake which project it's building. The -B flag sets the binary directory to ~/test/_build/googletest, which is where CMake will store intermediate build outputs before they are installed. This should always be distinct from the source directory. Finally, since we are using a single-configuration generator (Make is the default on Linux), we must specify the build type at this time. I have chosen RelWithDebInfo to keep debugging easy, but also to enable optimizations.
In general, you should always build your project with in the same configuration as its dependencies, so we'll use RelWithDebInfo again later.
For more detail on how to configure generic CMake projects, I'll refer you to this question/answer: How do I build a CMake project?
Finally, here's the output of running the command:
alex:~/test$ cmake -S googletest/ -B _build/googletest -DCMAKE_BUILD_TYPE=RelWithDebInfo
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.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 Python: /usr/bin/python3.10 (found version "3.10.4") found components: Interpreter
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/_build/googletest
Step 3: Build GMock
Now we'll go ahead and run the build. The following command will work with any single-config generator:
alex:~/test$ cmake --build _build/googletest/
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 25%] Linking CXX static library ../lib/libgtest.a
[ 25%] Built target gtest
[ 37%] Building CXX object googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 50%] Linking CXX static library ../lib/libgmock.a
[ 50%] Built target gmock
[ 62%] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 75%] Linking CXX static library ../lib/libgmock_main.a
[ 75%] Built target gmock_main
[ 87%] Building CXX object googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library ../lib/libgtest_main.a
[100%] Built target gtest_main
The build should complete relatively quickly.
Step 4: Installing GMock
At this point, you could run sudo cmake --install _build/googletest/ to install it globally to /usr/local, but I wouldn't recommend this. It's much better to keep a frequently updated dependency like Google Test/GMock tied to the project that's using it.
Instead, we will install it to a project-local prefix, like so:
alex:~/test$ cmake --install _build/googletest/ --prefix _local
-- Install configuration: "RelWithDebInfo"
-- Installing: /home/alex/test/_local/include
-- Installing: /home/alex/test/_local/include/gmock
-- Installing: /home/alex/test/_local/include/gmock/gmock-matchers.h
-- Installing: /home/alex/test/_local/include/gmock/gmock-function-mocker.h
-- Installing: /home/alex/test/_local/include/gmock/internal
-- Installing: /home/alex/test/_local/include/gmock/internal/gmock-pp.h
-- Installing: /home/alex/test/_local/include/gmock/internal/gmock-internal-utils.h
-- Installing: /home/alex/test/_local/include/gmock/internal/gmock-port.h
-- Installing: /home/alex/test/_local/include/gmock/internal/custom
-- Installing: /home/alex/test/_local/include/gmock/internal/custom/gmock-port.h
-- Installing: /home/alex/test/_local/include/gmock/internal/custom/gmock-matchers.h
-- Installing: /home/alex/test/_local/include/gmock/internal/custom/gmock-generated-actions.h
-- Installing: /home/alex/test/_local/include/gmock/internal/custom/README.md
-- Installing: /home/alex/test/_local/include/gmock/gmock-more-actions.h
-- Installing: /home/alex/test/_local/include/gmock/gmock-more-matchers.h
-- Installing: /home/alex/test/_local/include/gmock/gmock-nice-strict.h
-- Installing: /home/alex/test/_local/include/gmock/gmock.h
-- Installing: /home/alex/test/_local/include/gmock/gmock-cardinalities.h
-- Installing: /home/alex/test/_local/include/gmock/gmock-spec-builders.h
-- Installing: /home/alex/test/_local/include/gmock/gmock-actions.h
-- Installing: /home/alex/test/_local/lib/libgmock.a
-- Installing: /home/alex/test/_local/lib/libgmock_main.a
-- Installing: /home/alex/test/_local/lib/pkgconfig/gmock.pc
-- Installing: /home/alex/test/_local/lib/pkgconfig/gmock_main.pc
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestTargets.cmake
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestTargets-relwithdebinfo.cmake
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestConfigVersion.cmake
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestConfig.cmake
-- Up-to-date: /home/alex/test/_local/include
-- Installing: /home/alex/test/_local/include/gtest
-- Installing: /home/alex/test/_local/include/gtest/gtest-param-test.h
-- Installing: /home/alex/test/_local/include/gtest/internal
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-port-arch.h
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-string.h
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-death-test-internal.h
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-type-util.h
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-port.h
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-internal.h
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-param-util.h
-- Installing: /home/alex/test/_local/include/gtest/internal/gtest-filepath.h
-- Installing: /home/alex/test/_local/include/gtest/internal/custom
-- Installing: /home/alex/test/_local/include/gtest/internal/custom/README.md
-- Installing: /home/alex/test/_local/include/gtest/internal/custom/gtest.h
-- Installing: /home/alex/test/_local/include/gtest/internal/custom/gtest-port.h
-- Installing: /home/alex/test/_local/include/gtest/internal/custom/gtest-printers.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-matchers.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-death-test.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-spi.h
-- Installing: /home/alex/test/_local/include/gtest/gtest.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-test-part.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-typed-test.h
-- Installing: /home/alex/test/_local/include/gtest/gtest_prod.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-assertion-result.h
-- Installing: /home/alex/test/_local/include/gtest/gtest_pred_impl.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-message.h
-- Installing: /home/alex/test/_local/include/gtest/gtest-printers.h
-- Installing: /home/alex/test/_local/lib/libgtest.a
-- Installing: /home/alex/test/_local/lib/libgtest_main.a
-- Installing: /home/alex/test/_local/lib/pkgconfig/gtest.pc
-- Installing: /home/alex/test/_local/lib/pkgconfig/gtest_main.pc
The --prefix flag tells cmake --install into which directory to install the project. Here, we've chosen a directory named _local in our working directory. The name of this folder is arbitrary. I've chosen this name to mirror the /usr/local prefix naming and to play nicely with a common .gitignore strategy of ignoring top-level directories prefixed with and underscore.
Notice in the command output what's getting installed. Headers, the GTest and GMock static libraries, yes, but also pkg-config files and, most importantly, the CMake package files:
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestTargets.cmake
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestTargets-relwithdebinfo.cmake
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestConfigVersion.cmake
-- Installing: /home/alex/test/_local/lib/cmake/GTest/GTestConfig.cmake
These are the files that find_package will use (soon) to load GTest into a dependent project. The two standard files are GTestConfig.cmake and GTestConfigVersion.cmake. The first one is the most important, and it's responsible for actually implementing the CMake package. It will ultimately load GTestTargets.cmake and GTestTargets-relwithdebinfo.cmake, which are specific to GTest. Notice also how RelWithDebInfo appears again in the generated file name; that's because config-specific information is stored there. If you want to support multiple configs, you'll need to redo steps 2-4 with a new CMAKE_BUILD_TYPE (e.g. Debug, Release, MinSizeRel)
Step 5: Creating an example project
Let's create a simple example project now that uses GMock. First, we'll create a directory for it:
alex:~/test$ mkdir example
and now we'll go in and create some files:
alex:~/test$ cd example/
alex:~/test/example$ touch CMakeLists.txt main.cpp
Using your favorite text editor, add the following contents to main.cpp:
#include <gmock/gmock.h>
using namespace testing;
struct Example : public Test {};
TEST_F(Example, AlwaysPass) { ASSERT_THAT(0, Eq(0)); }
TEST_F(Example, AlwaysFail) { ASSERT_THAT(0, Eq(1)); }
This is as basic of a "hello world" for GMock as I could come up with. It has one test that always passes and another that always fails (just so we can see the various outputs).
Now we'll write the build script in CMakeLists.txt:
cmake_minimum_required(VERSION 3.23)
project(example)
find_package(GTest REQUIRED)
add_executable(example main.cpp)
target_link_libraries(example PRIVATE GTest::gmock_main)
Once again, this is as simple as can be.
The first two lines are required boilerplate. They must always1 appear as the first two lines of your project, in that order, with nothing before or in between.
The first command, cmake_minimum_required, tells CMake which set of backwards-compatibility policies to enable. It does not put CMake into an emulation mode or anything like that. You must test your build with the version written there because CMake will not stop you from using features that are too new for the declared minimum version.
The second command, project, names your project and kicks off CMake's compiler detection routines.
Next, we tell CMake that this project depends on the GTest package by issuing find_package(GTest REQUIRED). The REQUIRED argument kills the configure step if the package cannot be found. The name GTest is derived from the GTestConfig.cmake file. For any CMake project XYZ, its main package file must be named either XYZConfig.cmake or XYZ-config.cmake.
Finally, we add our test executable example and link it to the target GTest::gmock_main. This target provides a main function in addition to the GMock standard library. If you want to write your own main, then link to GTest::gmock instead.
1. with very few exceptions that are hardly worth mentioning
Step 6: Building and running the example
Now we're finally ready to build and run the example. Let's go back up to our working directory:
alex:~/test/example$ cd ..
alex:~/test$
And now we'll go ahead and configure the build:
alex:~/test$ cmake -S example -B _build/example -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=$PWD/_local
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.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 GTest: /home/alex/test/_local/lib/cmake/GTest/GTestConfig.cmake (found version "1.11.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/_build/example
Note the -DCMAKE_PREFIX_PATH=$PWD/_local flag. That's telling CMake that there are additional libraries and CMake packages in $PWD/_local and so find_package and the other find_* commands should look there. If you didn't pass this flag, you might see an error like this:
CMake Error at /usr/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
/usr/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.23/Modules/FindGTest.cmake:270 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:4 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/alex/test/_build/example/CMakeFiles/CMakeOutput.log".
Now that we're configured, we can build the example:
alex:~/test$ cmake --build _build/example/
[ 50%] Building CXX object CMakeFiles/example.dir/main.cpp.o
[100%] Linking CXX executable example
[100%] Built target example
and then run it:
alex:~/test$ _build/example/example
Running main() from gmock_main.cc
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from Example
[ RUN ] Example.AlwaysPass
[ OK ] Example.AlwaysPass (0 ms)
[ RUN ] Example.AlwaysFail
/home/alex/test/example/main.cpp:8: Failure
Value of: 0
Expected: is equal to 1
Actual: 0 (of type int)
[ FAILED ] Example.AlwaysFail (0 ms)
[----------] 2 tests from Example (0 ms total)
[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.
[ FAILED ] 1 test, listed below:
[ FAILED ] Example.AlwaysFail
1 FAILED TEST
As you can see, our passing test passed, and our failing test failed, as expected!
Step 6: CTest integration (optional)
If we want, we can integrate this with CTest for easier running of multiple GMock binaries down the line. Here's the new CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
project(example)
enable_testing() # ------------------------ ADDED 1
find_package(GTest REQUIRED)
include(GoogleTest) # ------------------------ ADDED 2
add_executable(example main.cpp)
target_link_libraries(example PRIVATE GTest::gmock_main)
gtest_discover_tests(example) # ------------------------ ADDED 3
Aside from the three lines marked ADDED, nothing has changed. The first added line simply enables CTest support. The second added line imports CMake's native support for Google Test. Finally, the third line tells CTest that the example executable contains GTest tests.
After making these edits, an incremental build will automatically re-run CMake.
alex:~/test$ cmake --build _build/example/
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/_build/example
Consolidate compiler generated dependencies of target example
[ 50%] Linking CXX executable example
[100%] Built target example
And now we can use the CTest runner on our build directory:
alex:~/test$ ctest --test-dir _build/example/
Internal ctest changing into directory: /home/alex/test/_build/example
Test project /home/alex/test/_build/example
Start 1: Example.AlwaysPass
1/2 Test #1: Example.AlwaysPass ............... Passed 0.00 sec
Start 2: Example.AlwaysFail
2/2 Test #2: Example.AlwaysFail ...............***Failed 0.00 sec
50% tests passed, 1 tests failed out of 2
Total Test time (real) = 0.00 sec
The following tests FAILED:
2 - Example.AlwaysFail (Failed)
Errors while running CTest
Output from these tests are in: /home/alex/test/_build/example/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
And once again, we can see that our passing test passed and our failing test failed. Hooray!