首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使libtool合并yasm创建的对象文件

无法使libtool合并yasm创建的对象文件
EN

Stack Overflow用户
提问于 2016-09-09 22:15:36
回答 2查看 180关注 0票数 2

我在试着让libtoolyasm合作。

yasm从我的.asm源代码创建了正确的.o files,但是我不知道如何让libtool构建相关的.lo.dep文件。它希望通过合并.o文件来构建共享库。

EN

回答 2

Stack Overflow用户

发布于 2016-09-14 10:41:43

libtool生成的文件通常使用以下布局:包含位置元数据的build目录中的.lo文件;build目录中的静态对象.o文件;以及build/.libs目录中的PIC / shared .o对象。

您可以使用libtool编译模式。我不熟悉yasm,所以你必须填写开关。它将运行两次yasm构建,一次使用-DPIC (可能还有其他共享对象选项)。

libtool --tag=CC --mode=compile yasm <options> src.asm

如果使用automake,这可能需要对.asm文件使用明确的规则:

代码语言:javascript
复制
.asm.lo:
        $(LIBTOOL) --tag=CC --mode=compile \
        yasm <options> $<

请记住,这些是Makefiles中的制表符,而不是(8)空格字符!您可能还需要在此之前添加:.SUFFIXES: .asm .lo。我使用变量$(LIBTOOL),因为有些平台(例如OSX)需要将其安装为glibtool,而Makefile.in就是这么做的。

例如,生成的src.losrc.o.libs/src.o应该由make clean遵守。

对于你的库libfoo,你需要用:EXTRA_libfoo_la_SOURCES = src.asm让automake知道这些源代码,用libfoo_la_LIBADD = src.lo让automake知道这些源代码。甚至有必要将其添加到依赖项:libfoo_la_DEPENDENCIES = src.lo

尽管我不明白为什么仅仅将src.asm放在libfoo_la_SOURCES中是不够的。

票数 0
EN

Stack Overflow用户

发布于 2016-09-16 04:34:45

这是可行的(尽管我从未想过如何让libtool在目标目录中创建.lo文件,或者创建目标目录的.libs目录)。

Makefile规则:

代码语言:javascript
复制
# Rule to build object files from asm files.
#
# XXX
# Libtool creates the .lo file in the directory where make is run. Move the file
# into place explicitly; I'm sure this is wrong, but have no idea how to fix it.
# Additionally, in a parallel make, the .libs file may not yet be created, check
# as necessary, but ignore errors.
.asm.lo:
        -d=`dirname $@`; test $d/.libs || mkdir $d/.libs
        $(LIBTOOL) --tag=CC --mode=compile sh $(srcdir)/dist/yasm.sh $< $@
        rm -f $@
        mv `basename $@` $@

执行yasm调用的支持shell脚本:

代码语言:javascript
复制
#! /bin/sh

# Libtool support for yasm files, expect the first argument to be a path to
# the source file and the second argument to be a path to libtool's .lo file.
# Use the second argument plus libtool's -o argument to set the real target
# file name.
source=$1
target=`dirname $2`
while test $# -gt 0
do
        case $1 in
        -o)
                target="$target/$2"
                shift; shift;;
        *)
                shift;;
        esac
done

yasm -f x64 -f elf64 -X gnu -g dwarf2 -D LINUX -o $target $source
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39413673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档