Search code examples
c++makefilecompiler-errorswebots

Cannot compile .cpp file externally for Webots with Makefile


I'm trying to build a C++ program for Webots.

So first, I just pressed File -> New -> New Robot Controller menu and made everything default except the language, which I chose C++.

Then, Webots generated me my_controller.cpp and Makefile inside a new folder my_controller.

Because I wanted to use other tools as my text editor instead of the one that is incorporated in Webots, I chose to build externally.

When I tried to build it by typing %WEBOTS_HOME%\msys64\usr\bin\make.exe INSIDE my_controller folder externally using command prompt, it told me this:

make: Nothing to be done for 'all'.

Surprisingly, when I pressed the button below, it successfully generated build folder and my_controller.exe:

Gear-like icon

Is it possible to build cpp inside vscode? If so, how?



FYI:

When I uncommented line 42 and replaced with CXX_SOURCES = my_controller.cpp, I got the error message that it can't create build/release/my_controller.o when I executed %WEBOTS_HOME%\msys64\usr\bin\make.exe.

So I retried make command above after creating empty build/release folder, and I got this:

# updating my_controller.d
# compiling my_controller.cpp
# linking my_controller.exe
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: build/release/my_controller.o:my_controller.cpp:(.text.startup+0x29): undefined reference to `webots::Robot::Robot()'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: build/release/my_controller.o:my_controller.cpp:(.text.startup+0x30): undefined reference to `webots::Robot::getBasicTimeStep() const'
collect2.exe: error: ld returned 1 exit status
make: *** [D:/Webots/resources/Makefile.include:576: build/release/my_controller.exe] Error 1

About my environment, I have installed MinGW in D:\MinGW, installed Webots in D:\Webots, but I don't know what's causing my problem.


Solution

    • Read documentation carefully and found msys2 is necessary for building
    • Install msys2 from here
    • pacman -S make and pacman -S gcc
    • Add {path_to_msys64}\usr\bin (e.g. D:\msys64\usr\bin) to Windows PATH

    Above worked perfectly!

    Thank you Some programmer dude and john :)