1

I have been using ROS Kinetic for a while, and today when I went to make a new catkin workspace following the ROS tutorials page (http://wiki.ros.org/catkin/Tutorials/create_a_workspace) I get a CMake Error stating that PROJECT_NAME is set to Project, which is invalid. I have never run into this issue with any of my other work spaces I have created.

I do not want to mess with toplevel.cmake out of fear of screwing up my other work spaces.

Any ideas why this is happening?

CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkin_package.cmake:91 (message):
  catkin_package() PROJECT_NAME is set to 'Project', which is not a valid
  project name.  You must call project() before calling catkin_package().

Thank you.

JaQ
  • 13
  • 4

3 Answers3

0

I was able to reproduce the above error you are getting. For that what I did is opened my CMakeLists.txt and commented the second line which defines the package Name, i.e., project(package_name). After that, I tried to build my package via catkin_make, but got below error(see the error inside yellow box):

enter image description here

Then, I tried to build the same package after uncommenting the above line. This time I was able to build my package(test, in my case) successfully, without any error.

enter image description here

CMakeLists.txt file contains project() as well as catkin_package() and the former function should be called before catkin_package() inside the file. So, project(package_name) is either missing from your CMakeLists.txt file or is commented.

If it is missing, then manually add it. If it is there, but commented then uncomment it.

Read more about the correct format of CMakeLists.txt file from here.

Anubhav Singh
  • 8,321
  • 4
  • 25
  • 43
  • Thank you for your detailed response! This certainly makes sense. I wonder why this is a problem now and never before. When I make a new workspace folder, call it ```test_ws/src```, then I run ```catkin_make``` in the top folder, it creates a ```CMakeLists.txt``` in the src folder like I would expect it to. This file has a sym link to ```/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake```, which also does not have the ```project()``` function call. Should I change ```toplevel.cmake``` ? I ask because I have been warned on more than one occasion to NOT change system files like that. – JaQ Jul 10 '19 at 16:26
  • Yes the problem seems to be that when I run ```catkin_make``` in a brand new work space, the ```CMakeLists.txt``` file that is generated is a sym link to ```/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake```. No idea how that happened though. – JaQ Jul 10 '19 at 16:48
  • Welcome. If my answer helped you, please accept it. Thanks. Check this: https://stackoverflow.com/help/someone-answers – Anubhav Singh Jul 10 '19 at 16:51
  • To be clear, this does not actual solve my problem, but the accepted answer helped me find the real problem. – JaQ Jul 11 '19 at 16:45
  • I have not solved the problem. I think the problem is when I run ```catkin_make``` in ```catkin_ws```, a ```CMakeLists.txt``` gets generated that is a symlink to ```/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake```. I am not sure if this is suppose to happen, but I do not know what else would be the problem. I moved to a different computer and the problem is not present, so I assume the problem is my machines configuration. I plan to reinstall everything (after a deadline) to see if the problem persists. Should I marked as not solved? – JaQ Jul 12 '19 at 18:25
  • So, this `CMakeLists.txt` that you are referring to has been generated in at `/home/user/catkin_ws/src` path ? If yes, this is fine. But, when you create a ros package in `src` directory, then one `CMakeLists.txt` file will also get created inside the package itself, containing package_name as described in my explaination above. So, I think it's fine. But you must be getting above error because of missing/commented `project(package_name)` line in `CmakeLists.txt` file inside your ros package under `src` directory, not `CmakeLists.txt` file inside `src` directory. – Anubhav Singh Jul 12 '19 at 19:26
0

ironically, you'll be running : sudo apt-get install ros-<distro_name>-catkin to reinstall catkin because even if u clear your entire workspace the problem will persist due to some symbolic link or something broken in the package which will always result in the same error, upon reinstalling catkin it worked for me, knowing that I had the exact same issue.

Altaf
  • 2,838
  • 1
  • 16
  • 8
0

Had to come answer this because I think I did the same thing OP did. Here's what happened: There are supposed to be TWO CMakeLists.txt in your project folder. One lives at ProjectName/src and should be read-only and should actually be a link to your /opt/ros/your-ros-distro/share/catkin/cmake/toplevel.cmake folder.

If you do like I did, and I'm assuming like OP did, and edit that file, and then use your superuser to overwrite that file, then you are (1) breaking all of your catkin projects, because ALL of the catkin projects link to this one file, AND you're misconfiguring this project because the CMakeLists.txt file you're supposed to modify actually exists a folder deeper, at ProjectName/src/ProjectName/. THIS is where you're supposed to put the CMakeLists.txt file that names your project, where your package.xml file is supposed to go, etc.

If you use superuser to force-overwrite the read-only CMakeLists.txt file then you're going to have a bad day. Fortunately you can fix that file by fixing the toplevel.cmake folder, which you can do by reinstalling the catkin package: sudo apt-get install --reinstall ros-indigo-catkin

And, to put this in terms of OP's question specifically - the project() needs to get named at the inner file, the ProjectName/src/ProjectName/CMakeLists.txt, because again the root file is read-only and should never be modified.

Chuck
  • 1,977
  • 1
  • 17
  • 23