Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

1 . If there are multiple files referring to one node, which code is executed when we run that node?

The code that is part of the main entry point, which is by default: int main(int argc, char *argv[]).

Note that this is no different from how you'd specify a target in (GNU) Make: it's perfectly valid for binaries to consist of multiple object files.

2 . Why do we add the header files to the add_executable? I never saw this before.

This is often done for CMake generators that generate projects for tools / IDEs that don't show all files by default (in a project explorer view fi), but only those files that are "part of" a target. Qt Creator is one of those, as is Visual Studio.

Note: these questions are not ROS specific: your first question is basic CMake / Make, the second is a 'trick' (and listed as one of the CMake antipatterns (but read the Errata section at the bottom of the page).

1 . If there are multiple files referring to one node, which code is executed when we run that node?

The code that is part of the main entry point, which is by default: int main(int argc, char *argv[]).

Note that this is no different from how you'd specify a target in (GNU) Make: it's perfectly valid for binaries to consist of multiple object files.

2 . Why do we add the header files to the add_executable? I never saw this before.

This is often done for CMake generators that generate projects for tools / IDEs that don't show all files by default (in a project explorer view fi), but only those files that are "part of" a target. Qt Creator is one of those, as is Visual Studio.

Note: these questions are not ROS specific: your first question is basic CMake / Make, the second is a 'trick' (and listed as one of the CMake antipatterns (but read the Errata section at the bottom of the page).


Edit:

But I don't understand. Like when we call that node , which file is executed? are they all executed? which order?

Please read the link to the wikipedia article about entry points. The question "which file is executed" doesn't really make sense in the context of compiled languages and object code.

1 . If there are multiple files referring to one node, which code is executed when we run that node?

The code that is part of the main entry point, which is by default: int main(int argc, char *argv[]).

Note that this is no different from how you'd specify a target in (GNU) Make: it's perfectly valid for binaries to consist of multiple object files.

2 . Why do we add the header files to the add_executable? I never saw this before.

This is often done for CMake generators that generate projects for tools / IDEs that don't show all files by default (in a project explorer view fi), but only those files that are "part of" a target. Qt Creator is one of those, as is Visual Studio.

Note: these questions are not ROS specific: your first question is basic CMake / Make, the second is a 'trick' (and listed as one of the CMake antipatterns (but read the Errata section at the bottom of the page).


Edit:

But I don't understand. Like when we call that node , which file is executed? are they all executed? which order?

Please read the link to the wikipedia article about entry points. The question "which file is executed" doesn't really make sense in the context of compiled languages and object code.

code (as there isn't necessarily a 1-to-1 correspondence).