I am trying to write my first ever compiler in C using LLVM for its backend, but I get an error when I try to run it. I have not found anything about this exact error message on other places.
Here is the error message:
./build/cave: error while loading shared libraries: libLLVMWindowsManifest.so.19: cannot open shared object file: No such file or directory
The latest LLVM is installed from source, I ran make, and make install too.
OS: WSL Debian 12
Makefile:
CC := clang
PROJECT := cave
CFLAGS := -Wall -Wextra -Werror -Wpedantic
# LLVM stuff
CFLAGS += `llvm-config --cflags`
LDFLAGS := `llvm-config --ldflags`
LIBS := `llvm-config --libs`
INCLUDES := -Iinclude
SRC_DIR := src
SRC := $(wildcard $(SRC_DIR)/*.c)
BUILD_DIR := build
OBJ := $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
.PHONY: all build clean
all: build
build: $(BUILD_DIR)/$(PROJECT)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDES) $(BUILD_ARGS)
$(BUILD_DIR)/$(PROJECT): $(OBJ)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(LIBS) $(BUILD_ARGS)
release:
$(MAKE) BUILD_ARGS="-O3" -B
clean:
rm -rf $(BUILD_DIR)
codegen.h:
#pragma once
#include <llvm-c/Types.h>
typedef struct LLVMBackend {
LLVMContextRef context;
LLVMModuleRef module;
LLVMBuilderRef builder;
LLVMValueRef *(*generateLLVMIR)(struct LLVMBackend *);
} LLVMBackend;
LLVMBackend backend_new(void);
void free_backend(LLVMBackend);
Here is the codegen.c file too:
#include "codegen.h"
#include <llvm-c/Core.h>
#include <stddef.h>
static LLVMValueRef *generateLLVMIR(LLVMBackend *self) {
(void)self; // not used yet
return NULL;
}
LLVMBackend backend_new(void) {
LLVMContextRef context = LLVMContextCreate();
LLVMModuleRef module =
LLVMModuleCreateWithNameInContext("example", context);
LLVMBuilderRef builder = LLVMCreateBuilderInContext(context);
return (LLVMBackend){
.context = context,
.module = module,
.builder = builder,
.generateLLVMIR = generateLLVMIR,
};
}
void free_backend(LLVMBackend backend) {
LLVMDisposeBuilder(backend.builder);
LLVMDisposeModule(backend.module);
LLVMContextDispose(backend.context);
}
I tried reinstalling the LLVM binaries with make clean and then make and make install again, but it didn’t work.
>Solution :
You need to specify path where your executable can find LLVM libs at runtime:
export LD_LIBRARY_PATH=$(llvm-config --libdir):$LD_LIBRARY_PATH
./build/cave