[Bug] I got error while trying to execute the code

This is an error report.


Screenshot of the error


Error details

I was trying to execute the code for CMake.txt but after executing cmake .. I went for make in this instance, I got the error about the "main" not being defined I just copied and pasted the code from the course so help me to understand what went wrong and how to mitigate this error.

Hi @kushal49 ,

the error is saying that you don’t have a function called main in the main.cpp file.

Along the course you may have created more than one main.cpp file.

I see in the logs that you are compiling in the build_test folder, therefore, could you double-check if there is a main function on catkin_ws/src/build_test/src/main.cpp?

Every C/C++ program needs a main function, because this is the function called when you execute your program.

I looked for
catkin_ws/src/build_test/src/main.cpp
the output is -catkin_ws/src/build_test/src/main.cpp: No such file or directory
yet inside the ~catkin_ws/src/build_test/src
I can see main.cpp now please let me know what to do to get over this error?

Hi,
I think the problem is that you don’t have a main() function inside the main.cpp.

I can see in the screenshot you sent that you have properly created the files. They should look like this:

image

In your case, that is correct. So you can see that there is a file named main.cpp in your IDE (in the screenshot you sent).

However, I suspect that the content of your main.cpp is empty. Open the main.cpp in the IDE and see what is there. Very likely, you forgot to copy the content. It should contain the following:

#include "first.hpp"

int main() {
  WhatsUp();
  ButWhy();
  return 0;
}

Let me know if that is the case

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.