【发布时间】:2019-12-19 09:34:55
【问题描述】:
我希望 CMake 在生成我的 kernel 可执行文件时发出以下命令或等效命令
mipsel-linux-gnu-ld -o kernel hello.o termprint.o crtso.o libumps.o -G 0 -nostdlib -T ./umps/umpscore.ldscript
请注意,上述命令完全跳过了对kernel 的gcc 调用——它只运行链接器。为了使用 CMake 复制该命令,我正在尝试定义以下规则
file(WRITE null.c "")
add_executable(kernel null.c)
target_link_options(kernel PRIVATE ${LDFLAGS})
target_link_libraries(kernel phase0 crtso libumps termprint)
但问题是生成的Makefile 发出一个编译步骤来生成kernel,而我只想做链接
$ make VERBOSE=1 kernel
# Lots of output
...
mipsel-linux-gnu-gcc -rdynamic -G 0 -nostdlib -T /home/acsor/Software/BiKaya/src/umps/umpscore.ldscript CMakeFiles/kernel.dir/null.c.o CMakeFiles/phase0.dir/src/phase0.c.o CMakeFiles/crtso.dir/src/umps/crtso.S.o CMakeFiles/libumps.dir/src/umps/libumps.S.o CMakeFiles/termprint.dir/src/termprint.c.o -o kernel
...
# Link errors follow
如何以 CMake 风格的方式做我想做的事?你可以找到我的 CMake 设置here。
【问题讨论】:
-
编译步骤在哪里? GCC 也可以用于链接。
-
hello.o termprint.o crtso.o libumps.o是否也由 CMake 文件编译?请同时显示 CMake。 -
Here it is。我正在考虑调整
CMAKE_C_LINK_EXECUTABLE变量,有什么缺点吗? -
这些
.c.o扩展名都正确吗?... -
@Acsor 也许最干净的方法是创建一个工具链文件?看看here。