Int getopt() conflicting declaration issue during compilation

Hi, I’m getting the conflicting declaration issue when I try to compile the firmware code. From the search in source code, I notice there are also px4_getopt() and getopt_long() provided. I’m not sure how I should fix this and was wondering if anyone could give some hints. Thanks.

[10/522] Building CXX object src/drivers/bmp280/CMakeFiles/drivers__bmp280.dir/bmp280.cpp.obj
FAILED: /opt/gcc-arm-none-eabi-5_4-2016q2/bin/arm-none-eabi-g++   -DBUILD_URI=localhost -DCONFIG_ARCH_BOARD_PX4FMU_V4 -DMODULE_NAME=\"bmp280\" -DPX4_MAIN=bmp280_app_main -D__DF_NUTTX -D__PX4_NUTTX -D__STDC_FORMAT_MACROS -I. -Isrc -Isrc/modules -I../src -I../src/drivers/boards/px4fmu-v4 -I../src/include -I../src/lib -I../src/lib/DriverFramework/framework/include -I../src/lib/matrix -I../src/modules -I../src/platforms -Ipx4fmu-v4/NuttX/nuttx/nuttx-export/include -Ipx4fmu-v4/NuttX/nuttx/nuttx-export/include/cxx -Ipx4fmu-v4/NuttX/nuttx/nuttx-export/arch/chip -Ipx4fmu-v4/NuttX/nuttx/nuttx-export/arch/common -Ipx4fmu-v4/NuttX/nuttx/nuttx-export/arch/armv7-m -Ipx4fmu-v4/NuttX/apps/include -Iexternal/Install/include -g -fno-exceptions -fno-rtti -std=gnu++11 -fno-threadsafe-statics -DCONFIG_WCHAR_BUILTIN -D__CUSTOM_FILE_IO__ -fcheck-new -Wall -Warray-bounds -Werror -Wextra -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wmissing-declarations -Wpointer-arith -Wshadow -Wuninitialized -Wunused-variable -Wno-sign-compare -Wno-unused-parameter -Wunused-but-set-variable -Wformat=1 -Wdouble-promotion -Wno-missing-field-initializers -Wreorder -fvisibility=hidden -include visibility.h -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard -nodefaultlibs -nostdlib -fno-strict-aliasing -fomit-frame-pointer -funsafe-math-optimizations -ffunction-sections -fdata-sections -fno-strength-reduce -fno-builtin-printf -Os -DNDEBUG   -Wframe-larger-than=1024 -fno-strict-aliasing -fomit-frame-pointer -funsafe-math-optimizations -ffunction-sections -fdata-sections -fno-strength-reduce -fno-builtin-printf -MD -MT src/drivers/bmp280/CMakeFiles/drivers__bmp280.dir/bmp280.cpp.obj -MF src/drivers/bmp280/CMakeFiles/drivers__bmp280.dir/bmp280.cpp.obj.d -o src/drivers/bmp280/CMakeFiles/drivers__bmp280.dir/bmp280.cpp.obj -c ../src/drivers/bmp280/bmp280.cpp
In file included from ../src/drivers/bmp280/bmp280.cpp:53:0:
/usr/include/getopt.h:169:20: error: conflicting declaration of C function 'int getopt(...)'
 extern int getopt ();
                    ^
compilation terminated due to -Wfatal-errors.

Is this PX4 master? Make sure your build environment exactly matches the documentation (https://dev.px4.io/en/), you have the latest PX4 master, then fully clean make distclean and try again.

This isn’t currently happening in the build system (https://semaphoreci.com/px4/firmware/) so we need to find what’s different in your local environment.

Yes, it is in master. And I don’t see this problem on my home computer, just appeared on my lab computer. Is the compiler supposed to use the header in /use/include? I know generally a cross-compile should not but maybe because px 4 is using nuttx with POSIX compliance so that it could? If so any requirement of the GCC version on the host computer?