Compiling MQTT library encounters fd_mask error

I am trying to compile a third party MQTT library. The error is reported that the compiler can’t recognize the fd_mask type, the file where this error occurs doesn’t seem to come from my project, is there any good way to fix this error.

Hi @cuiw

This doesn’t look like a datatype which is built into B&R provided libraries, so in this case it is the responsibility of the third-party developer to define this datatype for you, or to tell you where it is defined.

You could try right-clicking on the library in the Logical View and selecting Properties, then go to the Dependencies tab. If this library has been well documented, the developer should have listed any required dependencies here. If you add all of these dependencies, the library will hopefully compile.

Another possibility is that this type is defined, but for some reason that definition is not compiling. If you do a Find-In-Files (Ctrl+Shift+F) and search for the name of the datatype, you may find it somewhere else in your project. Then you can double check that the file where it’s defined is added to the software configuration and compiling correctly.

Unfortunately, if you still cannot find the definition, you’ll either have to reach out to the developer, remove all references to this datatype in your code, or define the datatype yourself.

1 Like

Thank you for your answer, in fact I found that the file that reported the error belonged to a file in AS.

The project was upgraded from AS4.7 to 4.12, and strangely enough if I open the project in AS4.10 it compiles through.

Hello,
this type is or should be defined by the standard C header files.
However, B&R is not providing the full set of C libraries and function. Check this page in Automation Help.

What I’ve seen in the installation folders (this is where the path from the error is pointing) that the GCC V6.3.0 does not have this type declared.
GCC V4.1.2 does have it declared (at least in my 4.12 installation) but it is guarded by some defines and the following comment, starting at line 205 of the “types.h” file.

# if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) 
/* We don't define fd_set and friends if we are compiling POSIX
   source, or if we have included (or may include as indicated
   by __USE_W32_SOCKETS) the W32api winsock[2].h header which
   defines Windows versions of them.   Note that a program which
   includes the W32api winsock[2].h header must know what it is doing;
   it must not call the cygwin32 select function.
*/

So I expect, that Automation Studio and Automation Runtime is not able use this functions / makros since the basic functions are not supported and excluded via other defines. Maybe you want to check the MQTT functionblock from the B&R Github.

Maybe in future, with Automation Software 6, where more C functions are available and also GCC 11.3.0, this might be supported, but no guarantees.

BR Fabian

2 Likes

Thanks for the heads up, I paid attention to the comments in the types.h file. Then compared it with the types.h file in AS410 that compiled through, I found that the definition of fd_mask was commented out in AS412, and after uncommenting it, it compiled fine. I don’t know why AS412 commented out that definition though.

Great that it compiling :+1:

It is strange that a standard header file is different. I installed my Automation Studio just recently and the declaration was active.

As a general advice, please do not edit the header files form the installation directory since this can cause some strange behaviors.

In this case I think the edit is reasonable and can be done. :smile:

All the best
Fabian

1 Like

I remembered that I received a project some time ago which defined fd_mask by itself and duplicated the definition in types.h, so I commented out the fd_mask in types.h. I forgot to restore it after I compiled the program.
It was my mistake, thank you very much for your help.:grinning:

3 Likes

Hello,could you share your MATT library?
I need it very much.
Thank you!@ cuiw

Hello, attached is my project which is mainly used for learning to compile third party embedded libraries from: GitHub - menudoproblema/libemqtt: Embedded C client library for the MQTT protocol. If you need to use stable MQTT libraries, you can use: GitHub - br-automation-com/paho.mqtt.c-ar: MQTT Client for Automation Runtime based on eclipse/paho.mqtt.c
EmbeddedMQTT_412.zip (149.7 KB)

3 Likes

thanks
Best regards!