c - 将 libConfuse 添加到 eclipse [c][交叉编译]

标签 c eclipse cross-compiling

您好,我尝试使用 libConfuse 访问配置文件。

这是我的代码

#include <stdio.h>
#include <confuse.h>

#include "core.h"
#include "readconfig.h"

int read_config_file(const char * filename, struct damterm_socket *dt_sock){

    cfg_t *cfg;

    cfg_opt_t socket_opts[] = {
            CFG_STR("destination_ip", IP_ADDR_DEFAULT, CFGF_NONE),
            CFG_INT("port", PORT_DEFAULT, CFGF_NONE),
            CFG_END()
        };
    cfg = cfg_init(socket_opts, CFGF_NONE);
    if(cfg_parse(cfg, filename) == CFG_PARSE_ERROR)
        printf("Błąd parsowania pliku!\n");
    else if(cfg_parse(cfg, filename) == CFG_FILE_ERROR)
        printf("Bład odczytu pliku\n"); //!TODO check existing of the file if not create new one.


    return -1; //!TODO Do nothing, return error.
}

来自 Eclipse 的错误:

readconfig.c:(.text+0x68): undefined reference to `cfg_init'
readconfig.c:(.text+0x78): undefined reference to `cfg_parse'
readconfig.c:(.text+0x8c): undefined reference to `cfg_parse'

我在/usr/local/lib 中添加了: 属性>设置>包括 (-I) 属性>设置>库(-L) 之后错误是:

/home/sylwek/iGT/OpenWrt-SDK-mr-mips-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/local/lib/libconfuse.so when searching for -lconfuse
makefile:29: polecenia dla obiektu 'mips' nie powiodły się
/home/sylwek/iGT/OpenWrt-SDK-mr-mips-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/local/lib/libconfuse.a when searching for -lconfuse

/home/sylwek/iGT/OpenWrt-SDK-mr-mips-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libconfuse.so when searching for -lconfuse
/home/sylwek/iGT/OpenWrt-SDK-mr-mips-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lconfuse
/home/sylwek/iGT/OpenWrt-SDK-mr-mips-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libgcc_s.so.1 when searching for libgcc_s.so.1

这是安装文件中的注释:

Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

我也试过将混淆添加到 (-l) 但有找不到它的错误:

ls -l /usr/local/lib/libconfuse.so
lrwxrwxrwx 1 root root 19 05-31 13:22 /usr/local/lib/libconfuse.so -> libconfuse.so.1.0.0

我希望我能提供足够的信息,有人可以帮助我。 附言我做交叉编译。

最佳答案

您混淆了编译器选项:

  • -L 添加库路径
  • -I 为包含添加路径
  • -l(libname) 添加要链接的特定编译库

undefined reference to 是链接错误。所以你没有添加库。

至少将 -L/usr/local/lib -lconfuse 添加到您的命令中

顺便说一句,您应该将/usr/local/lib 添加到库搜索路径,默认情况下将路径添加到 /etc/ld.so.conf 并启动 ldconfig 命令。

关于c - 将 libConfuse 添加到 eclipse [c][交叉编译],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37545135/

相关文章:

c - 简单的 minishell,由于 fgets 的工作方式,无法识别 "quit"以结束程序

c - 获取链表的节点号n

android - 如何将 Android 调试 keystore 放入颠覆存储库,然后让 Eclipse 使用它?

linux - mxe 交叉编译 linux 到 windows vtk 示例

arm - Libtool 声称在交叉编译期间不支持共享库

c++ - 交叉编译时如何处理依赖关系

c - 使用 pcap 示例编程

c - 如何在 chroot 中执行命令?

java - 写入txt文件,空指针异常

android - java.lang.RuntimeException 无法实例化