Build using 0.5 libyaml-cpp-dev fails with boost errors - c++

I installed libyaml-cpp-dev via sudo apt install libyaml-cpp-dev and got yaml-cpp 0.5 version installed on my machine.
dpkg -s libyaml-cpp-dev | grep Version
Version: 0.5.2-4ubuntu1
Using this , I tried to build a testing code, demo.cpp as below:
#include <string>
#include "yaml-cpp/yaml.h"
int main(){
std::string config_file{"/home/freyr/exper/yamp-cpp/rvs.conf"};
YAML::Node config = YAML::LoadFile(config_file);
return 0;
}
with a cmake,
cmake_minimum_required (VERSION 2.8.11)
project (HELLO)
find_package(yaml-cpp REQUIRED)
add_executable (helloDemo demo.cpp)
include_directories(${YAML_CPP_INCLUDE_DIRS})
target_link_libraries(helloDemo ${YAML_CPP_LIBRARIES})
When I tried to build , I get below error:
make: Entering directory '/home/freyr/exper/yamp-cpp/build' make[1]: Entering directory '/home/freyr/exper/yamp-cpp/build' make[2]: Entering directory '/home/freyr/exper/yamp-cpp/build' Scanning dependencies of target helloDemo make[2]: Leaving directory '/home/freyr/exper/yamp-cpp/build' make[2]: Entering directory '/home/freyr/exper/yamp-cpp/build' [ 50%] Building CXX object CMakeFiles/helloDemo.dir/demo.cpp.o In file included from /usr/include/yaml-cpp/node/iterator.h:13:0,
from /usr/include/yaml-cpp/node/impl.h:11,
from /usr/include/yaml-cpp/yaml.h:17,
from /home/freyr/exper/yamp-cpp/demo.cpp:3: /usr/include/yaml-cpp/node/detail/iterator.h: In member function ‘void YAML::detail::iterator_base<V>::increment()’: /usr/include/yaml-cpp/node/detail/iterator.h:48:54: error: ‘next’ is not a member of ‘boost’ void increment() { this->base_reference() = boost::next(this->base()); }
^~~~ /usr/include/yaml-cpp/node/detail/iterator.h:48:54: note: suggested alternatives: In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
from /usr/include/c++/7/bits/char_traits.h:39,
from /usr/include/c++/7/ios:40,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from /home/freyr/exper/yamp-cpp/demo.cpp:1: /usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note: ‘std::next’
next(_ForwardIterator __x, typename
^~~~ In file included from /usr/local/include/boost/mpl/next.hpp:17:0,
from /usr/local/include/boost/mpl/bind.hpp:25,
from /usr/local/include/boost/mpl/lambda.hpp:18,
from /usr/local/include/boost/mpl/apply.hpp:25,
from /usr/local/include/boost/iterator/iterator_facade.hpp:36,
from /usr/include/yaml-cpp/node/detail/node_iterator.h:12,
from /usr/include/yaml-cpp/node/detail/iterator.h:12,
from /usr/include/yaml-cpp/node/iterator.h:13,
from /usr/include/yaml-cpp/node/impl.h:11,
from /usr/include/yaml-cpp/yaml.h:17,
from /home/freyr/exper/yamp-cpp/demo.cpp:3: /usr/local/include/boost/mpl/next_prior.hpp:29:8: note: ‘boost::mpl::next’ struct next
^~~~ CMakeFiles/helloDemo.dir/build.make:62: recipe for target 'CMakeFiles/helloDemo.dir/demo.cpp.o' failed make[2]: *** [CMakeFiles/helloDemo.dir/demo.cpp.o] Error 1 make[2]: Leaving directory '/home/freyr/exper/yamp-cpp/build' CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/helloDemo.dir/all' failed make[1]: *** [CMakeFiles/helloDemo.dir/all] Error 2 make[1]: Leaving directory '/home/freyr/exper/yamp-cpp/build' Makefile:83: recipe for target 'all' failed make: *** [all] Error 2
I see in latest https://github.com/jbeder/yaml-cpp/blob/master/include/yaml-cpp/node/detail/iterator.h there are no references to boost ad it is all std c++ alone.
How do I install latest version of libyaml-cpp-dev which has no boost dependencies ? I dont want to build and install from latest version as git cloning from master every time will not be a very secure practice.

yaml-cpp introduced boost dependency in version 0.5 and removed it in version 0.6. You need to upgrade your Ubuntu to a newer release or install yaml-cpp from sources, or install a version of yaml-cpp older than 0.5.
See: https://yaml-cpp.docsforge.com/#how-to-build
yaml-cpp 0.6.0 has been released! This release requires C++11, and no longer depends on Boost.
See also https://www.ubuntuupdates.org/package/core/hirsute/main/base/yaml-cpp - the current version of yaml-cpp in Ubuntu 21.4 is 0.6.3-9ubuntu1

Related

Compiler Error k4a-calibration Aruco dictionary is protected

Project Link: https://github.com/stytim/k4a-calibration
I want to run the project but it can't compile
Error message
[ 33%] Building CXX object CMakeFiles/calib_k4a.dir/src/camera_extrinsics.cpp.o
/home/ccnam/Downloads/k4a-calibration/src/camera_extrinsics.cpp: In member function ‘bool ExtrinsicsCalibration::CalculateExtrinsics(const std::vector<FrameInfo>&, std::vector<AlignmentTransform>&)’:
/home/ccnam/Downloads/k4a-calibration/src/camera_extrinsics.cpp:213:51: error: ‘cv::Ptr<cv::aruco::Dictionary> cv::aruco::Board::dictionary’ is protected within this context
cv::aruco::detectMarkers(gray, board->dictionary, markerCorners, markerIds, params);
^~~~~~~~~~
In file included from /usr/local/include/opencv4/opencv2/aruco_detector.hpp:6:0,
from /usr/local/include/opencv4/opencv2/aruco.hpp:7,
from /usr/local/include/opencv4/opencv2/aruco/charuco.hpp:9,
from /home/ccnam/Downloads/k4a-calibration/include/camera_extrinsics.hpp:11,
from /home/ccnam/Downloads/k4a-calibration/src/camera_extrinsics.cpp:1:
/usr/local/include/opencv4/opencv2/aruco/board.hpp:89:29: note: declared protected here
CV_PROP Ptr<Dictionary> dictionary;
^~~~~~~~~~
CMakeFiles/calib_k4a.dir/build.make:75: recipe for target 'CMakeFiles/calib_k4a.dir/src/camera_extrinsics.cpp.o' failed
make[2]: *** [CMakeFiles/calib_k4a.dir/src/camera_extrinsics.cpp.o] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/calib_k4a.dir/all' failed
make[1]: *** [CMakeFiles/calib_k4a.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
Step
git clone https://github.com/stytim/k4a-calibration.git
cd k4a-calibration
mkdir build && cd build
cmake ..
make
Environment
Ubuntu 18.04
Change it to board->getDictionary(). When you use project dependencies with newer versions then you need to deal with the involved changes.

Using OPCUA Library in a New Cmake Project

In this time, I want to use Freeopcua to create a library to use in other project.
I have install all the tools in debian.soft file and build with following command sudo sh build.sh, cmake ., make, sudo make install. Although, in directory /usr/local/include and /usr/local/lib, there are opc directory and libopc*.so respectively, when I create a new cmake project, there is an error. Hope someone can help me or give some suggest. Thanks everyone~~~
I have refer to Libraries in /usr/local/lib not found, but it doesn't work for me
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(OPCUAIndependent)
include_directories(/usr/local/include/)
link_directories(/usr/local/lib/)
add_executable(sourceCode sourceCode.cpp)
target_link_libraries(sourceCode opc)
Error
[ 50%] Linking CXX executable sourceCode
/usr/bin/ld: cannot find -lopc
collect2: error: ld returned 1 exit status
CMakeFiles/sourceCode.dir/build.make:96: recipe for target 'sourceCode' failed
make[2]: *** [sourceCode] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/sourceCode.dir/all' failed
make[1]: *** [CMakeFiles/sourceCode.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

Cannot install OpenOnload on AWS Server

I am trying to install OpenOnload on an AWS server running Ubuntu server 18.04.3. I downloaded the DEB release package from version 7.1.0.265 (the latest) from here: https://support.solarflare.com/index.php/component/cognidox/?view=categories&id=361
and then extract out of it just the folder \onload_7.1.0.265-debiansource.tgz\onload_7.1.0.265.orig.tar.gz and untar that. Then I can run
$ ./scripts/onload_install
as per the instructions in the README file. On Ubuntu 20 on my local machine this all worked and installed OpenOnload fine but on an AWS server instance this error is thrown:
onload_install: Building Onload.
Build tree made for linux as x86_64_linux-4.15.0-1057-aws
make: Entering directory '/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws'
# Build both autocompat.h files: linux_net and linux_affinity.
make -C driver/linux_net
make[1]: Entering directory '/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net'
make -C /usr/src/linux-headers-4.15.0-1057-aws CC="cc" M=$(pwd)
make[2]: Entering directory '/usr/src/linux-headers-4.15.0-1057-aws'
/home/ubuntu/onload-7.1.0.265/src/driver/linux_net/Makefile:61: SFE4001/Falcon is no longer supported
CHK /home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/autocompat.h
UPD /home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/autocompat.h
CHK /home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/config.h
UPD /home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/config.h
CC [M] /home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.o
/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.c: In function ‘efx_init_struct’:
/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.c:5225:2: error: implicit declaration of function ‘efx_mtd_free’; did you mean ‘efx_mtd_probe’? [-Werror=implicit-function-declaration]
efx_mtd_free(efx);
^~~~~~~~~~~~
efx_mtd_probe
/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.c:5224:1: warning: label ‘fail’ defined but not used [-Wunused-label]
fail:
^~~~
/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.c: In function ‘efx_fini_struct’:
/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.c:5247:9: error: ‘struct efx_nic’ has no member named ‘mtd_struct’
if (efx->mtd_struct) {
^~
/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.c:5248:6: error: ‘struct efx_nic’ has no member named ‘mtd_struct’
efx->mtd_struct->efx = NULL;
^~
/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.c:5249:6: error: ‘struct efx_nic’ has no member named ‘mtd_struct’
efx->mtd_struct = NULL;
^~
cc1: some warnings being treated as errors
scripts/Makefile.build:330: recipe for target '/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.o' failed
make[3]: *** [/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net/efx.o] Error 1
Makefile:1580: recipe for target '_module_/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net' failed
make[2]: *** [_module_/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net] Error 2
make[2]: Leaving directory '/usr/src/linux-headers-4.15.0-1057-aws'
/home/ubuntu/onload-7.1.0.265/src/driver/linux_net/Makefile:300: recipe for target 'modules' failed
make[1]: *** [modules] Error 2
make[1]: Leaving directory '/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws/driver/linux_net'
../../src/mmake.mk:57: recipe for target 'all' failed
make: *** [all] Error 2
make: Leaving directory '/home/ubuntu/onload-7.1.0.265/build/x86_64_linux-4.15.0-1057-aws'
onload_build: ERROR: Failed to build driver components.
onload_install: ERROR: Build failed. Not installing.
Could this be due to incompatibility with some specific features on AWS? I checked the version compatibility for the downloaded source and it says compatible with Ubuntu server 18.04. Any ideas on how to fix it would be greatly appreciated!
Based on the comments.
The solution was to use Onload-7.0.0.176 instead of Onload-7.1.0.265.
Seems version Onload-7.1.0.265 has some compilation bugs on Ubuntu 18.04.

Build Bitcoin with cmake

I tried to compile bitcoin with cmake and I get the following error.
system info:
4.4.0-116-generic
cmake version 3.5.1
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)
CMakeLists.txt (Demo)
cmake_minimum_required(VERSION 2.8.12.2)
project(Bitcoin)
#set(CMAKE_CXX_STANDARD 11)
add_definitions(-std=c++11)
......
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
aux_source_directory(./src/ DIR_SRCS)
add_executable(bitcoin ${DIR_SRCS})
cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fyn/bitcoin
make
In file included from /usr/include/stdlib.h:42:0,
from /usr/include/c++/5/cstdlib:72,
from /usr/include/c++/5/ext/string_conversions.h:41,
from /usr/include/c++/5/bits/basic_string.h:5249,
from /usr/include/c++/5/string:52,
from /home/youwei/bitcoin/src/fs.h:9,
from /home/youwei/bitcoin/src/fs.cpp:1:
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:79:27: error: redeclaration of ‘unsigned int wait::<anonymous struct>::__w_retcode’
unsigned int __w_retcode:8;
^
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:74:27: note: previous declaration ‘unsigned int wait::<anonymous struct>::__w_retcode’
unsigned int __w_retcode:8; /* Return code if exited normally. */
^
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:80:28: error: redeclaration of ‘unsigned int wait::<anonymous struct>::__w_coredump’
unsigned int __w_coredump:1;
CMakeFiles/bitcoin.dir/build.make:86: recipe for target 'CMakeFiles/bitcoin.dir/src/fs.cpp.o' failed
make[2]: *** [CMakeFiles/bitcoin.dir/src/fs.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/bitcoin.dir/all' failed
make[1]: *** [CMakeFiles/bitcoin.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
You are clearly missing some libaries. Run
./autogen.sh
./configure --with-gui=no --disable-wallet
and check the logs (which will tell you which libaries are missing)
Edit: I suggest to remove --with-gui=no --disable-wallet if you want to know full compability.
I also ran into problems compiling bitcoin, as it has a lot of dependencies but it turns out it has a depends system built in to tackle that issue. It's best to utilize it when compiling. So, from scratch:
clone the bitcoin repo and build the depends system:
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin/depends
make
Once this completes successfully, you'll see a new folder in the depends directory with the name corresponding to your environment, e.g. x86_64-pc-linux-gnu. Set the path to this folder when running ./configure from the repository's root folder using the --prefix flag and run make:
cd ..
./autogen.sh
./configure --prefix=`pwd`/depends/x86_64-pc-linux-gnu
make

ROS rosmake error

I am currently working on a project with ROS. I am completely new to ROS and it's features. Currently i'm doing a tutorial on ROS and started using code for the first time. although i do have some experience with c++, i can't figure out what is going wrong. In ROS i use the rosmake command and it fails to compile the cpp file/code. Can anyone help me figure out why the error occurs? (and possibly how to fix it?)
below is the cpp file code:
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "example1_a");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_
msgs::String>("message", 1000);
ros::Rate loop_rate(10);
while (ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss << " I am the example1_a node ";
msg.data = ss.str();
//ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
And here the build log:
mkdir -p bin
cd build && cmake -Wdev -DCMAKE_TOOLCHAIN_FILE=/opt/ros/indigo/share/ros/core/rosbuild/rostoolchain.cmake ..
[rosbuild] Building package chapter2_tutorials
[rosbuild] using multiarch 'x86_64-linux-gnu' for finding Boost
-- Using CATKIN_DEVEL_PREFIX: /home/rospc/dev/rosbook/chapter2_tutorials/build/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/indigo
-- This workspace overlays: /opt/ros/indigo
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Skip enable_testing() for dry packages
-- Using CATKIN_TEST_RESULTS_DIR: /home/rospc/dev/rosbook/chapter2_tutorials/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.16
-- Using these message generators: gencpp;genlisp;genpy
[rosbuild] Including /opt/ros/indigo/share/roslisp/rosbuild/roslisp.cmake
[rosbuild] Including /opt/ros/indigo/share/roscpp/rosbuild/roscpp.cmake
[rosbuild] Including /opt/ros/indigo/share/rospy/rosbuild/rospy.cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rospc/dev/rosbook/chapter2_tutorials/build
cd build && make -j8 -l8
make[1]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[2]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[ 0%] Built target rospack_genmsg_libexe
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[ 0%] Built target rosbuild_precompile
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
Scanning dependencies of target example1_a
Scanning dependencies of target example1_b
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[3]: Entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[100%] [100%] Building CXX object CMakeFiles/example1_b.dir/src/example1_b.cpp.o
Building CXX object CMakeFiles/example1_a.dir/src/example1_a.cpp.o
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp: In function ‘int main(int, char**)’:
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:8:42: error: ‘std_’ was not declared in this scope
ros::Publisher chatter_pub = n.advertise<std_
^
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:8:32: error: parse error in template argument list
ros::Publisher chatter_pub = n.advertise<std_
^
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: no matching function for call to ‘ros::NodeHandle::advertise(const char [8], int)’
msgs::String>("message", 1000);
^
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: note: candidates are:
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
from /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:1:
/opt/ros/indigo/include/ros/node_handle.h:236:15: note: template<class M> ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool)
Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false)
^
/opt/ros/indigo/include/ros/node_handle.h:236:15: note: template argument deduction/substitution failed:
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: template argument 1 is invalid
msgs::String>("message", 1000);
^
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
from /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:1:
/opt/ros/indigo/include/ros/node_handle.h:302:13: note: template<class M> ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, const SubscriberStatusCallback&, const SubscriberStatusCallback&, const VoidConstPtr&, bool)
Publisher advertise(const std::string& topic, uint32_t queue_size,
^
/opt/ros/indigo/include/ros/node_handle.h:302:13: note: template argument deduction/substitution failed:
/home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: template argument 1 is invalid
msgs::String>("message", 1000);
^
make[3]: *** [CMakeFiles/example1_a.dir/src/example1_a.cpp.o] Error 1
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[2]: *** [CMakeFiles/example1_a.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
Linking CXX executable ../bin/example1_b
make[3]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
[100%] Built target example1_b
make[2]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build'
make: *** [all] Error 2
This next code is from the second file, which does compile and creates no errors:
#include "ros/ros.h"
#include "std_msgs/String.h"
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "example1_b");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("message", 1000, chatterCallback);
ros::spin();
return 0;
}
Line breaks in C++ code can only be done in 3 ways :
cout<<"Error:This is a really long error "
"message that exceeds the maximum permitted length.\n";
or
cout<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";
or
c\
o\
u\
t<<"Error:This is a really long error \
message that exceeds the maximum permitted length.\n";
other than that, it will throw you errors ...
Change:
ros::Publisher chatter_pub = n.advertise<std_
msgs::String>("message", 1000);
By:
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("message", 1000);
PS : You should not use rosmake. It's an old tool to build your workspace.
Use catkin_make or catkin build.
Note: You can't use both catkin_make and catkin build on the same workspace. If you want to switch you need to clean your workspace. For that it's easy, you have to erase your build, devel and install directory in your workspace folder.
$ cd ~/catkin_ws
$ sudo rm -r devel build install
Alternative ways :
If you use catkin_make and want to clean your workspace to switch to catkin build use
$ catkin_make clean
$ catkin build
If you use catkin build and want to clean your workspace to switch to catkin_make use
$ catkin clean
$ catkin_make
rosmake vs catkin:
Since ROS Groovy, it's not recommended to use rosmake, here is why we use catkin:
Make better use of all tools provided by Cmake,
Cmake's C means Cross Platform. The idea is to make ROS more portable on different architectures (ARM) and OS (OS X and Windows).
With rosbuild each package had its own Cmake, package dependency management was less stable.
Cmake can compile smarter by parallelizing dependencies.
Reduce memory space by optimizing dependencies.
A single installation target which allows companies to run closed and proprietary software on ROS.
catkin_make vs catkin build:
Quite the same, but the most recent catkin build. Nowadays, some people recommend to switch from catkin_make to catkin build. The main difference between both is that catkin build has a better isolation package. It will build each package a workspace.
Use C++11 for make your project.
For this use the cmake flag in your command:
catkin_make -DCMAKE_CXX_FLAGS=-std=c++11
Or
catkin build -DCMAKE_CXX_FLAGS=-std=c++11