2

I'm currently having problem with simple project(or llvm-example for that matter). My assignment requires me to use llvm libraries, however this isn't as easy as I had hoped.

I've build LLVM using MinGW GCC and CMake. After build I can compile with clang fine. However if I create simple hello world type of program

#include "llvm-c/Core.h"

int main(int argc, char**argv)
{
  return 0;
}

and try to compile it with

clang++ main.cpp

I get

In file included from main.cpp:1:
./llvm-c/Core.h:18:10: fatal error: 'llvm-c/ErrorHandling.h' file not found
#include "llvm-c/ErrorHandling.h"

For this example I have copied contents of include directory into directory with main.cpp. After getting this issue I tried to inspect those headers and all of them have position llvm/ or llvm-c/, instead of pure relative address. I figured these libs were used to build/make llvm and libs for me to use are actually in build directory, which is where I have built llvm, but include directory in build has only about 1/2 *.h files.

I can't seem to find anything in documentation related to this and even basic llvm examples are expecting to include libs in format like llvm/Core.h

EDIT

After solving inclusion problem, now I get several other problems which seems to be linked to mingw.

This is how new program looks.

#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS

#include <llvm-c/Core.h>

using namespace std;

int main()
{
    LLVMModuleRef rff =  LLVMModuleCreateWithName("testname");
    return 0;
}

this generates

d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(CommandLine.cpp.obj):CommandLine.cpp|| undefined reference to `__mingw_strtod'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(regerror.c.obj):regerror.c|| undefined reference to `__ms_vsnprintf'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `SHGetKnownFolderPath@16'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `_imp__CoTaskMemFree@4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `_imp___chsize_s'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(TimeValue.cpp.obj):TimeValue.cpp|| undefined reference to `_localtime32'|

I used llvm-config --libs core for linker additions.

Tried commands:

g++ main.cpp -lLLVMCore -lLLVMSupport
clang++ main.cpp -lLLVMCore -lLLVMSupport
7
  • "For this example I have copied contents of include directory into directory with main.cpp" - Do you mean that "fixed" your issue? Commented Mar 21, 2016 at 9:03
  • 1
    In build system you should provide the include path with the llvm/include directory and library path with the directory in build where you have your library binaries... presumably build/lib Commented Mar 21, 2016 at 9:05
  • No it didnt. It wont compile at this point, because libs are included with their folders in path(which makes final path something like llvm-c/llvm-c/Core.h I figured that maybe removing folder from each instance of #include would help, but its too much files and I dont think this is right approach. Commented Mar 22, 2016 at 0:17
  • As for paths, llvm libs that have been build are in PATH so there shouldn't be this problem, and static link problem would pop different error. I did try to add include path to compilation -I"path/to/include", but this case builds first *.h and fails at the second one (one inside that header) Commented Mar 22, 2016 at 0:19
  • "and even basic llvm examples are expecting to include libs in format like llvm/Core.h" - so do you mean that the only problem remains is about that quoted sentence? Where do you get those examples? Commented Mar 22, 2016 at 5:24

2 Answers 2

3

Those are WinAPI references. The easiest way is to find those are google for documentation for it or go to the mingw library directory ( ..\mingw530_32\i686-w64-mingw32\lib\ ) and find in files.

So

  • FOLDERID_LocalAppData is defined in libuuid.a so use the -luuid compile parameter
  • _imp__CoTaskMemFree@4 is defined in libole32.a so use the -lole32 compile parameter

For me g++ -std=c++11 -ID:\Devel\install\include main.cc -LD:\Devel\install\lib -lLLVMCore -lLLVMSupport -luuid -lole32

is working as I installed the llvm to D:\Devel\install

Sign up to request clarification or add additional context in comments.

Comments

0

If you need the headers from your-llvm/include directory instead of copying the contents of the include directory you should just specify the include path to your-llvm/include with -I option or whatever the build system requires.

2 Comments

Already tried that, before posting this question. clang++ main.cpp -I"D:\llvm\include" here is command I used. And this is result: In file included from D:\llvm\include/llvm-c/ErrorHandling.h:17:0, from D:\llvm\include/llvm-c/Core.h:18, from main.cpp:1: D:\llvm\include/llvm-c/Types.h:17:36: fatal error: llvm/Support/DataTypes.h: No such file or directory #include "llvm/Support/DataTypes.h" ^ compilation terminated.
I have finally got this working, its mostly that, however what was needed to be done is to add not only include directory of llvm/include but also llvm/build/include. Build seems to have generated few libs on its own. Now its just pops "undefined referce to ..." errors which I will add to main question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.