Hi, I ran into an error when I was using the function extractor. After executing the code cmake ../ -DLLVM_DIR=${LLVM_BUILD_DIR}/lib/cmake/llvm -DClang_DIR=${LLVM_BUILD_DIR}/lib/cmake/clang
in README.md, I could not find the "shared library file in the /lib/ directory" in my LLVM build folder. It seems that there is something to specify in the step to "create the Makefiles for your LLVM build then compile it". I could not find "libFunctionExtractor.so" either.
Below is my working process.
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- Found LLVM 15.0.7
-- Using LLVMConfig.cmake in: /usr/lib/llvm-15/build/lib/cmake/llvm
LLVM STATUS:
Definitions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
Includes /usr/lib/llvm-15/include
/usr/lib/llvm-15/include
Libraries /usr/lib/llvm-15/lib
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chongying/Code_generator/Angha/src/extractor/build
[ 50%] Building CXX object FunctionExtractor/CMakeFiles/FunctionExtractor.dir/FunctionExtractor.cpp.o
/home/chongying/Code_generator/Angha/src/extractor/FunctionExtractor/FunctionExtractor.cpp: In constructor ‘WholeFileVisitor::WholeFileVisitor(clang::CompilerInstance*, llvm::StringRef)’:
/home/chongying/Code_generator/Angha/src/extractor/FunctionExtractor/FunctionExtractor.cpp:103:32: error: no match for ‘operator=’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘llvm::StringRef’)
103 | _outFileName = file;
| ^~~~
In file included from /usr/include/c++/11/string:55,
from /usr/lib/llvm-15/include/llvm/ADT/Hashing.h:54,
from /usr/lib/llvm-15/include/llvm/ADT/Optional.h:19,
from /usr/lib/llvm-15/include/llvm/Support/Casting.h:17,
from /usr/lib/llvm-15/include/clang/Basic/LLVM.h:21,
from /usr/lib/llvm-15/include/clang/Basic/DiagnosticIDs.h:17,
from /usr/lib/llvm-15/include/clang/Basic/Diagnostic.h:17,
from /usr/lib/llvm-15/include/clang/AST/NestedNameSpecifier.h:18,
from /usr/lib/llvm-15/include/clang/AST/Type.h:21,
from /usr/lib/llvm-15/include/clang/AST/CanonicalType.h:17,
from /usr/lib/llvm-15/include/clang/AST/ASTContext.h:19,
from /usr/lib/llvm-15/include/clang/AST/AST.h:17,
from /home/chongying/Code_generator/Angha/src/extractor/FunctionExtractor/FunctionExtractor.cpp:41:
/usr/include/c++/11/bits/basic_string.h:679:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
679 | operator=(const basic_string& __str)
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:679:37: note: no known conversion for argument 1 from ‘llvm::StringRef’ to ‘const std::__cxx11::basic_string<char>&’
679 | operator=(const basic_string& __str)
| ~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/11/bits/basic_string.h:689:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
689 | operator=(const _CharT* __s)
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:689:31: note: no known conversion for argument 1 from ‘llvm::StringRef’ to ‘const char*’
689 | operator=(const _CharT* __s)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/basic_string.h:700:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
700 | operator=(_CharT __c)
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:700:24: note: no known conversion for argument 1 from ‘llvm::StringRef’ to ‘char’
700 | operator=(_CharT __c)
| ~~~~~~~^~~
/usr/include/c++/11/bits/basic_string.h:717:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
717 | operator=(basic_string&& __str)
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:717:32: note: no known conversion for argument 1 from ‘llvm::StringRef’ to ‘std::__cxx11::basic_string<char>&&’
717 | operator=(basic_string&& __str)
| ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/11/bits/basic_string.h:785:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::initializer_list<_Tp>) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
785 | operator=(initializer_list<_CharT> __l)
| ^~~~~~~~
/usr/include/c++/11/bits/basic_string.h:785:42: note: no known conversion for argument 1 from ‘llvm::StringRef’ to ‘std::initializer_list<char>’
785 | operator=(initializer_list<_CharT> __l)
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/home/chongying/Code_generator/Angha/src/extractor/FunctionExtractor/FunctionExtractor.cpp: In member function ‘virtual bool FunctionVisitor::VisitFunctionDecl(clang::FunctionDecl*)’:
/home/chongying/Code_generator/Angha/src/extractor/FunctionExtractor/FunctionExtractor.cpp:189:61: error: could not convert ‘(& mng)->clang::SourceManager::getFilename(D->clang::FunctionDecl::getSourceRange().clang::SourceRange::getBegin())’ from ‘llvm::StringRef’ to ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’}
189 | inputFile = validateFilename(mng.getFilename(D->getSourceRange().getBegin()));
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| llvm::StringRef
gmake[2]: *** [FunctionExtractor/CMakeFiles/FunctionExtractor.dir/build.make:76: FunctionExtractor/CMakeFiles/FunctionExtractor.dir/FunctionExtractor.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:208: FunctionExtractor/CMakeFiles/FunctionExtractor.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2