【求助】linux 交叉编译 找不到库文件 cannot find -lcurl

天经地义之经 2013-05-26 01:32:17
请教大侠们个问题,我用gcc和arm-linux-gcc编译hello world程序都没有问题,但是编译带有库libcurl的上网程序的时候,gcc没问题,但是用arm-linux-gcc就出错了,

我是在虚拟机中的linux系统中运行的
------------------------------------------------------这是交叉编译
[root@fyfyall curl-2]# make
arm-linux-gcc -DDEBUG -c -o getinmemory.o getinmemory.c
arm-linux-gcc getinmemory.o -o getin -L/usr/lib/libcurl.so -lcurl
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/lib/libcurl.so" is unsafe for cross-compilation
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/lib/libcurl.so when searching for -lcurl
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /usr/local/arm/4.3.2/arm-none-linux-gnueabi/bin/../lib/libcurl.so when searching for -lcurl
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lcurl
collect2: ld returned 1 exit status
------------------------------------------------------这是gcc 编译及运行
[root@fyfyall curl-2]# make
gcc -DDEBUG -c -o getinmemory.o getinmemory.c
gcc getinmemory.o -o getin -L/usr/lib/libcurl.so -lcurl

[root@fyfyall curl-2]# ./getin
10437 bytes retrieved

运行也没问题
就是交叉编译就不行了,交叉编译如果就一句hello world 也是没问题的
但是有库就不行了
不知道有库时候要注意什么
------------------------------------------------------
[root@fyfyall curl-2]# ls /usr/lib | grep libcurl*
libcurl.so
libcurl.so.4
libcurl.so.4.1.1
------------------------------------------------------这是源文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <curl/curl.h>

struct MemoryStruct {
char *memory;
size_t size;
};


static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;

mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}

memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;

return realsize;
}


int main(void)
{
CURL *curl_handle;
CURLcode res;

struct MemoryStruct chunk;

chunk.memory = (char *)malloc(1); /* will be grown as needed by the realloc above */
chunk.size = 0; /* no data at this point */

curl_global_init(CURL_GLOBAL_ALL);

/* init the curl session */
curl_handle = curl_easy_init();

/* specify URL to get */
curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.baidu.com/");

/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

/* we pass our 'chunk' struct to the callback function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

/* some servers don't like requests that are made without a user-agent
field, so we provide one */
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");

/* get it! */
res = curl_easy_perform(curl_handle);

/* check for errors */
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else {
/*
* Now, our chunk.memory points to a memory block that is chunk.size
* bytes big and contains the remote file.
*
* Do something nice with it!
*
* You should be aware of the fact that at this point we might have an
* allocated data block, and nothing has yet deallocated that data. So when
* you're done with it, you should free() it as a nice application.
*/

printf("%lu bytes retrieved\n", (long)chunk.size);

//printf("%s",chunk.memory);
//printf("百度推广您的产品\n");
}

/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);

if(chunk.memory)
free(chunk.memory);

/* we're done with libcurl, so clean it up */
curl_global_cleanup();

return 0;
}
------------------------------------------------------这是makefile文件
OBJ=getinmemory.o
#CC=arm-linux-gcc
CC=gcc
CFLAGS= -DDEBUG
all: getin
getin: $(OBJ)
$(CC) $^ -o $@ -L/usr/lib/libcurl.so -lcurl

clean:
$(RM) *.o getin
------------------------------------------------------
...全文
5716 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bjgzq 2014-07-07
  • 打赏
  • 举报
回复
楼主的问题解决了吗?怎么解决的?我也遇到相同的问题
蜗牛慢慢的爬 2014-01-06
  • 打赏
  • 举报
回复
./obj/gdevopvp.o: In function `opvp_load_vector_driver': gdevopvp.c:(.text+0x6788): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/arm-2010.09/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lfontconfig collect2: ld returned 1 exit status make: *** [bin/gs] Error 1 楼主能告诉我你怎么解决的吗,我现在和你遇到的问题是一样的,编译x86平台是正确的,一交叉编译就出问题,我这个是编译的ghostscript,实在是不知道怎么回事情了,求解!!!
lishen_ 2013-05-28
  • 打赏
  • 举报
回复
configure会生成日志的,把日志贴出来看看。
天经地义之经 2013-05-28
  • 打赏
  • 举报
回复
引用 4 楼 lishen2 的回复:
configure会生成日志的,把日志贴出来看看。
谢谢啦,后来又可以了,开始不知道是不是我搞错目录了
天经地义之经 2013-05-26
  • 打赏
  • 举报
回复
引用 2 楼 lishen2 的回复:
先用交叉编译环境编译一下libcurl,然后编译你的程序的时候修改一下makefile,注意给链接器的参数-L./path_to_cross_libcurl将-L参数的数值修改为刚才生成的libcurl.so或者libcurl.a的路径。
请问交叉编译libcurl要怎么编译的 我交叉编译libcurl ./configure --host=arm-linux 出现错误 configure: error: cannot find out size of long. 如果只是 ./configure 就没问题
lishen_ 2013-05-26
  • 打赏
  • 举报
回复
先用交叉编译环境编译一下libcurl,然后编译你的程序的时候修改一下makefile,注意给链接器的参数-L./path_to_cross_libcurl将-L参数的数值修改为刚才生成的libcurl.so或者libcurl.a的路径。
d294136138 2013-05-26
  • 打赏
  • 举报
回复
那个库应该用arm-linux-gcc编译出来的动态库吧,你这里用电脑的怎么行呢

742

社区成员

发帖
与我相关
我的任务
社区描述
该论坛主要探讨Linux系统在IBM Power平台的安装、部署、应用开发等话题,并为网友们提供自由交流的平台。
社区管理员
  • Power Linux社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧