bkryza / clang-uml

Customizable automatic UML diagram generator for C++ based on Clang.
Apache License 2.0
611 stars 44 forks source link

Issue with standard headers cstddef on Ubuntu 22.04 #282

Open TheWorldOfCode opened 5 months ago

TheWorldOfCode commented 5 months ago

Hello

Clang UML is a great tool and I have been using it for a couple of years on work-related projects. We have just updated from Ubuntu Focal to Ubuntu Jammy.

On Ubuntu Jammy it complaining that it cannot locate cstddef when processing boost/uuid/uuid.hpp. When I attempt to solve the issue new errors are generated.

  1. Missing __cstddef___. Solution --add-compile-flag '-I/usr/include/c++/11'
  2. Missing bits/c++config.h. Solution --add-compile-flag '-I/usr/include/x86_64-linux-gnu/c++/11'
  3. Missing omp.h. Solution --add-compile-flag '-I/usr/lib/gcc/x86_64-linux-gnu/11/include
  4. Errors in _xmmintrin.h. Here it complains that use of undeclared identifier 'bultin_ia32_cvsi642ss'; did you mean 'builtin_ia32_cvtsd2ss'

Clang - UML

clang-uml 0.5.2
Copyright (C) 2021-2024 Bartek Kryza <bkryza@gmail.com>
Linux x86_64 5.15.0-105-generic
Built against LLVM/Clang libraries version: 15.0.7
Using LLVM/Clang libraries version: Ubuntu clang version 15.0.7

Configuration dump

compilation_database_dir: /home/user/workspace/build
output_directory: /home/user/workspace/ropca/docs/uml
__parent_path: /home/user/workspace
comment_parser: plain
debug_mode: false
git:
  branch: ****
  revision: *****
  commit: *****
  toplevel: /home/user/workspace
relative_to: /home/user/workspace
generate_metadata: true
diagrams:
  arthur:
    type: class
    comment_parser: plain
    debug_mode: false
    exclude:
      namespaces:
        - rw
        - std
        - cv
        - Qt
        - QChar
        - QArrayData
        - QByteArray
        - QString
        - QRegExp
        - QTime
        - QDate
        - QLocale
        - QIODevice
        - QAbstractTransition

        - QAbstractItemModel
        - QTextStream
        - QUrl
        - QUuid
        - QCborError
        - QEventLoop
        - QtPrivate
        - QCborValue
        - QCborStreamReader
        - __cxxabiv1
        - __gnu_cxx
        - QVariant
        - QCommandLineOption
        - QEvent
        - QCommandLineParser
        - QCryptographicHash
        - QDataStream
        - QElapsedTimer
        - QDeadlineTimer
        - QDir
        - QDirIterator
        - QEasingCurve
        - QMapNodeBase
        - QMutex
        - QFutureInterfaceBase
        - QHistoryState
        - QItemSelectionModel
        - QJsonValue
        - QJsonParseError
        - QJsonDocument
        - QLibrary
        - QLibraryInfo
        - QLineF
        - QLockFile
        - QMetaMethod
        - QTextCodec
        - QThread
        - QTimeLine
        - QTimeZone
        - QSysInfo
        - QRegularExpression
        - QDebug
        - QtMetaType
        - QtMetaTypePrivate
        - QAbstractAnimation
        - QMetaType
        - QMetaObject
        - QInternal
        - QtGlobalStatic
        - ropca::utility::printing
        - Eigen
      elements:
        - QCborTag
        - QCborKnownTags
        - QCborSimpleType
        - QtMsgType
        - QCborNegativeInteger
    glob:
      - ropca/src/gui/*_backend.cpp
    include:
      paths:
        - ropca/src
    plantuml:
      after:
        - remove @unlinked
    generate_metadata: true
    generate_method_arguments: none
    generate_concept_requirements: true
    generate_packages: false
    include_relations_also_as_members: false
    member_order: lexical
    package_type: namespace
    generate_template_argument_dependencies: true
    skip_redundant_dependencies: true

  platform_control_detect_joint:
    type: sequence
    from:
      - function: platform_control::detect_joints(hand_type)
    comment_parser: plain
    debug_mode: false
    exclude:
      namespaces:
        - cppflow
        - rw
        - ropca::utility::logging
      elements:
        - config_class
    glob:
      - ropca/src/control/platform_control.cpp
    include:
      paths:
        - ropca/src
    generate_metadata: true
    combine_free_functions_into_file_participants: false
    inline_lambda_messages: false
    generate_condition_statements: false
    generate_method_arguments: full
    generate_return_types: false
    generate_message_comments: false
    message_comment_width: 25
  platform_control_scan_hand:
    type: sequence
    from:
      - function: platform_control::scan_hand(hand_type)
    comment_parser: plain
    debug_mode: false
    exclude:
      namespaces:
        - cppflow
        - rw
        - ropca::utility::logging
      elements:
        - config_class
        - printable_pos
    glob:
      - ropca/src/control/platform_control.cpp
    include:
      paths:
        - ropca/src/control
        - ropca/src
    generate_metadata: true
    combine_free_functions_into_file_participants: false
    inline_lambda_messages: false
    generate_condition_statements: false
    generate_method_arguments: full
    generate_return_types: false
    generate_message_comments: false
    message_comment_width: 25
  platform_control_scan_joint:
    type: sequence
    from:
      - function: platform_control::scan_joint(joint_index)
    comment_parser: plain
    debug_mode: false
    exclude:
      namespaces:
        - cppflow
        - rw
        - ropca::utility::logging
        - printable_pos
      elements:
        - config_class
    glob:
      - ropca/src/control/platform_control.cpp
    include:
      paths:
        - ropca/src/control
        - ropca/src
    generate_metadata: true
    combine_free_functions_into_file_participants: false
    inline_lambda_messages: false
    generate_condition_statements: false
    generate_method_arguments: full
    generate_return_types: false
    generate_message_comments: false
    message_comment_width: 25
bkryza commented 5 months ago

@TheWorldOfCode

TL;DR: Add this to your command line --add-compile-flag "-DBOOST_UUID_NO_SIMD"

Full explanation:

I've managed to reproduce your issue on Ubuntu Jammy

❯ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

with the following project:

main.cpp

#include <QCoreApplication>

#include <boost/uuid/uuid.hpp>

namespace my_app {
struct A {};

struct B : public A {};
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    boost::uuids::uuid tag;

    return a.exec();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.14)

project(issue282 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

FIND_PACKAGE(Boost REQUIRED)

add_executable(issue282
  main.cpp
)
target_link_libraries(issue282 Qt${QT_VERSION_MAJOR}::Core)
target_include_directories(issue282 PUBLIC ${Boost_INCLUDE_DIRS})

include(GNUInstallDirs)
install(TARGETS issue282
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

.clang-uml

compilation_database_dir: build
output_directory: docs/diagrams
diagrams:
  my_app_class_diagram:
    type: class
    glob:
      - "*.cpp"
    using_namespace:
      - my_app
    exclude:
      namespaces:
        - std

Then when I ran clang-uml like this:

clang-uml -vvv

it worked. However if I added:

clang-uml -vvv --query-driver .

I was getting the same errors as you. The --query-driver . basically automates what you did by adding your flags manually. This however, forces Clang to use GCC headers, where it fails to parse some internal headers related to SSE and SIMD low level operations.

Fortunately using these low level optimizations can be disabled in Boost, like this (of course this will not affect your actual build - only diagram generation):

clang-uml -vvv --add-compile-flag "-DBOOST_UUID_NO_SIMD"

You can also try to remove the include flags you added manually from the config and just run:

clang-uml -vvv --query-driver . --add-compile-flag "-DBOOST_UUID_NO_SIMD"

With the latter on my system I get the diagram:

@startuml
class "A" as C_0001961966708590071804
class C_0001961966708590071804 {
__
+tag : boost::uuids::uuid
}
class "B" as C_0000521024381453213179
class C_0000521024381453213179 {
__
}
C_0001961966708590071804 <|-- C_0000521024381453213179

'Generated with clang-uml, version 0.5.2-31-ge21c2d2
'LLVM version Ubuntu clang version 17.0.6 (++20231209124227+6009708b4367-1~exp1~20231209124336.77)
@enduml

If this doesn't help please share if possible a sample entry from your compile_commands.json maybe I'll notice sth...

TheWorldOfCode commented 5 months ago

Many thanks for the fast response. Unfortunately, it didn't solve the issue.

I have appended the compile_commands.json as requested.

I have done some additional tests if I add the option --add-compile-flag '-mno-sse'. compile_commands.json

Adding the compile flag solves the issue with xmmintrin.h, but now it is complaining about std::nullopt.

/home/user/workspace/ropca/external_libraries/robotics/include/robotics/hardware/kuka/actions/types/motion.h:30:89: error: no viable conversion from 'const std::nullopt_t' to 'int'
                                   const std::optional<BoundedValue<float, 0.0f, 1.0f>> blendingRel = std::nullopt, const std::optional<float> blendingCart = std::nullopt,
bkryza commented 5 months ago

@TheWorldOfCode That I cannot reproduce - if possible you could try to install newer LLVM (e.g. 17) and rebuild clang-uml using:

LLVM_VERSION=17 make release

and then try with both --add-compile-flag '-mno-sse' and --query-driver ....

bkryza commented 5 months ago

@TheWorldOfCode Also, are you able to reproduce the problem using the above simple project, for instance by modifying the main.cpp:

#include <QCoreApplication>
#include <boost/uuid/uuid.hpp>

#include <optional>

namespace my_app {
struct AAA {};
struct A {
    boost::uuids::uuid tag;
    void foo(const std::optional<AAA> arg1 = std::nullopt) {
    }
};

struct B : public A {};
}  // namespace my_app

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);

    return a.exec();
}

?