【发布时间】:2016-03-19 18:24:12
【问题描述】:
我目前遇到了简单项目(或 llvm-example 的问题)的问题。我的任务要求我使用 llvm 库,但这并不像我希望的那么容易。
我已经使用MinGW GCC 和CMake 构建了LLVM。构建后我可以用clang很好地编译。但是,如果我创建简单的 hello world 类型的程序
#include "llvm-c/Core.h"
int main(int argc, char**argv)
{
return 0;
}
并尝试编译它
clang++ main.cpp
我明白了
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"
对于这个例子,我将include 目录的内容复制到main.cpp 目录中。收到此问题后,我尝试检查这些标头,它们都具有位置llvm/ 或llvm-c/,而不是纯相对地址。我认为这些库用于构建/制作 llvm,而我要使用的库实际上位于 build 目录中,这是我构建 llvm 的位置,但构建中的 include 目录只有大约 1/2 个 *.h 文件.
我似乎在与此相关的文档中找不到任何内容,甚至基本的 llvm 示例都希望包含 llvm/Core.h 等格式的库
编辑
在解决了包含问题后,现在我遇到了其他几个似乎与 mingw 相关的问题。
这就是新程序的外观。
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include <llvm-c/Core.h>
using namespace std;
int main()
{
LLVMModuleRef rff = LLVMModuleCreateWithName("testname");
return 0;
}
这会生成
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'|
我使用llvm-config --libs core 来添加链接器。
尝试过的命令:
g++ main.cpp -lLLVMCore -lLLVMSupport
clang++ main.cpp -lLLVMCore -lLLVMSupport
【问题讨论】:
-
“对于这个例子,我已经将包含目录的内容复制到带有 main.cpp 的目录中” - 你的意思是“修复”了你的问题吗?
-
在构建系统中,您应该提供带有 llvm/include 目录的包含路径和带有库二进制文件的构建目录的库路径...大概是 build/lib
-
不,没有。此时它不会编译,因为库包含在路径中的文件夹中(这使得最终路径类似于
llvm-c/llvm-c/Core.h我想也许从#include的每个实例中删除文件夹会有所帮助,但它的文件太多,我不知道认为这是正确的方法。 -
至于路径,已经构建的llvm库在
PATH所以不应该有这个问题,静态链接问题会弹出不同的错误。我确实尝试将包含路径添加到编译-I"path/to/include",但这种情况下首先构建*.h,并在第二个(该标题内的一个)处失败 -
"甚至基本的 llvm 示例都期望包含 llvm/Core.h 等格式的库" - 所以你的意思是唯一的问题是关于引用的句子吗?你从哪里得到这些例子?