Skip to content

error: invalid use of incomplete type ‘struct LLVMOpaqueModule’ #640

Closed Answered by Ziqi-Yang
Ziqi-Yang asked this question in Q&A
Discussion options

You must be logged in to vote

I find the solution. Just create a wrapper class/struct. Don't expose the LLVMModuleRef class outside.
Here is an example:

#include <nanobind/nanobind.h>
#include <nanobind/stl/string.h>
#include <llvm-c/Core.h>

namespace nb = nanobind;
using namespace nb::literals;

class PyLLVMModule {
public:
  explicit PyLLVMModule(const std::string &name) {
    module = LLVMModuleCreateWithName(name.c_str());
    if (!module) {
      throw std::runtime_error("Failed to create LLVM module");
    }
  }

  ~PyLLVMModule() {
    if (module) 
      LLVMDisposeModule(module);
  }

  // Delete copy constructor and copy assignment
  PyLLVMModule(const PyLLVMModule &) = delete;
  PyLLVMModule &operator=(const

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Ziqi-Yang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant