clang_parseTransitionUnit2 gives error

Enes Albay albayenes at gmail.com
Sun Apr 17 11:27:53 BST 2022


Thanks for your help Sven,

I found something more, If I create a QApplication object after
clang_parseTranslationUnit2() it works.

QApplication prevents libclang calls somehow.


On Sun, Apr 17, 2022 at 12:59 PM Sven Brauch <mail at svenbrauch.de> wrote:

> Hi,
>
> sorry, I don't see anything going wrong here -- I anticipated maybe it
> would load 2 different versions of libclang but that doesn't seem to be
> the case :(
>
> Greetings!
>
>
> On 4/17/22 09:34, Enes Albay wrote:
> >
> >
> >
> > Sorry for the late reply. I tried LIBGL_ALWAYS_INDIRECT=1 ./helloworld
> > from stackoverflow.
> >
> >
> > I attached LD_DEBUG=libs output with Qt and without Qt to this email.
> >
> >
> >
> >
> >
> > On Fri, Apr 15, 2022 at 2:02 AM Sven Brauch <mail at svenbrauch.de
> > <mailto:mail at svenbrauch.de>> wrote:
> >
> >     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>
> >
> >      >
> >     <
> 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>
> >      > <mailto: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> <http://milianw.de
> >     <http://milianw.de>>
> >      >
> >      >
> >      >
> >      >
> >      > --
> >      > Enes Albay
> >
> >
> >
> > --
> > Enes Albay
>


-- 
Enes Albay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20220417/f9112789/attachment-0001.htm>


More information about the KDevelop-devel mailing list