AIX Server下面ld C语言出警告 居然不能用%操作

farrio 2007-04-25 10:00:38
简单的C程序
#include <stdlib.h>
#include <time.h>
typedef struct _RandInfo {
int iMin;
int iMax;
int iRand;
} RandInfo;
void JMYTSXZCRAND(RandInfo *rndInf)
{
int tmp, rnd, bas;
printf("%d\n",rndInf->iMin);
printf("%d\n",rndInf->iMax);
if (rndInf->iMax > rndInf->iMin)
{
printf("if\n");
tmp = (int)(((rndInf->iMax) + 1) - (rndInf->iMin));
printf("tmp=%d\n",tmp);
rnd= rand();
printf("rnd=%d\n",rnd);
bas = rnd % tmp; /* <--- */
rndInf->iRand = bas + (rndInf->iMin);
}
else
rndInf->iRand = rndInf->iMin;
}
使用下面的makefile编译链接,居然出Warning。
但是如果把取模操作注释掉就没事了。
难道是我的makefile里面没有找到c编译器关于取模操作的lib?
makefile:
libTESTC.a : test_c.o
/usr/bin/ld -o libTESTC.a -G -bexpall -bnoentry test_c.o
test_c.o : test_c.c
/usr/vac/bin/xlc -Aa -c -I/usr/include -I/opt/hitachicodecnv/include -I/include test_c.c -o test_c.o
编译错误:
/usr/vac/bin/xlc -Aa -c -I/usr/include -I/opt/hitachicodecnv/include -I/include test_c.c -o test_c.o
/usr/bin/ld -o libTESTC.a -G -bexpall -bnoentry test_c.o
ld: 0711-768 WARNING: Object test_c.o, section 1, function .__divss:
The branch at address 0xa8 is not followed by a recognized no-op
or TOC-reload instruction. The unrecognized instruction is 0x60850000.
/opt/HILNGcbl/bin/ccbl -d -C2 -P3 -T1 -T2 -T6 -Un -X5 -Mw test_cbl.cbl
/usr/vac/bin/xlc -o TESTCBL -bdynamic -brtl -blibpath: -L/usr/lib -lm -lc -lbsd -L/opt/HILNGcbl/lib -lcbl85 -lcb
l85ml -lcbl85cgi -L./ -lTESTC test_cbl.o
...全文
439 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
farrio 2007-05-09
  • 打赏
  • 举报
回复
目前不知道原因,但是可以使用ANSI C里面的div函数替代%和/运算符,问题就是出在动态链接那里。如果改成静态的就没事了。但是最根本的原因还是不知道,只能先用这种方法替代一下。
mymtom 2007-04-30
  • 打赏
  • 举报
回复
还没有解决吗?
mymtom 2007-04-29
  • 打赏
  • 举报
回复
不会吧,居然解决不了!
楼主自己顶一下吧!
linux_is_perfect 2007-04-29
  • 打赏
  • 举报
回复
路过
futar 2007-04-29
  • 打赏
  • 举报
回复
貌似 tmp 有肯能为 0;
mymtom 2007-04-27
  • 打赏
  • 举报
回复
没招了,
IBM的链接上的错误跟你的一样啊,居然还不行
The following example shows typical error messages that result when a function marked as local instead resolves to a shared library function.
int main(void)
{
printf("Just in function foo1()\n");
printf("Just in function foo1()\n");
}
ld: 0711-768 WARNING: Object t.o, section 1, function .printf:
The branch at address 0x18 is not followed by a recognized no-op
or TOC-reload instruction. The unrecognized instruction is 0x83E1004C.An executable file is produced, but it will not run. The error message indicates that a call to printf in object file t.o caused the problem. When you have confirmed that the called routine should be imported from a shared object, recompile the source file that caused the warning and explicitly mark printf as imported. For example:

xlc -c -qprocimported=printf t.c
farrio 2007-04-27
  • 打赏
  • 举报
回复
还是一样的啊
mymtom 2007-04-26
  • 打赏
  • 举报
回复
想起来了是不是
-qprocimported=__divss
要改成
-qprocimported=_divss

因为C函数编译函数名前会加下划线 "_"

farrio 2007-04-26
  • 打赏
  • 举报
回复
libTESTC.a : test_c.o
/usr/bin/ld -o libTESTC.a -G -bdynamic -bexpall -bnoentry -blibpath: test_c.o
# /usr/bin/ld -o libTESTC.a test_c.o
test_c.o : test_c.c
/usr/vac/bin/xlc -Aa -c -qprocimported=__divss test_c.c -o test_c.o
# /usr/vac/bin/xlc -Aa -c -I/usr/include -I/opt/hitachicodecnv/include -I/include test_c.c -o test_c.o
还是不行
farrio 2007-04-26
  • 打赏
  • 举报
回复
问题依旧。
huzs_82 2007-04-25
  • 打赏
  • 举报
回复
不清楚那里的问题,应该不是"%"的问题,检查前面是不是有别的错误.
mymtom 2007-04-25
  • 打赏
  • 举报
回复
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.xlcpp8a.doc/compiler/ref/ruoptprc.htm
mymtom 2007-04-25
  • 打赏
  • 举报
回复
编译时加上如下的选项
-qprocimported=__divss
farrio 2007-04-25
  • 打赏
  • 举报
回复
应该就是 % 的问题,因为如果我把 % 变成 * 就没问题了。
而且如果我用 / 也会出这个问题,只不过不是 __divss 函数,换成了另外一个函数。

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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