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

Add libConfuse to eclipse [c][cross compilation]

您好,我尝试使用 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

我希望我能提供足够的信息并且有人可以帮助我。 P.S。我做交叉编译。

您混淆了编译器选项:

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

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

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

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

@LPs 回答:

If you are cross compiling you need the cross compiled library into your SDK.