How to succesfully "catkin_make" with files that include header files (C++)?
I recently started using ROS/catkin and learning to code in c++ and am very lost. I have gone through the tutorials and googled many things but am still confused, especially with what to put in CMakelist.txt in order for "catkin_make" to work. I coded a very simple example just to see if I could build ("catkin_make") successfully, including: main.cpp, add.h, add.cpp.
This is the error I get when I run "catkin_make":
Linking CXX executable /home/elim323/catkin_ws/devel/lib/shortest_path/shortest_path
CMakeFiles/shortest_path.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x1a): undefined reference to `add(int, int)'
collect2: ld returned 1 exit status
make[2]: *** [/home/elim323/catkin_ws/devel/lib/shortest_path/shortest_path] Error 1
make[1]: *** [shortest_path/CMakeFiles/shortest_path.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
The code for each file is as follows:
//main.cpp:
#include <iostream>
#include "add.h"
int main() {
using namespace std;
cout << "The sum of 3 and 4 is " << add(3,4) << endl;
return 0;
}
add.h:
#ifndef ADD_H
#define ADD_H
int add(int,int);
#endif
add.cpp:
#include "add.h"
int add(int a,int b) {
int sum;
sum = a + b;
return sum;
}
They are all in the same folder (/home/catkin_ws/src/shortest_path/src).
My CMakelist.txt file is as follows:
cmake_minimum_required(VERSION 2.8.3)
project(shortest_path)
find_package(catkin REQUIRED)
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(shortest_path src/main.cpp)
I guess my main questions are: what do I need in the CMakelist.txt file in order to build successfully? Are there standard things I should be putting in the CMakelist.txt file when coding in c++?