Compiling C files error

I’m trying to use the SPIFFS library which should be very easy but I have this error and I dont understand why.

if I leave the files with a .c extension, I get this error:

In file included from ./inc/application.h:29:0,
                 from ./inc/Particle.h:5,
                 from spiffs_config.h:16,
                 from spiffs.h:14,
                 from spiffs_hydrogen.c:8:
../system/inc/system_version.h:67:19: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
     uint16_t size = sizeof(SystemVersionInfo);
                   ^
In file included from ../wiring/inc/spark_wiring.h:38:0,
                 from ./inc/application.h:36,
                 from ./inc/Particle.h:5,
                 from spiffs_config.h:16,
                 from spiffs.h:14,
                 from spiffs_hydrogen.c:8:
../wiring/inc/spark_wiring_constants.h:31:23: fatal error: type_traits: No such file or directory
 #include <type_traits>
                       ^
compilation terminated.
make[1]: *** [../build/target/user/platform-6spiffs_hydrogen.o] Error 1
make: *** [user] Error 2

But as soon as I change all the file extensions from c to cpp it’s fine…

BTW I’m compiling with the cli with the command: particle compile photon c:\Spark\firmware\user\applications\spiffs

Anything that includes Particle.h or application.h usually needs to have a .cpp file extension. The files that eventually get included, like <type_traits> are C+±specific header files and won’t compile using the plain c compiler.

It’s possible to use plain .c files for library files that don’t need to use the Particle header files, but it’s often easier just to make everything .cpp files.

Ok good to know!

Thanks

In addition, if you’re getting the following errors, it’s because you need to rename your header files from *.h to *.hpp.
I don’t do a lot of C++ programming, so when I do, I prefer .h headers, but it will result in the following errors, which I couldn’t find in the forums anywhere. Maybe someone searching for these errors will see this and save some time in the future.

/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:42:40: error: 'EAFNOSUPPORT' was not declared in this scope
   address_family_not_supported =   EAFNOSUPPORT,
                                    ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:43:28: error: 'EADDRINUSE' was not declared in this scope
       address_in_use =     EADDRINUSE,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:44:34: error: 'EADDRNOTAVAIL' was not declared in this scope
       address_not_available =    EADDRNOTAVAIL,
                                  ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:45:30: error: 'EISCONN' was not declared in this scope
       already_connected =    EISCONN,
                              ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:46:35: error: 'E2BIG' was not declared in this scope
       argument_list_too_long =    E2BIG,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:47:35: error: 'EDOM' was not declared in this scope
       argument_out_of_domain =    EDOM,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:48:25: error: 'EFAULT' was not declared in this scope
       bad_address =     EFAULT,
                         ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:49:32: error: 'EBADF' was not declared in this scope
       bad_file_descriptor =    EBADF,
                                ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:55:25: error: 'EPIPE' was not declared in this scope
       broken_pipe =     EPIPE,
                         ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:56:31: error: 'ECONNABORTED' was not declared in this scope
       connection_aborted =    ECONNABORTED,
                               ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:57:42: error: 'EALREADY' was not declared in this scope
       connection_already_in_progress =   EALREADY,
                                          ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:58:31: error: 'ECONNREFUSED' was not declared in this scope
       connection_refused =    ECONNREFUSED,
                               ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:59:29: error: 'ECONNRESET' was not declared in this scope
       connection_reset =    ECONNRESET,
                             ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:60:30: error: 'EXDEV' was not declared in this scope
       cross_device_link =    EXDEV,
                              ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:61:40: error: 'EDESTADDRREQ' was not declared in this scope
       destination_address_required =   EDESTADDRREQ,
                                        ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:62:35: error: 'EBUSY' was not declared in this scope
       device_or_resource_busy =   EBUSY,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:63:32: error: 'ENOTEMPTY' was not declared in this scope
       directory_not_empty =    ENOTEMPTY,
                                ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:64:35: error: 'ENOEXEC' was not declared in this scope
       executable_format_error =   ENOEXEC,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:65:32: error: 'EEXIST' was not declared in this scope
       file_exists =            EEXIST,
                                ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:66:28: error: 'EFBIG' was not declared in this scope
       file_too_large =     EFBIG,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:67:30: error: 'ENAMETOOLONG' was not declared in this scope
       filename_too_long =    ENAMETOOLONG,
                              ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:68:35: error: 'ENOSYS' was not declared in this scope
       function_not_supported =    ENOSYS,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:69:29: error: 'EHOSTUNREACH' was not declared in this scope
       host_unreachable =    EHOSTUNREACH,
                             ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:72:31: error: 'EIDRM' was not declared in this scope
       identifier_removed =    EIDRM,
                               ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:75:34: error: 'EILSEQ' was not declared in this scope
       illegal_byte_sequence =    EILSEQ,
                                  ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:76:45: error: 'ENOTTY' was not declared in this scope
       inappropriate_io_control_operation =  ENOTTY,
                                             ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:77:25: error: 'EINTR' was not declared in this scope
       interrupted =     EINTR,
                         ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:79:26: error: 'ESPIPE' was not declared in this scope
       invalid_seek =     ESPIPE,
                          ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:81:28: error: 'EISDIR' was not declared in this scope
       is_a_directory =     EISDIR,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:82:26: error: 'EMSGSIZE' was not declared in this scope
       message_size =     EMSGSIZE,
                          ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:83:26: error: 'ENETDOWN' was not declared in this scope
       network_down =     ENETDOWN,
                          ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:84:27: error: 'ENETRESET' was not declared in this scope
       network_reset =     ENETRESET,
                           ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:85:32: error: 'ENETUNREACH' was not declared in this scope
       network_unreachable =    ENETUNREACH,
                                ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:86:28: error: 'ENOBUFS' was not declared in this scope
       no_buffer_space =    ENOBUFS,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:87:29: error: 'ECHILD' was not declared in this scope
       no_child_process =    ECHILD,
                             ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:90:21: error: 'ENOLINK' was not declared in this scope
       no_link =     ENOLINK,
                     ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:93:30: error: 'ENOLCK' was not declared in this scope
       no_lock_available =    ENOLCK,
                              ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:96:33: error: 'ENODATA' was not declared in this scope
       no_message_available =    ENODATA, 
                                 ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:99:24: error: 'ENOMSG' was not declared in this scope
       no_message =     ENOMSG, 
                        ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:100:31: error: 'ENOPROTOOPT' was not declared in this scope
       no_protocol_option =    ENOPROTOOPT,
                               ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:101:31: error: 'ENOSPC' was not declared in this scope
       no_space_on_device =    ENOSPC,
                               ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:104:32: error: 'ENOSR' was not declared in this scope
       no_stream_resources =    ENOSR,
                                ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:107:37: error: 'ENXIO' was not declared in this scope
       no_such_device_or_address =   ENXIO,
                                     ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:109:37: error: 'ENOENT' was not declared in this scope
       no_such_file_or_directory =   ENOENT,
                                     ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:110:28: error: 'ESRCH' was not declared in this scope
       no_such_process =    ESRCH,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:111:28: error: 'ENOTDIR' was not declared in this scope
       not_a_directory =    ENOTDIR,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:112:26: error: 'ENOTSOCK' was not declared in this scope
       not_a_socket =     ENOTSOCK,
                          ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:115:26: error: 'ENOSTR' was not declared in this scope
       not_a_stream =     ENOSTR,
                          ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:118:27: error: 'ENOTCONN' was not declared in this scope
       not_connected =     ENOTCONN,
                           ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:122:27: error: 'ENOTSUP' was not declared in this scope
       not_supported =     ENOTSUP,
                           ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:126:31: error: 'ECANCELED' was not declared in this scope
       operation_canceled =    ECANCELED,
                               ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:129:34: error: 'EINPROGRESS' was not declared in this scope
       operation_in_progress =    EINPROGRESS,
                                  ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:130:35: error: 'EPERM' was not declared in this scope
       operation_not_permitted =   EPERM,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:131:35: error: 'EOPNOTSUPP' was not declared in this scope
       operation_not_supported =   EOPNOTSUPP,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:132:34: error: 'EWOULDBLOCK' was not declared in this scope
       operation_would_block =    EWOULDBLOCK,
                                  ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:135:24: error: 'EOWNERDEAD' was not declared in this scope
       owner_dead =     EOWNERDEAD,
                        ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:138:30: error: 'EACCES' was not declared in this scope
       permission_denied =    EACCES,
                              ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:141:28: error: 'EPROTO' was not declared in this scope
       protocol_error =     EPROTO,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:144:35: error: 'EPROTONOSUPPORT' was not declared in this scope
       protocol_not_supported =    EPROTONOSUPPORT,
                                   ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:145:34: error: 'EROFS' was not declared in this scope
       read_only_file_system =    EROFS,
                                  ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:146:41: error: 'EDEADLK' was not declared in this scope
       resource_deadlock_would_occur =   EDEADLK,
                                         ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:147:42: error: 'EAGAIN' was not declared in this scope
       resource_unavailable_try_again =   EAGAIN,
                                          ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:148:32: error: 'ERANGE' was not declared in this scope
       result_out_of_range =    ERANGE,
                                ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:151:34: error: 'ENOTRECOVERABLE' was not declared in this scope
       state_not_recoverable =    ENOTRECOVERABLE,
                                  ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:155:28: error: 'ETIME' was not declared in this scope
       stream_timeout =     ETIME,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:159:28: error: 'ETXTBSY' was not declared in this scope
       text_file_busy =     ETXTBSY,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:163:41: error: 'ENFILE' was not declared in this scope
       too_many_files_open_in_system =   ENFILE,
                                         ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:164:32: error: 'EMFILE' was not declared in this scope
       too_many_files_open =    EMFILE,
                                ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:165:28: error: 'EMLINK' was not declared in this scope
       too_many_links =     EMLINK,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:166:41: error: 'ELOOP' was not declared in this scope
       too_many_symbolic_link_levels =   ELOOP,
                                         ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:169:28: error: 'EOVERFLOW' was not declared in this scope
       value_too_large =    EOVERFLOW,
                            ^
/usr/local/gcc-arm/arm-none-eabi/include/c++/4.9.3/arm-none-eabi/armv7-m/bits/error_constants.h:172:32: error: 'EPROTOTYPE' was not declared in this scope
       wrong_protocol_type =    EPROTOTYPE
                                ^