I am trying to create a C/C++ parser using libclang in Windows. I am using MinGW 6.3.0.
This is the line of code that I am using to compile the file.
g++ -I../clang/include/ main.cpp -L../clang/lib -llibclang -o cdeep
Folder Structure:
-clang
-include
-clang-c
-Index.h
-etc
-llvm-c
-lib
-libclang.lib
-etc
-src
-main.cpp
The code in main.cpp:
#include <iostream>
#include <clang-c/Index.h>
using namespace std;
int main()
{
CXIndex index = clang_createIndex(0, 0);
CXTranslationUnit unit = clang_parseTranslationUnit(
index,
"main.cpp", nullptr, 0,
nullptr, 0,
CXTranslationUnit_None);
if (unit == nullptr)
{
cerr << "Unable to parse translation unit. Quitting." << endl;
exit(-1);
}
clang_disposeTranslationUnit(unit);
clang_disposeIndex(index);
}
The error:
g++ -I../clang/include/ main.cpp -L../clang/lib -llibclang -o cdeep
C:\Users\ineeve\AppData\Local\Temp\ccLfSBTa.o:main.cpp:(.text+0x26): undefined reference to `clang_createIndex'
C:\Users\ineeve\AppData\Local\Temp\ccLfSBTa.o:main.cpp:(.text+0x64): undefined reference to `clang_parseTranslationUnit'
C:\Users\ineeve\AppData\Local\Temp\ccLfSBTa.o:main.cpp:(.text+0xa9): undefined reference to `clang_disposeTranslationUnit'
C:\Users\ineeve\AppData\Local\Temp\ccLfSBTa.o:main.cpp:(.text+0xb4): undefined reference to `clang_disposeIndex'
collect2.exe: error: ld returned 1 exit status
I get the same error if I don't use the -llibclang parameter.
This question is not a duplicate as my friend can compile exactly the same code with exactly the same g++ command.