I am currently studying LLVM. And I am following《LLVM Essentials》。In “Creating an LLVM Moudle” There is something as:
static llvm::LLVMContext context;
Module *module = new Module("Module",context);
module->dump();.
After compiling it I eventually get
Undefined symbols for architecture arm64:
"llvm::Module::dump() const", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture arm64` .
I'am using macOS 12.0.1, And I used homebrew to install llvm-17. Also I am using clion as my IDE with cmake configured as:
cmake_minimum_required(VERSION 3.16)
project(Demo)
set(CMAKE_CXX_STANDARD 17)
find_package(LLVM REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
#separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
#add_definitions(${LLVM_DEFINITIONS_LIST})
llvm_map_components_to_libnames(llvm_libs support core irreader)
add_executable(Demo main.cpp)
target_link_libraries(Demo ${llvm_libs})
and the code is:
#include <iostream>
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Verifier.h"
using namespace llvm;
static llvm::LLVMContext context;
int main() {
static IRBuilder<> Builder(context);
Module *module = new Module("Module",context);
module->dump(); //?? why this not working??
//This works well: module->print(llvm::errs(), nullptr);
return 0;
}
please help me If you know what is the problem. And besides I can't go to the implementation of LLVM function like module->dump(); I can only see the definition. why is that? I searched the Internet and it says maybe is the llvm is in release mode?
The definition of
Module::dumpis guarded by the following test:Brew very probably gave you a release build, and the Brew recipe does not seem to include
LLVM_ENABLE_DUMP.I suggest you patch your local brew recipe for LLVM to include that option (just add it to the list starting at line 100) after which you can have Brew rebuild LLVM by doing
brew install -s llvm@17.