clang_parseTransitionUnit2 gives error

Sven Brauch mail at svenbrauch.de
Fri Apr 15 00:02:54 BST 2022


Hi,

which solution did you try? The actual answer (not the comments) sounds 
plausible, we have heard of similar issues before, but that might not be 
easy to do on your system.

Maybe you can get further info with LD_DEBUG=libs set and checking if 
indeed two different versions of libclang are loaded along the road?

Greetings,
Sven


On 4/14/22 23:26, Enes Albay wrote:
> 
> I guess I found the reason for the error. Clang works if I comment out 
> the line "QApplication app(argc, argv);" Otherwise It gives error like this:
> 
> $ ./helloworld
> 4
> Unable to parse translation unit. Quitting.
> 
> As far as I understand this bug is related to this one 
> https://stackoverflow.com/questions/17953156/cannot-use-libclang-with-qt 
> <https://stackoverflow.com/questions/17953156/cannot-use-libclang-with-qt>
> 
> But the solution suggested in stackoverflow does not work for me. Do you 
> have any idea ?
> 
> /******************MAIN **************************/
> #include <QApplication>
> #include "clang-c/Index.h"
> 
> #include <iostream>
> using namespace std;
> 
> int main (int argc, char *argv[])
> {
>      QApplication app(argc, argv);
>     CXIndex index = clang_createIndex(0, 0);
>    CXTranslationUnit unit = nullptr;
> 
>    CXErrorCode code = clang_parseTranslationUnit2(
>      index,
>      "/media/enes/MyFiles/programming/cpp/cmakeExamples/ex1/main.cpp", 
> nullptr, 0,
>      nullptr, 0,
>      CXTranslationUnit_None, &unit);
> 
>    cerr << code << endl;
>    if (code != CXError_Success) {
>      cerr << "Unable to parse translation unit. Quitting." << endl;
>      exit(-1);
>    }
> 
>    return 0;
> }
> 
> 
> # CMakeLists.txt
> 
> cmake_minimum_required(VERSION 3.0)
> 
> project (helloworld)
> 
> set(LLVM_ROOT /usr/lib/llvm-13)
> set(QT_MIN_VERSION "5.15.2")
> 
> # Find Qt modules
> find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
>      Core    # QCommandLineParser, QStringLiteral
>      Widgets # QApplication
> )
> 
> find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config HINTS 
> ${LLVM_ROOT}/bin DOC "llvm-config executable" NO_DEFAULT_PATH)
> message(${LLVM_CONFIG_EXECUTABLE})
> set(Clang_DIR /usr/lib/llvm-13/cmake)
> 
> # Find CMake file for Clang
> find_package(Clang REQUIRED)
> 
> execute_process(
>          COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir
>          OUTPUT_VARIABLE LLVM_INCLUDE_DIRS
>          OUTPUT_STRIP_TRAILING_WHITESPACE
>          )
> 
> message(${LLVM_INCLUDE_DIRS})
> 
> execute_process(
>          COMMAND ${LLVM_CONFIG_EXECUTABLE} --libdir
>          OUTPUT_VARIABLE LLVM_LIBRARY_DIRS
>          OUTPUT_STRIP_TRAILING_WHITESPACE
>          )
> 
> include_directories(${LLVM_INCLUDE_DIRS})
> 
> set(helloworld_SRCS main.cpp)
> add_executable(helloworld ${helloworld_SRCS})
> target_link_libraries(helloworld
>      Qt5::Widgets
>      /usr/lib/llvm-13/lib/libclang.so
>      /usr/lib/llvm-13/lib/libclang-cpp.so.13
> )
> ~
> 
> 
> 
> On Tue, Apr 12, 2022 at 6:37 PM Milian Wolff <mail at milianw.de 
> <mailto:mail at milianw.de>> wrote:
> 
>     On Tuesday, April 12, 2022 5:33:38 PM CEST Enes Albay wrote:
>      > I found something. After removing clang and llvm from my system I
>     get the
>      > following error which is the same as before removing clang.
>      >
>      > I think the actual problem is clang_parseTranslationUnit2 can not
>     call
>      > clang even before removing clang
>      >
>      > Is there a way to verify such a situation?
> 
>     We use libclang directly, not clang. Try to ldd on the
>     kdevclangsupport or use
>     gdb and `info shared` to see where it loads that from. You didn't
>     remove all
>     of that yet apparently.
> 
>     -- 
>     Milian Wolff
>     http://milianw.de <http://milianw.de>
> 
> 
> 
> 
> -- 
> Enes Albay
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xA4AAD0019BE03F15.asc
Type: application/pgp-keys
Size: 3147 bytes
Desc: OpenPGP public key
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20220415/f132e8aa/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20220415/f132e8aa/attachment.sig>


More information about the KDevelop-devel mailing list