【问题标题】:How do I link a static lib to a yocto autotools project in Eclipse如何在 Eclipse 中将静态库链接到 yocto autotools 项目
【发布时间】:2016-04-06 15:54:05
【问题描述】:

我在Eclipse 中创建了一个Yocto autotools 项目(基于Hello World 项目)。

我想将我的代码分成多个库,然后以静态库 (.a) 的形式将它们链接到我的项目。

现在我有一个应用程序和一些静态库。但是,无论我尝试什么,我都无法编译我的代码。每个单独的 lib 编译并生成一个 .a 文件,但我的应用程序没有。

在网上搜索后,我有一个可能的解决方案 - 添加一个指向我的静态库的直接链接:

MyApp_CPPFLAGS="-I$LOCATION"
MyApp_LDADD="/home/xxx/workspace/MyApp/Encoding2/Debug/libEncoding2.a"

这是我的Makefile.am 文件,其中libEncoding2.a 存在于该路径中。

我得到的错误是:

make[2]: *** No rule to make target `"/home/xxx/workspace/MyApp/Encoding2/Debug/libEncoding2.a"', needed by `MyApp'.  Stop.

我已经构建了 lib,所以我不确定为什么需要 make try。

任何帮助将不胜感激。

【问题讨论】:

    标签: eclipse static-libraries autotools yocto


    【解决方案1】:

    因为您在食谱中使用静态库,您可以使用以下命令链接到您的项目源文件夹中的库,即 hello-world-0.1,以链接到您的静态库

    ln -s /home/xxx/workspace/MyApp/Encoding2/Debug/libEncoding2.a
    

    然后编辑您的 bb 文件 hello-world_0.1.bb,将源路径添加到您的 URL

    SRC_URI = " \
      file://libEncoding2.a \
      file://hello-world.c \
    "
    

    并在 do_compile 块中,使用以下命令编译您的项目

    do_compile() {
      ${CC} hello-world.c libEncoding.a -o hello-world
    }
    
    do_install() {
       install -d ${D}${bindir}/Hello
       install -m 0755 enet ${D}${bindir}/Hello
    }
    

    在你对项目进行 bitbake 之后

    bitbake hello-world
    

    运行mkefidisk.sh,你可以在/usr/bin/Hello/hello-world中找到hello-world。希望这个提示可以帮助到你。

    顺便说一句,我不熟悉 autotools,我只是使用 make 来 bitbake 食谱。我认为你的静态库也应该在 Yocto 而不是在 Eclipse 中创建。所以我认为你的静态库路径可能不正确,它应该位于~/yocto/build/tmp/... 或类似的地方。就我而言,它位于 ln -s ~/yocto/build/tmp/sysroots/intel-corei7-64/usr/lib/libEncoding.a 取决于您的目标环境。

    【讨论】:

      【解决方案2】:

      根据您是否使用libtool,您应该分别拥有noinst_LTLIBRARIESnoinst_LIBRARIES 目标列表。这应该只包含您的库的名称(libEncoding2.lalibEncoding2.a。)

      你不应该为此使用完整路径,你应该引用Make变量,所以你要找的是

      MyApp_CPPFLAGS = -I$LOCATION
      MyApp_LDADD = libEncoding2.la  # or .a
      

      这样就行了。

      但另一方面,您似乎应该花一些时间来了解自动工具的工作原理,因为它可能不是您想要的。稍加注意,您可以以我的Autotools Mythbuster 为起点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-30
        • 1970-01-01
        • 2016-10-19
        • 1970-01-01
        • 2017-04-08
        • 2012-01-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多