how to correctly use code from another package? Error: Does not name a type
The project has two packages, and as one packages tries to to use code from the other package, this error occurs:
In file included from /home/mo/Desktop/workspace/src/jimmy_lidar_motor_control/src/lidar_motor_control.cpp:40:0:/home/mo/Desktop/workspace/src/jimmy_lidar_motor_control/include/jimmy_lidar_motor_control/lidar_motor_control.h:17:5: error: ‘jimmycpp’ does not name a type
jimmycpp::LidarRotation lidarMotorForRotationObj;
^
in workspace/src
directory there are 2 packages (for now). one acts as a library (called jimmycpp), and the other (called jimmy_lidar_motor_control) is trying to use a file in the jimmycpp library. I am using standard ros package organization:
└─-----─ src
├── jimmycpp
│ ├── CMakeLists.txt
│ ├── include
│ │ └── jimmycpp
│ │ ├── ampsteppers.h
│ │ ├── arduinomega.h
│ │ ├── lidar_encoder.h
│ │ ├── lidar_rotation.h
│ │ └── trc_logging.h
│ ├── package.xml
│ ├── README.md
│ └── src
│ ├── ampsteppers.cpp
│ ├── arduinomega.cpp
│ ├── lidar_encoder.cpp
│ ├── lidar_rotation.cpp
│ ├── main.cpp
│ └── trc_logging.cpp
└── jimmy_lidar_motor_control
├── CMakeLists.txt
├── include
│ └── jimmy_lidar_motor_control
│ └── lidar_motor_control.h
├── launch
│ └── lidar_motor_control.launch
├── msg
│ └── motion_command_to_execute.msg
├── package.xml
└── src
└── lidar_motor_control.cpp
The library header file that needs to be included by the the package using the library is: jimmycpp/include/jimmycpp/lidar_rotation.h
. Here is a very brief internal view:
//no implementation only a bunch of declarations
class LidarRotation
{
private:
//bunch of code
public:
LidarRotation();
//public methods for other packages to call
};
The actual implementation of the LidarRotation class takes place in src/lidar_roation.cpp
in jimmycpp. The CMakeLists.txt for jimmycpp library package looks like this:
# What version of CMake is needed?
cmake_minimum_required(VERSION 2.8.3)
# The name of this package (must match name in package.xml).
project(jimmycpp)
#use the C++11 standard
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
roscpp
)
# Declare our catkin package.
catkin_package(
INCLUDE_DIRS
include
CATKIN_DEPENDS
roscpp
LIBRARIES
jimmycpp
)
# Specify locations of header files.
include_directories(
include
${catkin_INCLUDE_DIRS}
)
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE)
add_library(jimmycpp
include/${PROJECT_NAME}/arduinomega.h
include/${PROJECT_NAME}/ampsteppers.h
include/${PROJECT_NAME}/trc_logging.h
include/${PROJECT_NAME}/lidar_rotation.h
include/${PROJECT_NAME}/lidar_encoder.h
src/arduinomega.cpp
src/ampsteppers.cpp
src/trc_logging.cpp
src/lidar_rotation.cpp
src/lidar_encoder.cpp
)
#serial was added for serial comm to motor rotating lidar.
#labjackusb is the exodriver for the U3.
target_link_libraries(jimmycpp serial labjackusb ${catkin_LIBRARIES})
In the package that wants to use the jimmycpp library (the lidar_rotation.h & lidar_rotation.cpp) there is only one header file called lidar_motor_control.h
. In this header file I declare my library, and a few variables. no classes, very simple:
/// my low level library
#include <jimmycpp/lidar_rotation.h>
//This is my handle for my library.
//jimmycpp::LidarRotation lidarMotorForRotationObj;
//lots more stuff
if I uncomment the line jimmycpp::LidarRotation lidarMotorForRotationObj;
i get the error at the begining of this long (sorry) question. But if I comment the line out catkin_make
completes with no errors (but I can't use my library). Here is the CMakeLists.txt for the second package:
# What version of CMake is needed?
cmake_minimum_required(VERSION 2.8.3)
# The name of this package (must match package.xml).
# from here on "${PROJECT_NAME}" == "jimmy_base"
project(jimmy_lidar_motor_control)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options ...