使用 libcurl 构建项目在 linux 下不起作用
building project with libcurl doesn't work under linux
我正在尝试在 Eclipse Juno 的 Linux 下用 C 语言构建一个小项目。当我包含 libcurl 库时,我认为链接器总是抛出找不到 -lcurl 的错误。我知道互联网上有几篇文章,但没有任何帮助。整体看起来是这样的:
Building target: c_template
Invoking: GCC C Linker
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/bin/armv7a-vfp-neon-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc -L/usr/lib --sysroot=/usr/local/oecore-i686-arm/sysroots/armv7a-vfp-neon-oe-linux-gnueabi -o "c_template" ./src/atCommand.o ./src/charDevice.o ./src/curl.o ./src/debug.o ./src/linux_prototype.o ./src/output.o ./src/simStatus.o ./src/urc.o ./src/wwan.o -lpthread -lcurl
from <command-line>:0:
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/defs.h:87:10: warning: type defaults to 'int' in declaration of 'BOOL' [-Wimplicit-int]
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/atCommand.h:56:12: warning: 'atCommandsHandler' defined but not used [-Wunused-variable]
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/debug.h:60:12: warning: 'deviceHandler' defined but not used [-Wunused-variable]
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libpthread.so while searching for pthread
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libcurl.so while searching for curl
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: error: cannot find -lcurl
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libc.so while searching for c
../src/curl.c:66: error: undefined reference to 'curl_global_init'
../src/curl.c:69: error: undefined reference to 'curl_easy_init'
../src/curl.c:72: error: undefined reference to 'curl_slist_append'
../src/curl.c:73: error: undefined reference to 'curl_slist_append'
../src/curl.c:76: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:79: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:82: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:85: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:98: error: undefined reference to 'curl_easy_perform'
../src/curl.c:101: error: undefined reference to 'curl_easy_strerror'
../src/curl.c:105: error: undefined reference to 'curl_slist_free_all'
../src/curl.c:108: error: undefined reference to 'curl_easy_cleanup'
../src/curl.c:112: error: undefined reference to 'curl_global_cleanup'
collect2: ld returned 1 exit status
make: *** [c_template] Error 1
我已经为链接器设置了库路径:
对于库搜索路径 (-L):/usr/lib
对于库 (-l):curl
我的命令行模式如下所示:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX} ${OUTPUT} ${INPUTS}
谁能帮帮我。会很棒。
非常感谢
您正在为 ARM 交叉编译 c_template
,因此您需要在交叉编译环境中为 ARM 安装 libcurl
。现在它为您的 i686 主机找到了 libcurl
,但它不能使用它,如下所示:
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libcurl.so while searching for curl
因此,首先 compile/install libcurl
在您的编译环境中针对您的目标平台,并确保您的编译器可以找到它。
我正在尝试在 Eclipse Juno 的 Linux 下用 C 语言构建一个小项目。当我包含 libcurl 库时,我认为链接器总是抛出找不到 -lcurl 的错误。我知道互联网上有几篇文章,但没有任何帮助。整体看起来是这样的:
Building target: c_template
Invoking: GCC C Linker
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/bin/armv7a-vfp-neon-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc -L/usr/lib --sysroot=/usr/local/oecore-i686-arm/sysroots/armv7a-vfp-neon-oe-linux-gnueabi -o "c_template" ./src/atCommand.o ./src/charDevice.o ./src/curl.o ./src/debug.o ./src/linux_prototype.o ./src/output.o ./src/simStatus.o ./src/urc.o ./src/wwan.o -lpthread -lcurl
from <command-line>:0:
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/defs.h:87:10: warning: type defaults to 'int' in declaration of 'BOOL' [-Wimplicit-int]
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/atCommand.h:56:12: warning: 'atCommandsHandler' defined but not used [-Wunused-variable]
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/debug.h:60:12: warning: 'deviceHandler' defined but not used [-Wunused-variable]
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libpthread.so while searching for pthread
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libcurl.so while searching for curl
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: error: cannot find -lcurl
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libc.so while searching for c
../src/curl.c:66: error: undefined reference to 'curl_global_init'
../src/curl.c:69: error: undefined reference to 'curl_easy_init'
../src/curl.c:72: error: undefined reference to 'curl_slist_append'
../src/curl.c:73: error: undefined reference to 'curl_slist_append'
../src/curl.c:76: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:79: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:82: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:85: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:98: error: undefined reference to 'curl_easy_perform'
../src/curl.c:101: error: undefined reference to 'curl_easy_strerror'
../src/curl.c:105: error: undefined reference to 'curl_slist_free_all'
../src/curl.c:108: error: undefined reference to 'curl_easy_cleanup'
../src/curl.c:112: error: undefined reference to 'curl_global_cleanup'
collect2: ld returned 1 exit status
make: *** [c_template] Error 1
我已经为链接器设置了库路径: 对于库搜索路径 (-L):/usr/lib 对于库 (-l):curl
我的命令行模式如下所示:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX} ${OUTPUT} ${INPUTS}
谁能帮帮我。会很棒。
非常感谢
您正在为 ARM 交叉编译 c_template
,因此您需要在交叉编译环境中为 ARM 安装 libcurl
。现在它为您的 i686 主机找到了 libcurl
,但它不能使用它,如下所示:
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libcurl.so while searching for curl
因此,首先 compile/install libcurl
在您的编译环境中针对您的目标平台,并确保您的编译器可以找到它。