I am a beginner in ROS.My operation system is Ubuntu 12.04 and my ROS is hydro.After I read some chapters about the "talker and listener" of The Beginner Tutorials in ROS.wiki,I try to write a publisher to publish message to topic "turtle1/com_vel" so that I can control the turtle to run round.But when I try to make my code,it fails.The terminal remind me that
CMake Error at /opt/ros/hydro/share/catkin/cmake/catkinConfig.cmake:72 (find_package):
Could not find a configuration file for package ros.
Set ros_DIR to the directory containing a CMake configuration file for ros.
The file will have one of the following names:
rosConfig.cmake
ros-config.cmake
I guess that there is something wrong with my CMakeLists.txt.But after comparing it with the demo in ROS.wiki,I still can't find the error.
This is my code in cpp file.In this file,I define a publisher named move_turtle.
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
int main( int argc, char** argv )
{
// initialization
ros::init(argc, argv, "move_turtle");
ros::NodeHandle n;
ros::Publisher move_pub = n.advertise<geometry_msgs::Twist>("turtle1/com_vel",100);
ros::Rate loop_rate(10);
//define the moving rule that I want.It is a circle.
geometry_msgs::Twist com_cicle;
com_cicle.linear.x=3.0;
com_cicle.linear.y=com_cicle.linear.z=0.0;
com_cicle.angular.x=com_cicle.angular.y=0.0;
com_cicle.angular.z=2.0;
while(ros::ok())
{
//publish the msg to topic /tuttle1/com_vel
move_pub.pulish(com_cicle);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
And my CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 2.8.3)
project(move_turtle)
find_package(catkin REQUIRED COMPONENTS
ros
geometry_msgs
turtlesim
)
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
)
## Declare a cpp executable
add_executable(move_turtle src/move_turtle.cpp)
## Specify libraries to link a library or executable target against
target_link_libraries(move_turtle ${catkin_LIBRARIES})
Oh...I used 'ros' instead of 'roscpp' in line 5 in 'CMakeLists.txt'.That was why it reminded me that there was no 'ros' package in my path.
Related
I'm trying to build a minimalist project using OpenCV in the browser.
I've compiled OpenCV on my computer.
Here is the C++ code (josef.cpp):
#include <iostrem>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv.hpp>
int main(int argc, char **argv)
{
printf("Hello here\n");
cv::Mat m;
std::cout << m;
}
Here is the CMakeLists.txt :
cmake_minimum_required(VERSION 2.8)
project( josef )
# Give here the directory in which we have
# the file OpenCVConfig.cmake
set(OpenCV_DIR "/usr/local/lib/cmake/opencv4")
find_package( OpenCV REQUIRED )
add_executable( josef josef.cpp )
target_link_libraries( josef ${OpenCV_LIBS} )
Compiling with
cmake .
make
works perfectly well and provides an executable which produces the expected result:
Hello here
[]
My problem arises when trying with emscripten.
emcmake cmake .
produces lot of warnings like that one:
CMake Warning (dev) at /usr/local/lib/cmake/opencv4/OpenCVModules.cmake:393 (add_library):
ADD_LIBRARY called with SHARED option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
Call Stack (most recent call first):
/usr/local/lib/cmake/opencv4/OpenCVConfig.cmake:126 (include)
CMakeLists.txt:7 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
Then
emmake make
fails on undefined symbols:
error: undefined symbol: _ZN2cv3Mat10deallocateEv
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
My question is : what do I wrong ? How to tell emscripten where are the famous missing symbols (these are the file .so if I understood correctly) ?
This is partially a hack solution.
In the file /usr/local/lib/cmake/opencv4/OpenCVModules.cmake, change every instances of "SHARED" by "STATIC".
In your cmake file, add the line
file( GLOB opencv_js "/path/to/opencvjs/opencv/build_js/lib/*.a")
This part supposes that you compiled opencv by hand.
then refer to my answer to my next question. (in short: use a canvas, do not use cv::imdecode.)
I'm having some problems try to link two shared library to my main.cpp file in a cmake file.
My folder tree is:
**mainfolder**
|_main.cpp
|_CMakeLists.txt
|
| **lib**
|_**lib1**
|_CMakeLists.txt
|_liblib1.so
|_**src**
|_lib1.cpp
|_**include**
|_lib1.h
|_**lib2**
|_CMakeLists.txt
|_liblib2.so
|_**src**
|_lib2.cpp
|_**include**
|_lib2.h
the two CMakeLists.txt for the two libraries are quite similar and created according to this link:
cmake_minimum_required(VERSION 2.6)
project( LibraryLib1 C CXX )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
set(CMAKE_BUILD_TYPE Release)
find_package( OpenCV REQUIRED )
# Find source files
file(GLOB SOURCES src/*.cpp)
# Include header files
include_directories(include)
# Create shared library
add_library(${PROJECT_NAME} SHARED ${SOURCES})
# Install library
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
# Install library headers
file(GLOB HEADERS include/*.h)
install(FILES ${HEADERS} DESTINATION include/${PROJECT_NAME})
my main.cpp file is:
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/opencv.hpp>
#include "lib/lib1/lib1.h"
#include "lib/lib2/lib2.h"
using namespace cv;
int main()
{
printf("Executing main.cpp");
lib1 lib1object;
lib2 lib2object;
for(;;)
{
lib1object.Analize(param1, param2);
lib2object.Draw(param1, param2, param3);
}
return 0;
}
My main.cpp should call openCV + the two libraries. Could you please tell me which line I have to add to the CMakeLists.txt in the main folder to run my main?
in this moment the mainfolder/CMakeLists.txt is:
cmake_minimum_required(VERSION 2.8)
project( MyProject C CXX )
find_package( OpenCV REQUIRED )
add_executable( main main.cpp )
target_link_libraries( main ${OpenCV_LIBS})
I really appreciate your help. Thanks!!
One more thing... If I modify tghe last row of the mainfolder/CMakeLists.txt as:
target_link_libraries( main ${OpenCV_LIBS} LibraryLib1 LibraryLib2)
where LibraryLib1 and LibraryLib2 are the name of the two library project, I obtain:
/usr/bin/ld: unable to find -lLibraryLib1
/usr/bin/ld: unable to find -lLibraryLib2
You have separate projects for the libraries and the main file. Therefore, the main file doesn't know the target names from the other projects. The easiest solution (as everything is in a single source tree) is to have just a single projects.
Therefore, use add_subdirectory to build your libarires directly in the main project:
cmake_minimum_required(VERSION 2.8)
project( MyProject C CXX )
add_subidrectory(lib/lib1)
add_subidrectory(lib/lib2)
find_package( OpenCV REQUIRED )
add_executable( main main.cpp )
target_link_libraries( main ${OpenCV_LIBS} LibraryLib1 LibraryLib2)
This ensures that target names are known. This assumes that you have calls in the subfolders like add_library(LibraryLib1.... Otherwise, exchange the names appropriately.
I seem to have an issue with my CMakeLists and opencv.
I am currently using opencv version 2.4 which is confirmed by
pkg-config --modversion opencv
2.4.8
and
dpkg -l libopencv*
which outputs http://pastebin.com/ZJEfLjDX
But for some reason when i cmake a simple program such as
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
Will cmake not continue due to this error.
CMake Error at /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVModules.cmake:183 (message):
The imported target "opencv_core" references the file
"/opt/ros/indigo/lib/libopencv_core3.so.3.1.0"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVModules.cmake"
but not all the files it references.
Call Stack (most recent call first):
/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake:86 (include)
CMakeLists.txt:3 (find_package)
-- Configuring incomplete, errors occurred!
with this CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
The project has no ros dependency, and I have no idea why it is looking for OpenCVConfig.cmake inside ros.
A simple locate shows that the correct version is available other places
locate OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/build/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/build/unix-install/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/cmake/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/cmake/templates/OpenCVConfig.cmake.in
/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake
/usr/local/share/OpenCV/OpenCVConfig.cmake
/usr/share/OpenCV/OpenCVConfig.cmake
but why does it choose to use the one from ros, which I am not sure is even an option if I don't have opencv3.1.0-dev installed?
I know that a solution to this problem would be SET the path. But why can't find_package make use of the 2.4.8 version? I even tried to change the filename of /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake to /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake.old, which caused the same error?... Why is cmake not able to find opencv by simple using find_package( OpenCV REQUIRED ), and how do I make it so that it possible to find using this.
I'm working on running a Hello World program on the Linksys WRT54G-V4 running either dd-wrt or OpenWRT.
Right now this router is running dd-wrt for reasons I'll explain below. I'd like to switch this router to OpenWRT, because I've not been able to build dd-wrt or its toolchain. I 'assume' that the OpenWRT toolchain should produce executable binaries that will run on dd-wrt also.
OpenWRT was pretty straightforward to build, since it has a nice menu driven make system. Using this handy tool I built a toolchain that will cross compile from my x86 Ubuntu box to a MIPS target.
Following the instructions I've been able to build OpenWRT and produce images for brcm47xx and brcm63xx.
For example, here is a successful compile of my little Hello World program:
jim#ubuntu:~/Desktop/tests$ cat helloC.c
#include <stdio.h>
int main (int argc, char **argv)
{
printf("Hello World\n");
return 0;
}
jim#ubuntu:~/Desktop/tests$
jim#ubuntu:~/Desktop/tests$ mipsel-openwrt-linux-gcc -o HelloWorld helloC.c
jim#ubuntu:~/Desktop/tests$
jim#ubuntu:~/Desktop/tests$ file HelloWorld
HelloWorld: ELF 32-bit LSB executable, MIPS, MIPS32 version 1, dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, not stripped
jim#ubuntu:~/Desktop/tests$
Sadly, when I try to run HelloWorld on my WRT54G-V4 running dd-wrt I get a seg fault.
Looking at Wikipedia, I see that this router uses the Broadcom BCM5352.
When I run make menuconfig in by OpenWRT/trunk directory I don't see an option for the BCM5352, which is why I'm reluctant to flash my router with one of the images I've created in the brcm47xx or brcm63xx directories. I don't want to guess wrong and brick the router.
Question 1 - Which Broadcom configuration should I select using make menuconfig to target my WRT54G-V4 with its BCM5352 chipset?
Question 2 - Should my 'HelloWorld' executable file I generated above run directly from the command line on the 54G, or must I make it a package per http://www.gargoyle-router.com/wiki/doku.php?id=openwrt_coding ?
TIA
You can follow the official howto (from: http://www.dd-wrt.com/forum/viewtopic.php?p=21499&sid=de90601a8d51747d1c8ccec29284127d)
1. The helloworld.c source
Code:
#include <stdio.h>
int main ( void ) {
printf( "Hello world!\n" );
}
2. Get and unpack the toolchain in your homedir
Code:
cd ~
wget ftp://ftp.dd-wrt.com/sourcecode/toolchains.x86.debian.sp1.tar.bz2
tar -jxf toolchains.x86.debian.sp1.tar.bz2
3. Add the path to your cross-compiler executable to your path environment variable and compile helloworld.c
Code:
PATH=~/toolchains/4.1.0-uclibc-0.9.28/bin:$PATH mipsel-linux-uclibc-gcc helloworld.c -o helloworld
4. Check if its correctly compiled with the cross-compiler
Code:
file helloworld
helloworld: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
5. Finally, transfer the helloworld binary file to your router, set the executable bit and run it.
Tested with Ubuntu 6.06.1 LTS.
I've just reorganised my code (which worked before) and am now getting an error message when I run my executable: The program can't start because opencv_core230d.dll is missing from your computer. The error is accurate, I only have .lib library files for OpenCV, but it worked before and I don't think this should be a problem, should it?
An extract from the cmake file is:
FIND_PACKAGE( OpenCV REQUIRED )
# Define LIBRARY and SRC_FILES to create my library
add_library(${LIBRARY} ${SRC_FILES})
target_link_libraries(${LIBRARY} ${OpenCV_LIBS} )
# Define appName and appFile to create application,
# and link to my library and OpenCV
add_executable(${appName} ${appFile})
target_link_libraries(${appName} ${LIBRARY} ${OpenCV_LIBS})
Am I doing anything obviously wrong, or what else might cause this error?
EDIT: I've now reduced this problem to a minimal example. Inside one directory test I have two files: testApp.cpp and CMakeLists.txt as follows:
testApp.cpp
#include <opencv2/opencv.hpp>
int main(int argc, char* argv[])
{
cv::namedWindow("Test");
cv::waitKey(0);
cv::destroyAllWindows();
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(test)
FIND_PACKAGE( OpenCV REQUIRED )
add_executable(appName testApp.cpp)
target_link_libraries(appName ${OpenCV_LIBS})
message(STATUS "Linking testapp to: ${OpenCV_LIBS}")
With the error as before: opencv_highgui230d.dll is missing.
The problem is that the environment variable PATH does not point to the location where OpenCV's DLLs reside. Search inside OpenCV directories and if you can't find it you'll need to reinstall OpenCV.
Seems this is a common problem which simply needed some more research. To fix, I just added the OpenCV/bin directory to the PATH environmental variable. Still not sure why it was working previously though...