Home | Tutorials | Wiki | Issues
Ask Your Question
0

I am trying to write my own plugin, which has its own header file. For its compilation, I am following Plugins 101 tutorials. When I run make command in terminal in build folder, it says "fatal error: myproject.hh: No such file or directory compilation terminated". How to solve this problem ?

asked 2018-06-27 03:12:57 -0500

pk gravatar image

updated 2018-06-27 04:02:10 -0500

Gazebo Version: 7.13.1
Ubuntu 16.04,

Tutorial Link: Plugins 101

File Structure :
Myproject (Folder)
----myproject.cc
----myproject.hh
----CMakeLists.txt
----build (Folder)

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
find_package(gazebo REQUIRED)

include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})

list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")
add_library(myproject SHARED myproject.cc)

target_link_libraries(myproject ${GAZEBO_LIBRARIES})

I have written a new header file myproject.hh and included it in myproject.cc. When I try to compile myproject.cc, it says "myproject.hh not found". What changes should I make to my CMakeLists.txt, so that it recognises the header file. Thanks in advance.

edit retag flag offensive close merge delete

Comments

What's the `include` line in `myproject.cc`?

chapulina gravatar imagechapulina ( 2018-06-27 11:05:23 -0500 )edit

cmake looks fine from an amateur pov

tacyon gravatar imagetacyon ( 2018-06-28 01:28:55 -0500 )edit

#include <myproject.hh>

pk gravatar imagepk ( 2018-06-28 05:58:16 -0500 )edit

I add "include_directories(${HEADER_FILES})" to my CMakeLists.txt file and it works.

pk gravatar imagepk ( 2018-06-28 06:01:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-28 03:21:36 -0500

wentz gravatar image

You need to tell the compiler to use your header file. Try to change:

add_library(myproject SHARED myproject.cc)

to

add_library(myproject SHARED myproject.cc myproject.hh)

if this dont fix your problem you should make sure to include your header file like this: #include "myproject.hh"

and not with these <>.

edit flag offensive delete link more

Comments

What difference it makes by using " " instead of <> ?

pk gravatar imagepk ( 2018-06-28 05:56:52 -0500 )edit
1

In general it should work with both. The difference is that <> are used for including system libraries while "" are used for local libraries. Sometimes this could lead to the compiler can't find the include file. Just give it a try with both ways.

wentz gravatar imagewentz ( 2018-06-30 06:01:57 -0500 )edit

I gave it a try with both, "" and <> it didn't work. Thanks a lot for the help ! I added "include_directories(${HEADER_FILES})" to my CMakeLists.txt file and it works.

pk gravatar imagepk ( 2018-06-30 10:59:21 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-06-27 03:12:57 -0500

Seen: 197 times

Last updated: Jun 28 '18