При компиляции объектного файла, созданного через LLVM C++ API с использованием Clang в Ubuntu (wsl), я получаю следующую ошибку
compiled.o : fatal error LNK1107: invalid or corrupt file: cannot read at 0x898
clang: error: linker command failed with exit code 1107 (use -v to see invocation)
У меня есть следующий код на моем языке (который успешно запускается, если я распечатаю модуль в IR-файл и скомпилирую его с помощью clang в исполняемый файл)
func printf(format : string, args : any...) : int
func main(argc : int) : int {
printf("number of arguments : %d\n", argc);
c = 155;
printf("check c : %d\n", c);
return 0;
}
Я использовал этот код для создания объектного файла
void Codegen::save_to_object_file(const std::string &out_path) {
// Initialize the target registry etc.
InitializeAllTargetInfos();
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmParsers();
InitializeAllAsmPrinters();
auto TargetTriple = sys::getDefaultTargetTriple();
module->setTargetTriple(TargetTriple);
std::string Error;
auto Target = TargetRegistry::lookupTarget(TargetTriple, Error);
// Print an error and exit if we couldn't find the requested target.
// This generally occurs if we've forgotten to initialise the
// TargetRegistry or we have a bogus target triple.
if (!Target) {
error(Error);
return;
}
auto CPU = "generic";
auto Features = "";
TargetOptions opt;
auto TheTargetMachine = Target->createTargetMachine(
TargetTriple, CPU, Features, opt, Reloc::PIC_);
module->setDataLayout(TheTargetMachine->createDataLayout());
std::error_code EC;
raw_fd_ostream dest(out_path, EC, sys::fs::CD_CreateAlways);
if (EC) {
error("Could not open file: " + EC.message());
return;
}
legacy::PassManager pass;
auto FileType = CodeGenFileType::CGFT_ObjectFile;
if (TheTargetMachine->addPassesToEmitFile(pass, dest, nullptr, FileType)) {
error("TheTargetMachine can't emit a file of this type");
return;
}
pass.run(*module);
dest.flush();
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... bject-file
LLVM генерирует поврежденный объектный файл ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
По умолчанию компилятор генерирует ассемблерный или объектный код [дубликат]
Anonymous » » в форуме C++ - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-