Reputation: 11
I am now learning llvm
for coursework in school. I followed the llvm official tutorial and met a problem when finishing character 3 (link: https://releases.llvm.org/15.0.0/docs/tutorial/MyFirstLanguageFrontend/LangImpl03.html).
Below is my environment:
Windows 10 with AMD R5800H
clang version 16.0.0
LLVM version 16.0.0
CMake version 3.25.0
clang and LLVM were built by source code from GitHub using CMake and VS-2022
These are the files I include in my .cc program:
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <vector>
We can see that the first few lines include the llvm header files.
When I finished coding, I tried to compile in the PowerShell statement below (PS. I don't know what each part means, just following the tutorial):
clang++ -g -O3 my-lang.cc `llvm-config --cxxflags --ldflags --system-libs --libs core` -o mylang
But the Shell outputs the following information:
clang: error: unsupported option '--cxxflags'
clang: error: unsupported option '--ldflags'
clang: error: unsupported option '--system-libs'
clang: error: unsupported option '--libs'
clang: error: no such file or directory: 'llvm-config'
clang: error: no such file or directory: 'core -o'
clang: error: no such file or directory: 'mylang'
It is obvious that there is something wrong with my clang and/or llvm-config, but I failed to solve them.
clang: error: unsupported option '--cxxflags'
clang: error: unsupported option '--ldflags'
clang: error: unsupported option '--system-libs'
clang: error: unsupported option '--libs'
clang: error: no such file or directory: '`llvm-config'
clang: error: no such file or directory: 'core`'
I only do llvm-config --cxxflags --ldflags --system-libs --libs core
and get things below:
-IE:\CDemo\llvm\llvm-project\llvm\include -IE:\CDemo\llvm\llvm-project\build\include -std:c++17 /EHs-c- /GR- -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-LIBPATH:E:\CDemo\llvm\llvm-project\build\Release\lib
E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMCore.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMRemarks.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMBitstreamReader.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMBinaryFormat.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMSupport.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMDemangle.lib
psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib
And do clang++ my-lang.cc -o mylang
and get things below:
my-lang.cc:1:10: fatal error: 'llvm/ADT/APFloat.h' file not found
#include "llvm/ADT/APFloat.h"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
I think these are files that I need to link in my program, and these also proves that llvm-config
can works properly.
But why clang and llvm-config cannot work properly together?
How can I compile my program?
==========
edit date: 2022/12/2
Yeah. I tried $()
and it did work. But a new error has occorred.
When I do the statement clang++ -g -O3 my-lang.cc $(llvm-config --cxxflags --ldflags --system-libs --libs core) -o mylang
in the Power Shell, it said:
clang++: error: no such file or directory: 'E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMCore.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMRemarks.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMBitstreamReader.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMBinaryFormat.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMSupport.lib E:\CDemo\llvm\llvm-project\build\Release\lib\LLVMDemangle.lib'
clang++: error: no such file or directory: 'psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib'
The first point I am really confused about is that those files exist on my PC and are on the right path.
PS E:\CDemo\llvm\llvm-project\build\Release\lib> dir
Mode LastWriteTime Length Name
---- ------------- ------ ----
...
-a---- 2022/12/1 22:59 19281400 LLVMCore.lib
-a---- 2022/12/1 22:58 1184306 LLVMRemarks.lib
-a---- 2022/12/1 22:56 240648 LLVMBitstreamReader.lib
-a---- 2022/12/1 22:56 887888 LLVMBinaryFormat.lib
-a---- 2022/12/1 22:56 11201768 LLVMSupport.lib
-a---- 2022/12/1 22:56 862826 LLVMDemangle.lib
...
Second is what these mean psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib
and where can I find them?
Upvotes: 1
Views: 690