I tested LLVM compiler tool chain and builds a generic MFC application using LLVM-VS2010 as platform toolset from .vcproj. But what I need is just the Abstract Syntax Tree dump. I tried clang-check but shows the ff:
LLVM ERROR: Could not detect compilation database...json-compilation-database: Error while opening JSON database: no such file or directory.
Found out that json compilation database is generated by cmake (http://clang.llvm.org/docs/JSONCompilationDatabase.html).
Is there a way to skip compilation database and just produce ast-dump?
Related
I want to create a software-generated control flow diagram for this code using LLVM CFG https://github.com/inmcm/Simon_Speck_Ciphers/blob/master/C/speck.c
But when I followed the instructions given on the LLVM webpage (https://www.programmersought.com/article/61364910575/), and typed the following command: clang -S -emit-llvm simon.c -o g.ll
Terminal shows this error message:
clang: error: -emit-llvm cannot be used when linking
I am new to this tool and Linux, can someone please help?
I was able to generate the llvm IR and the CFG dot files for the above mentioned speck.c file. The message cannot be used when linking appears only when you haven't passed any special flags for output like -S, -c, etc. so I'm guessing you have made some typo in the command.
You can try using clang -save-temps speck.c command, which would generate the bitcode (.bc) file for the LLVM IR, which can be used in any place where the .ll file is used.
I am using Vim's YouCompleteMe C semantic completer installed with the --clang-completer flag. It complains that it can not find the 'omp.h' file used in the Eigen/Core library file. Error message is as follows:
In included file: 'omp.h' file not found /usr/include/eigen3/Eigen/Core:247:10: note: error occurred here [pp_file_not_found]
The code compiles and runs perfect, so that's why I know it is not a real issue and something wrong with YouCompleteMe. I have tried using both clang and clangd, it does not matter, same issue.
If I simply remove the -fopenmp from the compile_command.json file, it fixes the issue.
Thanks in advance.
The pre-built clangs from llvm.org don't include openmp. YCM includes a copy of the clang resource dir from the pre-built llvm.org packages, therefore 'omp.h' (which is part of the resource dir) is not found.
If you need to use openmp, then i suggest you set g:ycm_clangd_binary_path to point to a clangd that is installed alongside your llvm toolchain containing openmp.
After solving this Omitted code blocks from clang AST for ObjectiveC, I've tried it on a small Objective C .m file along with an appropriate compile_commands.json and it works properly and I get the entire syntax tree.
Now I'm trying to see if it's possible to run it on the entire xcodebuild
[
{
"directory" : "/Users/xx/Desktop/iOSApplication",
"command" : "xcodebuild clean build CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO -project /Users/xx/Desktop/iOSApplication/iOSApplication.xcodeproj/",
"file" : "iOSApplication.xcodeproj"
}
]
When I tried to then run clang-check -ast-dump /Users/xx/Desktop/iOSApplication/iOSApplication.xcodeproj it gives me the errors error: unknown argument: '-project' and error: unable to handle compilation, expected exactly one compiler job in ''
Is it actually possible to run the AST based checker on the entire xcodeproject? Or how should I go about compiling the files 1 at a time?
I've managed to generate the compile_commands.json by following this guide here http://docs.oclint.org/en/stable/guide/xcodebuild.html
However, I'd still like to be able to run my RecursiveASTVisitor on the entire projects. Or alternatively, pass in the xcode project and enumerate all the source files would probably work too.
Anyone has ideas how to go about passing entire xcodebuild project as parameter for RecursiveASTVisitor?
Right now I'm running my ASTVisitor like this ./MyASTChecker ~/Desktop/directory/sample1.m but I'd like to make it do something like ./MyASTChecker ~/Desktop/directory/sampleproject.xcodeproj
The way I do it is at compile time using scan-build. This works for me with cmake/make based projects.
scan-build --use-analyzer=clang -enable-checker <checker_name> make
This will read the makefile and build everything in there while running the specified checker on each file as it's compiled. If you only want to build with some flags or a specific target, you can do this:
scan-build --use-analyzer=clang -enable-checker <checker_name> make <build_options>
If you instead have a cmake based project. You might first want to generate a makefile in a build directory. I do this for that:
cmake <path_to_cmakelists> -DCMAKE_CXX_COMPILER=c++-analyzer -DCMAKE_CC_COMPILER=ccc-analyzer
This followed by scan-build from above will compile and run checker on the source files while each file is being compiled.
I have only tried this with CMAKE / MAKE but should work with xcode like this:
scan-build --use-analyzer=clang -enable-checker <checker_name> xcodebuild
and with build options
scan-build --use-analyzer=clang -enable-checker <checker_name> xcodebuild <build_options>
You can read more about scan-build here
I am using gcc 4.9.2 and trying to use gfortran in order to read and write hdf5 binary files. I am getting the following error:
USE HDF5
1
Fatal Error: File 'hdf5.mod' opened at (1) is not a GNU Fortran module file
I tried removing and reinstalling gfortran but no change. Any suggestion would be appreciated.
The HDF5 library (or at least, the Fortran interface part of it) needs to be compiled with the corresponding Fortran compiler and (major) version that you use for your own code as well.
I've compiled Z3 from sources at codeplex. Configuration details:
Operation system Debian 5.0 (Lenny)
GLIBC 2.7
GCC 4.4.3
OpenMP 4.3.4 (package version)
When I try to build the c example I get:
../../lib/libz3.so: undefined reference to `std::ctype<char>::_M_widen_init() const#GLIBCXX_3.4.11'
When I try to build the c++ example I get:
../../lib/libz3.so: undefined reference to `omp_init_nest_lock#OMP_3.0'
../../lib/libz3.so: undefined reference to `omp_unset_nest_lock#OMP_3.0'
../../lib/libz3.so: undefined reference to `omp_set_nest_lock#OMP_3.0'
../../lib/libz3.so: undefined reference to `omp_destroy_nest_lock#OMP_3.0'.
The examples mentioned were downloaded previously from Z3 website. When I build the test_capi example, which comes along with the source code, I get the union of the error messages above.
What is the nature of the problem? Are there any prerequisites for the system for using Z3?
On another Debian 6.0 machine everything goes smoothly.
Thanks in advance.
I'm assuming you are using the official src release or master branch. If that is the case, could you try to compile test_capi using in the test_capi directory?
gcc -o test_capi -I ../lib test_capi.c -L ../bin/external -lz3 -lstdc++ -lgomp
In the command above we are explicitly telling gcc to link with the C++ standard and OMP libraries.
For the c++ example, you just need to include -lgomp, since g++ will link with the C++ standard library by default. You can find other missing dependencies using ldd:
ldd ../bin/external/libz3.o
That being said, I'm working on a new build system for Z3, you can try it by getting the unstable branch from codeplex. Could you give a try? It would be great to have your feedback to make the build to go smoothly in many more platforms.