Closed allbluelai closed 6 months ago
@allbluelai Strange, it works for me, can you paste the output of the following command:
cat debug/compile_commands.json | grep t20001.cc
and also:
clang-uml --version
@bkryza Hello,
cat debug/compile_commands.json | grep t20001.cc ```sh $ cat build/compile_commands.json | grep t20001.cc "command": "/usr/bin/c++ -isystem /usr/include/c++/11 -isystem /usr/include/x86_64-linux-gnu/c++/11 -isystem /usr/include/c++/11/backward -isystem /usr/lib/gcc/x86_64-linux-gnu/11/include -isystem /usr/local/include -isystem /usr/include/x86_64-linux-gnu -isystem /usr/include -o CMakeFiles/main.dir/t20001.cc.o -c /home/john/Documents/test/t20001.cc", "file": "/home/john/Documents/test/t20001.cc"
clang-uml --version
$ clang-uml --version clang-uml 0.5.2 Copyright (C) 2021-2024 Bartek Kryza <bkryza@gmail.com> Linux x86_64 6.5.0-25-generic Built against LLVM/Clang libraries version: 15.0.7 Using LLVM/Clang libraries version: Ubuntu clang version 15.0.7
@allbluelai Ok, so it seems that for some reason your CMake does not add the -std=c++17
flag to the compilation command - and std::variant
requires at least C++ 17.
Can you try to add -std=c++17
manually to the compile_commands.json
like that:
"command": "/usr/bin/c++ -std=c++17 -isystem /usr/include/c++/11 ...
and see if this helps. If yes, you'll have to figure out how to force CMake to add this flag to your compile_commands.json
during build.
One idea is to add the following line at the end of your CMakeLists.txt
:
cmake_minimum_required(VERSION 3.0)
project(testMain)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
add_executable(main main.cpp t20001.cc)
target_compile_features(main PRIVATE cxx_std_17)
Can you try to add
-std=c++17
manually to thecompile_commands.json
like that:"command": "/usr/bin/c++ -std=c++17 -isystem /usr/include/c++/11 ...
and see if this helps.
Yes, it helps.
target_compile_features(main PRIVATE cxx_std_17)
This does not work for me. But I use the new `CMakeLists.txt':
cmake_minimum_required(VERSION 3.0) project(testMain) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") # new line # set(CMAKE_CXX_STANDARD 17) # delete it, no need set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) add_executable(main main.cpp t20001.cc)
It works. And
compile_commands.json
fort20001.cc
:{ "directory": "/home/john/Documents/test/build", "command": "/usr/bin/c++ -isystem /usr/include/c++/11 -isystem /usr/include/x86_64-linux-gnu/c++/11 -isystem /usr/include/c++/11/backward -isystem /usr/lib/gcc/x86_64-linux-gnu/11/include -isystem /usr/local/include -isystem /usr/include/x86_64-linux-gnu -isystem /usr/include -std=c++17 -o CMakeFiles/main.dir/t20001.cc.o -c /home/john/Documents/test/t20001.cc", "file": "/home/john/Documents/test/t20001.cc" }
@bkryza Finally, thank you again. I'll close it.
Actually c++17 support has been added in CMake 3.8, I suggest to upgrade the cmake minimum version to 3.8 https://cmake.org/cmake/help/latest/release/3.8.html#id6
@leha-bot Hi,
Actually c++17 support has been added in CMake 3.8, I suggest to upgrade the cmake minimum version to 3.8 https://cmake.org/cmake/help/latest/release/3.8.html#id6
Sorry, using CMake 3.8 didn't help for me. Even if I use CMake 3.22.1 (the latest version in my OS) it doesn't help.
My CMakeLists.txt
:
cmake_minimum_required(VERSION 3.22.1)
project(testMain)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") # comment out
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
add_executable(main main.cpp t20001.cc)
target_compile_features(main PUBLIC cxx_std_17)
And no -std=c++17
in compile_commands.json
:
{
"directory": "/home/john/Documents/test/build",
"command": "/usr/bin/c++ -isystem /usr/include/c++/11 -isystem /usr/include/x86_64-linux-gnu/c++/11 -isystem /usr/include/c++/11/backward -isystem /usr/lib/gcc/x86_64-linux-gnu/11/include -isystem /usr/local/include -isystem /usr/include/x86_64-linux-gnu -isystem /usr/include -o CMakeFiles/main.dir/t20001.cc.o -c /home/john/Documents/test/t20001.cc",
"file": "/home/john/Documents/test/t20001.cc"
}
OS:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
Hello, I added the following in t20001.cc:
my
CMakeLists.txt
:main.cpp just std::cout "hello world" code.
When I ran
clang-uml
, it outputed:I used CMakeLists.txt to set CPP compiler as C++ 17/20. (see
set(CMAKE_CXX_STANDARD 17)
inCMakeLists.txt
) The results in t20001 PlantUML only worked for C++ 20, and failed for C++ 17.