【问题标题】:Resolving conflicting type for functions with the same name in two external libraries解决两个外部库中同名函数的类型冲突
【发布时间】:2012-01-18 21:27:36
【问题描述】:

我已将以下库包含到我的代码中。

#include <minix/drivers.h>
#include <curl/curl.h>
#include <sys/stat.h>
#include <time.h>
#include <assert.h>
#include <string.h>

现在我收到以下错误:

In file included from /usr/local/include/curl/curlbuild.h:152
                 from /usr/local/include/curl/curl.h:34
                 from xxx.c:2
/usr/pkg/gcc44/lib/gcc/i686-pc-minix/4.4.3/include-fixed/sys/socket.h:134: error: conflicting types for '_send'
/usr/include/minix/ipc.h:152: note: previous declaration was here

据我所知,这意味着_send 已在两个库中声明(minix/drivers.hcurl/curl.h),我想知道是否有可能解决此问题或以某种方式解决它?

【问题讨论】:

  • 如果我可能会问,您的代码到底要做什么。以前不会遇到这种重叠似乎很奇怪。
  • 问题出现在编译时而不是链接时。您确定在您的程序中同时需要curl.hdrivers.h 吗?
  • @Jon 他们是必需的,因为我需要从网络加载文件并根据外部文件挂载文件系统。

标签: c minix


【解决方案1】:

由于您使用的是 minix,您可以使用 objcopy 修改其中一个(或两个)库。从手册页:

--redefine-sym old=new
       Change the name of a symbol old, to new.  This can be useful when 
       one is trying link two things together for which you have no source, 
       and there are name collisions.

或者,如果您不需要其中一个库中的_send

-L symbolname
--localize-symbol=symbolname
       Make symbol symbolname local to the file, so that it is not visible 
       externally.  This option may be given more than once.

当然,您需要相应地更新您的标题。我还建议将修改后的库和标头命名为其他名称,以便清楚地表明您已经修改了它们。

【讨论】:

猜你喜欢
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 2013-10-19
  • 1970-01-01
  • 1970-01-01
  • 2023-01-13
相关资源
最近更新 更多