我创建了两个模块(共享对象)CPU 和 SaveState 作为模拟器的一部分。两者都被独立编译成 .so 单独的文件,并在运行时由 Lua 脚本使用 require() 加载;IE:
SaveState = require("SaveState")
CPU = require("CPU")
在 CPU 中,有一个对 SaveState 进行操作的方法:
int CPU::save_state(SaveState *state) {
state->begin_section(savestate_namespace, savestate_data_size);
state->write16(this->reg.af);
state->write16(this->reg.bc);
state->write16(this->reg.de);
state->write16(this->reg.hl);
state->write16(this->reg.sp);
state->write16(this->reg.pc);
state->write8 (this->interrupts_enabled);
state->write8 (this->irq_flags);
state->write8 (this->ie_flags);
state->write8 (this->halted);
state->write8 (this->halt_bug);
state->write8 (this->extra_cycles);
state->write64(this->total_cycles);
state->write64(this->idle_cycles);
return SaveState::OK;
}
它编译得很好,但require("CPU")
行失败:
lua5.1: error loading module 'cpu' from file './src/cpu/build/cpu.so':
./src/cpu/build/cpu.so: undefined symbol: _ZN9SaveState7write64Ey
使用nm -D
我可以在 savestate.so 中看到确切的符号,但在运行时由于某种原因看不到它。