专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > AIX

AIX中用xlc是否能链接C++的动态库,需要添加什么参数?解决方案

发布时间:2011-06-27 19:07:41 文章来源:www.iduyao.cn 采编人员:星星草
AIX中用xlc是否能链接C++的动态库,需要添加什么参数?
场景:在AIX5.3下,用C语言调用C++函数:
代码:
world.h文件:#include <iostream>

class test
{
  public:
  void world();
};

world.cpp文件:#include <iostream>
using namespace std;
#include "world.h"

void test::world()
{
  std::cout << "world" << std::endl;
}

封装 mid.cpp:
#include <iostream>
using namespace std;

#include "world.h"

#ifdef __cplusplus
extern "C" {  
#endif
  
void m_world()
  {
  test test1;
  test1.world();
  }

#ifdef __cplusplus
}
#endif

mid.h头文件:
#ifdef __cplusplus
extern "C" { #endif

void m_world();

#ifdef __cplusplus
}
#endif

makefile文件:

all: libmid.so test
world.o:world.cpp
  xlC -g -o $@ -c $?
mid.o:mid.cpp
  xlC -g -o $@ -c $?
libmid.so:world.o mid.o
  xlC -G -o $@ $?
test:test.c
  xlC -brtl $? -g -o $@ -L${PWD} -lmid

其中 xlC -brtl $? -g -o $@ -L${PWD} -lmid,编译通过且程序运行结果为 world
而改为xlc -brtl $? -g -o $@ -L${PWD} -lmid,编译通过且程序报Illegal instruction(coredump)

将程序移植到linux环境中发现:gcc $? -g -o $@ -L${PWD} -lmid与g++ $? -g -o $@ -L${PWD} -lmid,程序结果都是world

问题:
如果想用xlc来编辑是否需要添加什么参数?还是说xlc不能编译,那为啥gcc可以?



------解决方案--------------------
试验了一下,如果使用xlc,可以在最后添加-lC
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: