Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cannot find OpenMP header omp.h #61

Open
XuehaiPan opened this issue Dec 19, 2023 · 0 comments
Open

[BUG] Cannot find OpenMP header omp.h #61

XuehaiPan opened this issue Dec 19, 2023 · 0 comments

Comments

@XuehaiPan
Copy link

XuehaiPan commented Dec 19, 2023

Hi, I'm currently developing a feature that aims to replace the system-installed clang-tidy with the version available as a PyPI package. However, I've encountered a challenge: the clang-tidy installed via pip seems unable to locate the omp.h header file, which is causing some issues. Interestingly, the version of clang-tidy that's installed using apt does not have this problem and functions correctly. I'm looking for insights or suggestions on how to resolve this discrepancy.

There is no omp.h shipped with the wheel in site-packages/clang_tidy/data/lib/clang/17/include. It also not looking for the system include directory which contains omp.h (/usr/lib/llvm-14/lib/clang/14.0.0/include).

Reproduce script:

sudo apt update && sudo apt install -y build-essential libomp-dev
sudo apt install -y python3-dev python3-venv

python3 -m venv venv
source venv/bin/activate
pip3 install clang-tidy

cat > test.cpp <<EOF
#include <omp.h>
#include <stdio.h>

int main() {
#pragma omp parallel for
  for (int i = 0; i < 10; i++) {
    int tid = omp_get_thread_num();
    printf("Hello World from thread = %d\n", tid);
  }
  return 0;
}
EOF

clang-tidy --extra-arg=-v test.cpp

Results in docker:

$ docker run -it --rm -h ubuntu --pull always ubuntu:latest
root@ubuntu:/# apt update && apt install -y build-essential libomp-dev
root@ubuntu:/# find / -name 'omp.h'
/usr/lib/gcc/x86_64-linux-gnu/11/include/omp.h
/usr/lib/llvm-14/lib/clang/14.0.0/include/omp.h

root@ubuntu:/# cat > test.cpp <<EOF
#include <omp.h>
#include <stdio.h>

int main() {
#pragma omp parallel for
  for (int i = 0; i < 10; i++) {
    int tid = omp_get_thread_num();
    printf("Hello World from thread = %d\n", tid);
  }
  return 0;
}
EOF

root@ubuntu:/# g++ -fopenmp test.cpp -o a.out && ./a.out
Hello World from thread = 0
Hello World from thread = 3
Hello World from thread = 4
Hello World from thread = 8
Hello World from thread = 5
Hello World from thread = 6
Hello World from thread = 1
Hello World from thread = 7
Hello World from thread = 9
Hello World from thread = 2

clang-tidy from PyPI:

root@ubuntu:/# apt install -y python3-dev python3-venv
root@ubuntu:/# python3 -m venv venv
root@ubuntu:/# source venv/bin/activate
(venv) root@ubuntu:/# pip3 install clang-tidy
Collecting clang-tidy
  Downloading clang_tidy-17.0.1-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 34.0/34.0 MB 947.2 kB/s eta 0:00:00
Installing collected packages: clang-tidy
Successfully installed clang-tidy-17.0.1

(venv) root@ubuntu:/# find / -name 'omp.h'
/usr/lib/gcc/x86_64-linux-gnu/11/include/omp.h
/usr/lib/llvm-14/lib/clang/14.0.0/include/omp.h

(venv) root@ubuntu:/# clang-tidy --extra-arg=-v test.cpp
Resource filename: /venv/lib/python3.10/site-packages/clang_tidy/data/bin/clang-tidy 
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cpp"
No compilation database found in / or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
clang version 17.0.1 (https://github.com/ssciwr/clang-tidy-wheel f518fa02ba2535ce69460b278117bd848ddbdeae)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /venv/lib/python3.10/site-packages/clang_tidy/data/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
clang Invocation:
 "/venv/lib/python3.10/site-packages/clang_tidy/data/bin/clang-tool" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-fsyntax-only" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-v" "-fcoverage-compilation-dir=/" "-resource-dir" "/venv/lib/python3.10/site-packages/clang_tidy/data/lib/clang/17" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward" "-internal-isystem" "/venv/lib/python3.10/site-packages/clang_tidy/data/lib/clang/17/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir=/" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "/test.cpp"

clang -cc1 version 17.0.1 based upon LLVM 17.0.1 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11
 /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11
 /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward
 /venv/lib/python3.10/site-packages/clang_tidy/data/lib/clang/17/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
1 error generated.
Error while processing /test.cpp.
/test.cpp:1:10: error: 'omp.h' file not found [clang-diagnostic-error]
    1 | #include <omp.h>
      |          ^~~~~~~
Found compiler error(s).
(venv) root@ubuntu:/# echo $?
1

clang-tidy installed by apt:

root@ubuntu:/# apt install -y clang-tidy
root@ubuntu:/# find / -name 'omp.h'
/usr/lib/gcc/x86_64-linux-gnu/11/include/omp.h
/usr/lib/llvm-14/lib/clang/14.0.0/include/omp.h

root@ubuntu:/# clang-tidy --extra-arg=-v test.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cpp"
No compilation database found in / or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
Ubuntu clang version 14.0.0-1ubuntu1.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-14/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
clang Invocation:
 "/usr/lib/llvm-14/bin/clang-tool" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-fsyntax-only" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-v" "-fcoverage-compilation-dir=/" "-resource-dir" "/usr/lib/llvm-14/lib/clang/14.0.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward" "-internal-isystem" "/usr/lib/llvm-14/lib/clang/14.0.0/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir=/" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "/test.cpp"

clang -cc1 version 14.0.0 based upon LLVM 14.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11
 /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11
 /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward
 /usr/lib/llvm-14/lib/clang/14.0.0/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
root@ubuntu:/# echo $?
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant