c++ - Ld Undefined reference to * 当从程序集中调用 c++ 函数时
问题描述
我有这个汇编代码
主程序
[bits 32]
global _start
extern foo_main
section .mbHeader
align 0x4
MODULEALIGN equ 1<<0
MEMINFO equ 1<<1
FLAGS equ MODULEALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
_start:
push ebx
call foo_main
foo.cpp
void foo_main()
{
// stuff
}
生成文件
foo_source_files := $(shell find . -name *.cpp)
foo_object_files := $(patsubst %.cpp, build/%.o, $(foo_source_files))
asm_source_files := $(shell find . -name *.asm)
asm_object_files := $(patsubst ./%.asm, build/%.o, $(asm_source_files))
$(foo_object_files): ./build/%.o : ./%.cpp
mkdir -p $(dir $@) && \
g++ -m32 -c $(foo_source_files) -o $@ -ffreestanding -O2 -Wall -Wextra
$(asm_object_files): ./build/boot/%.o : ./boot/%.asm
mkdir -p $(dir $@) && \
nasm -f elf $(asm_source_files) -o $@
.PHONY: build
build: $(foo_object_files) $(asm_object_files)
mkdir -p ./dist && \
ld -m elf_i386 -T ./targets/linker.ld $(kernel_object_files) $(asm_object_files) -o MyOS.bin -nostdlib
.PHONY: clear
clear:
rm -rf ./build/*
但是当我运行“make build”时,我得到了这个错误
ld: build/boot.o: in function `_start':
./boot/main.asm:(.mbHeader+0xe): undefined reference to `foo_main'
make: *** [Makefile:19: build] Error 1
那么如何使它能够从 main.asm 文件中调用汇编函数call foo_main
而不会出现此错误
解决方案
推荐阅读
- delphi - 如何根据 Delphi 中的某些变量禁用和启用按钮单击事件?
- c++11 - 读取二进制文件(一次 16 位)的 C++11 方式是什么?
- c++ - 为什么 CSpinButtonCtrl 不能正确处理大于 1000 的数字?
- caching - 可扩展且可快速重启的缓存
- reactjs - 为 React 安装 Firebase 时出现 Grpc 错误
- javascript - ClassList 切换在 React 中不起作用。我究竟做错了什么?
- matlab - 展开以消除不连续性
- javascript - 在由 javascript 触发的电子邮件中发送一些 php 变量
- ffmpeg - 无法使用 ffmpeg 创建缩略图
- java - JPA与父亲和孩子的复合id的一对多关系