Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:37:33+00:00 2026-06-10T09:37:33+00:00

I feel like I’m missing something very simple here. I want to play around

  • 0

I feel like I’m missing something very simple here. I want to play around with clang, so as a starting point I followed the code example in this video, around 3:40. The code is as follows:

#include "clang-c/Index.h" // Note: These two lines were 
#include <stdio.h>         // omitted from the video slides
int main(int argc, char *argv[])
{
    CXIndex Index = clang_createIndex(0, 0);
    CXTranslationUnit TU = clang_parseTranslationUnit(Index, 0, argv, argc, 0, 0, CXTranslationUnit_None);
    for (unsigned I = 0, N = clang_getNumDiagnostics(TU); I != N; ++I)
    {
        CXDiagnostic Diag = clang_getDiagnostic(TU, I);
        CXString String = clang_formatDiagnostic(Diag, clang_defaultDiagnosticDisplayOptions());
        fprintf(stderr, "%s\n", clang_getCString(String));
        clang_disposeString(String);
    }
    clang_disposeTranslationUnit(TU);
    clang_disposeIndex(Index);
    return 0;
}

In the video, he does not states that he’s omitted the two #include directives. I think I correctly filled those in in my example above. He also omits how the file was compiled and linked, which is the part I’m having trouble with. Following the instructions here I checked out and compiled clang and llvm. The files were checked out to ~/src/llvm then compiled from ~/src/build (just as the instructions say), and now I’m trying to make the simple test project above in ~/src/test. Below is how I’m calling gcc, and the output.

gcc -I../llvm/tools/clang/include/ -L../build/Debug+Asserts/lib/ -lclang main.cpp -o test
/tmp/ccrpABsq.o: In function `main':
main.cpp:(.text+0x24): undefined reference to `clang_createIndex'
main.cpp:(.text+0x5f): undefined reference to `clang_parseTranslationUnit'
main.cpp:(.text+0x74): undefined reference to `clang_getNumDiagnostics'
main.cpp:(.text+0x8b): undefined reference to `clang_getDiagnostic'
main.cpp:(.text+0x93): undefined reference to `clang_defaultDiagnosticDisplayOptions'
main.cpp:(.text+0xab): undefined reference to `clang_formatDiagnostic'
main.cpp:(.text+0xc0): undefined reference to `clang_getCString'
main.cpp:(.text+0xed): undefined reference to `clang_disposeString'
main.cpp:(.text+0x10d): undefined reference to `clang_disposeTranslationUnit'
main.cpp:(.text+0x118): undefined reference to `clang_disposeIndex'
collect2: ld returned 1 exit status
make: *** [all] Error 1

I checked ~/build/Debut+Asserts/lib and there is both libclang.a and libclang.so in that directory. I’m not sure what I’m doing wrong. I’ve tried googling around and haven’t found any tips, or instructions on what I should be linking against. Regardless, I’ve tried a few different things and nothing seems to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:37:34+00:00Added an answer on June 10, 2026 at 9:37 am

    Put -lclang after main.cpp. The order of arguments matters to gcc, as it resolves symbols from static libraries in order. See also Why does the order in which libraries are linked sometimes cause errors in GCC?.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like I am missing something very simple here, but this is the
I feel like I'm missing something very obvious here, but I can't get a
I feel like there's something rather basic I'm missing here, which I previously thought
I feel like I'm missing something here, but I have this datagrid which when
I feel like I'm missing something blindingly obvious here, so low hanging fruit for
I feel like I'm doing something dumb here. I'm making a simple TODO list
I feel like there is something obvious I'm missing here. I am trying to
I feel like I'm missing an obvious point here, but let's say I'm working
I feel like I'm missing something obvious here, but here it goes. I have
I feel like I'm doing something very dumb here. Maybe I'm just too tired.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.