# How the function "main()" is called

**URL:** <https://discuss.px4.io/t/how-the-function-main-is-called/93>\
**Category:** Uncategorized\
**Created:** [January 18, 2016, 10:18am UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93 "2016-01-18T10:18:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FreelyHard](https://discuss.px4.io/user_avatar/discuss.px4.io/freelyhard/32/57_2.png) [@FreelyHard](https://discuss.px4.io/u/FreelyHard)\
**Post date:** [January 18, 2016, 10:18am UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/1 "2016-01-18T10:18:06Z")

</div>

how the function like “fmu\_main(int argc, char \* argv[])” is called?  
 ![](https://discuss.px4.io/uploads/default/original/1X/5dad2a0365b3f5fff774fef8fbbad6bbe2013b30.png)

Maybe, It is called as a command in a script. But I can’t find it.

could you help me ?

---

<div class="post-metadata">

**Author:** ![Mark\_Whitehorn](https://discuss.px4.io/user_avatar/discuss.px4.io/mark_whitehorn/32/3533_2.png) [@Mark\_Whitehorn](https://discuss.px4.io/u/Mark_Whitehorn)\
**Post date:** [January 24, 2016, 4:21pm UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/2 "2016-01-24T16:21:12Z")

</div>

It’s started by script ROMFS/px4fmu\_common/init.d/rcS. See [http://dev.px4.io/advanced-system-startup.html](http://dev.px4.io/advanced-system-startup.html)

---

<div class="post-metadata">

**Author:** ![FreelyHard](https://discuss.px4.io/user_avatar/discuss.px4.io/freelyhard/32/57_2.png) [@FreelyHard](https://discuss.px4.io/u/FreelyHard)\
**Post date:** [January 25, 2016, 11:01am UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/3 "2016-01-25T11:01:55Z")

</div>

Thank you very much.  
I found the code is used in a structure in the same file. Then I inference the structure and didn’t find the source which call the fmu\_main() function.

 ![](https://discuss.px4.io/uploads/default/original/1X/486cd0cf35b87831649ba3eadf2809be1503061e.png)

I had found the rcs file, and I had known that the rcs script call other scripts in the same folder. However I don’t know the detailed process.

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [January 26, 2016, 7:42pm UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/4 "2016-01-26T19:42:07Z")

</div>

You can see the array of `struct builtin_s g_builtins[]`. This is a map of the “module names” to the main functions. You could now grep for where this table is used e. g. somewhere in NuttX.

---

<div class="post-metadata">

**Author:** ![Mark\_Whitehorn](https://discuss.px4.io/user_avatar/discuss.px4.io/mark_whitehorn/32/3533_2.png) [@Mark\_Whitehorn](https://discuss.px4.io/u/Mark_Whitehorn)\
**Post date:** [January 30, 2016, 8:51pm UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/5 "2016-01-30T20:51:36Z")

</div>

If the question is “how is a builtin function invoked using the NSH shell”,  
perhaps this Eclipse screen capture will help. I’m happy to report that no “grep” was necessary, just a C++ symbol search starting with references to g\_builtins:

 ![](https://discuss.px4.io/uploads/default/original/1X/658a26a711a87a6c80494201a6202efa08fa5759.png)

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [January 31, 2016, 7:45pm UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/6 "2016-01-31T19:45:42Z")

</div>

Hehe, sure grep or search in your favorite text editor ;). Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![FreelyHard](https://discuss.px4.io/user_avatar/discuss.px4.io/freelyhard/32/57_2.png) [@FreelyHard](https://discuss.px4.io/u/FreelyHard)\
**Post date:** [April 18, 2016, 12:52am UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/7 "2016-04-18T00:52:30Z")

</div>

O~~ I’ll find it. Thank you !~!~!~!~

---

<div class="post-metadata">

**Author:** ![FreelyHard](https://discuss.px4.io/user_avatar/discuss.px4.io/freelyhard/32/57_2.png) [@FreelyHard](https://discuss.px4.io/u/FreelyHard)\
**Post date:** [April 18, 2016, 12:58am UTC](https://discuss.px4.io/t/how-the-function-main-is-called/93/8 "2016-04-18T00:58:01Z")

</div>

I’m using the Qt Creator  
The “find in files” is very fast after once operate “find”.  
MAYBE the environment could be set up for compiling the code in Qt, though I haven’t finish it…
