<div dir="ltr"><br><div>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:</div><div><br></div><div>$ ./helloworld<br>4<br>Unable to parse translation unit. Quitting.<br></div><div><br></div><div>As far as I understand this bug is related to this one <a href="https://stackoverflow.com/questions/17953156/cannot-use-libclang-with-qt">https://stackoverflow.com/questions/17953156/cannot-use-libclang-with-qt</a></div><div><br></div><div>But the solution suggested in stackoverflow does not work for me. Do you have any idea ?</div><div><br></div><div>/******************MAIN **************************/</div><div>#include <QApplication><br>#include "clang-c/Index.h"<br> <br>#include <iostream><br>using namespace std;<br> <br>int main (int argc, char *argv[])<br>{<br> QApplication app(argc, argv);<br> CXIndex index = clang_createIndex(0, 0);<br> CXTranslationUnit unit = nullptr;<br> <br> CXErrorCode code = clang_parseTranslationUnit2(<br> index,<br> "/media/enes/MyFiles/programming/cpp/cmakeExamples/ex1/main.cpp", nullptr, 0,<br> nullptr, 0,<br> CXTranslationUnit_None, &unit);<br> <br> cerr << code << endl;<br> if (code != CXError_Success) {<br> cerr << "Unable to parse translation unit. Quitting." << endl;<br> exit(-1);<br> }<br> <br> return 0;<br>}<br> <br><br></div><div># CMakeLists.txt</div><div><br></div>cmake_minimum_required(VERSION 3.0)<br> <br>project (helloworld)<br> <br>set(LLVM_ROOT /usr/lib/llvm-13)<br>set(QT_MIN_VERSION "5.15.2")<br> <br># Find Qt modules<br>find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS<br> Core # QCommandLineParser, QStringLiteral<br> Widgets # QApplication<br>)<br> <br>find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config HINTS ${LLVM_ROOT}/bin DOC "llvm-config executable" NO_DEFAULT_PATH) <br>message(${LLVM_CONFIG_EXECUTABLE})<br>set(Clang_DIR /usr/lib/llvm-13/cmake)<br> <br># Find CMake file for Clang<br>find_package(Clang REQUIRED)<br> <br>execute_process(<br> COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir<br> OUTPUT_VARIABLE LLVM_INCLUDE_DIRS<br> OUTPUT_STRIP_TRAILING_WHITESPACE<br> )<br> <br>message(${LLVM_INCLUDE_DIRS})<br> <br>execute_process(<br> COMMAND ${LLVM_CONFIG_EXECUTABLE} --libdir<br> OUTPUT_VARIABLE LLVM_LIBRARY_DIRS<br> OUTPUT_STRIP_TRAILING_WHITESPACE<br> )<br> <br>include_directories(${LLVM_INCLUDE_DIRS})<br> <br>set(helloworld_SRCS main.cpp)<br>add_executable(helloworld ${helloworld_SRCS})<br>target_link_libraries(helloworld<br> Qt5::Widgets<br> /usr/lib/llvm-13/lib/libclang.so<br> /usr/lib/llvm-13/lib/libclang-cpp.so.13<br>) <br><div>~ <br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 12, 2022 at 6:37 PM Milian Wolff <<a href="mailto:mail@milianw.de">mail@milianw.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tuesday, April 12, 2022 5:33:38 PM CEST Enes Albay wrote:<br>
> I found something. After removing clang and llvm from my system I get the<br>
> following error which is the same as before removing clang.<br>
> <br>
> I think the actual problem is clang_parseTranslationUnit2 can not call<br>
> clang even before removing clang<br>
> <br>
> Is there a way to verify such a situation?<br>
<br>
We use libclang directly, not clang. Try to ldd on the kdevclangsupport or use <br>
gdb and `info shared` to see where it loads that from. You didn't remove all <br>
of that yet apparently.<br>
<br>
-- <br>
Milian Wolff<br>
<a href="http://milianw.de" rel="noreferrer" target="_blank">http://milianw.de</a><br>
<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div style="text-align:left">Enes Albay</div></div></div>