Skip to content

Compilation error due to missing pthread.h in LogModule on Linux #23

@yarduoc

Description

@yarduoc

When attempting to compile the module on Ubuntu 24.04, the compilation fails due to the absence of pthread.h in the log_module.cpp file. Specifically, the error messages point to the lack of declaration for pthread_mutex_init, pthread_mutex_lock, and pthread_mutex_unlock.

Here’s the error output encountered:

error: ‘pthread_mutex_init’ was not declared in this scope; did you mean ‘pthread_mutex_t’?
error: ‘pthread_mutex_unlock’ was not declared in this scope; did you mean ‘pthread_mutex_t’?
error: ‘pthread_mutex_lock’ was not declared in this scope; did you mean ‘pthread_mutex_t’?

Looking at the log_module.h, it appears that the inclusion of pthread.h has been commented out under the #else directive for Linux:

#ifndef LINUX
#include <windows.h>
#else
// #include <pthread.h>
#include <stdarg.h>
#define printf_s(fileptr,str)  (fprintf(fileptr,"%s",str))
#define __in
#endif // ??????????????????????

The code compiles perfectly when the commented-out line (#include <pthread.h>) is uncommented.

Questions:

  • Was the exclusion of pthread.h intentional for Linux, or is this an oversight?
  • Is there a specific reason for this exclusion that I should be aware of?
  • What would be the recommended approach for compiling the package without running into this error?

Environment:

  • Operating System: Ubuntu 24.04 (x86_64 architecture)
  • Kernel Version: 6.8.0-50-generic
  • ROS 2 Distribution: Jazzy
  • C++ Compiler: GCC 13.3.0
  • CMake Version: 3.28.3
  • Colcon Version: 0.18.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions