免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 11401 | 回复: 13
打印 上一主题 下一主题

为什么程序编译不通过呢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-03 11:31 |只看该作者 |倒序浏览
为什么含有象strnicmp,strncpy这样的函数都编译不通过呢,是不是gcc应该加哪个编译选项?

论坛徽章:
0
2 [报告]
发表于 2006-03-03 14:48 |只看该作者
先检查函数有没有,看看头文件是否包括,还有提问的时候最好将错误贴出
你调用的strnicmp是自己写的吗?系统应该没有这个函数

论坛徽章:
0
3 [报告]
发表于 2006-03-03 14:54 |只看该作者
系统提示如下:
/tmp/ccUHuv2u.o(.text+0x2a): In function `main':
strcpytest.c: undefined reference to `strnicmp'
collect2: ld returned 1 exit status
头文件已经包括了,在string.h的文件里面。这个函数不是自己写的,是库里有的

论坛徽章:
0
4 [报告]
发表于 2006-03-03 15:08 |只看该作者
原帖由 miaoxins 于 2006-3-3 14:54 发表
系统提示如下:
/tmp/ccUHuv2u.o(.text+0x2a): In function `main':
strcpytest.c: undefined reference to `strnicmp'
collect2: ld returned 1 exit status
头文件已经包括了,在string.h的文件里面。这个函 ...


你都包括string.h了,编译都提示说没有定义"undefined reference to `strnicmp'"
你说在string.h里面有没有这个函数?
你可以man strnicmp看看,找函数的时候最好man一下
如果是比较n个字符串的话是strncmp

论坛徽章:
0
5 [报告]
发表于 2006-03-03 15:26 |只看该作者
但是我的程序里面的数学类函数也出现了这样的情况,出错提示是这样:
test.c:412:2: warning: no newline at end of file
/tmp/ccOM1iHK.o(.text+0x254): In function `main':
test.c: undefined reference to `acos'
/tmp/ccOM1iHK.o(.text+0x27d):test.c: undefined reference to `asin'
/tmp/ccOM1iHK.o(.text+0x2a6):test.c: undefined reference to `atan'
/tmp/ccOM1iHK.o(.text+0x2d6):test.c: undefined reference to `atan2'
/tmp/ccOM1iHK.o(.text+0x2fc):test.c: undefined reference to `cos'
/tmp/ccOM1iHK.o(.text+0x322):test.c: undefined reference to `sin'
/tmp/ccOM1iHK.o(.text+0x352):test.c: undefined reference to `pow'
/tmp/ccOM1iHK.o(.text+0x37b):test.c: undefined reference to `sqrt'
/tmp/ccOM1iHK.o(.text+0x3a4):test.c: undefined reference to `ceil'
/tmp/ccOM1iHK.o(.text+0x3da):test.c: undefined reference to `floor'
/tmp/ccOM1iHK.o(.text+0x8b5): In function `test_stricmp':
test.c: undefined reference to `stricmp'
collect2: ld returned 1 exit status
我也把math.h文件包括进来了,可还是有这样的提示。用man看了这些数学函数都没有问题,在系统中都能看到。可就是编译时出现这样的提示。可在gcc编译的时候加了
-lm选项后,就可以编译通过。

论坛徽章:
0
6 [报告]
发表于 2006-03-03 15:57 |只看该作者
原帖由 miaoxins 于 2006-3-3 15:26 发表
但是我的程序里面的数学类函数也出现了这样的情况,出错提示是这样:
test.c:412:2: warning: no newline at end of file
/tmp/ccOM1iHK.o(.text+0x254): In function `main':
test.c: undefined reference to ...


调用math.h里的函数是要加-lm的,一般来说你调用函数都是要加-l的,
像一些常用的如在stdio.h,string.h里的基本函数可以不用加-l后面的库的,编译的时候默认会链接
如果你要加也可以

你可以到string.h(/usr/include)里自己找找你要的函数有没有
你用man查过那个函数了吗?

论坛徽章:
0
7 [报告]
发表于 2006-03-03 16:03 |只看该作者
到string.h里面去看是没有什么作用的,那些函数都是在库里面的。不过我用man看那个函数strnicmp到是没找到,可能是这个系统不支持吧(RH 9.0)。可我把它注释了,怎么有这个提示呢:
Segmentation fault

论坛徽章:
0
8 [报告]
发表于 2006-03-03 16:13 |只看该作者
原帖由 miaoxins 于 2006-3-3 16:03 发表
到string.h里面去看是没有什么作用的,那些函数都是在库里面的。不过我用man看那个函数strnicmp到是没找到,可能是这个系统不支持吧(RH 9.0)。可我把它注释了,怎么有这个提示呢:
Segmentation fault


你倒蛮会解释的,一般系统提供的肯定会在头文件中先给出,然后再提供lib库
至少我到现在还没有看到有提供strnicmp的系统函数(除非以后增加进去)
比较字符串的话用strcmp strncmp,
报Segmentation fault 一般都是非法操作内存造成的,这是你程序自己的问题了,不要怪你的系统不支持了

论坛徽章:
0
9 [报告]
发表于 2006-03-03 16:31 |只看该作者
可我换一个系统,strnicmp这个函数就能运行。这个系统的string.h文件内容是这样:
#ifndef _STRING_H_
#ifndef _STD_HEADER
#   include     <astwin32.h>
#endif                                                                          
#include        _STD_HEADER(string.h)
#ifndef _STRING_H_
#   define _STRING_H_        1
#endif
#ifdef __cplusplus
extern "C" {
#endif
    extern char *strdup(const char*);
    extern void *memccpy(void*,const void*,int,size_t);
#ifdef __cplusplus
}
#endif
#ifdef _BSDCOMPAT
#   include        <strings.h>
#endif /* _BSDCOMPAT */
#endif



astwin32.h文件内容是这样:
#define _DLL_INDIRECT_DATA        1
#define _UWIN        1
#ifndef _STD_INCLUDE_DIR
#   ifdef __GNUC__
#        define _STD_INCLUDE_DIR mingw32
#   else
#        define _STD_INCLUDE_DIR /msvc20/include
#   endif
#endif
#define        _STD_HEADER(name)        <_STD_INCLUDE_DIR/name>
#define WinMain _ast_WinMain
#ifdef __GNUC__
#   define __int64 long long int
#   define _int64 long long int
#endif
#ifdef _MSC_VER
#   pragma warning(disable: 406
#   pragma warning(disable: 4141)
#endif
#ifdef __BORLANDC__
#   pragma warn -pia
#endif
#ifdef _BSDCOMPAT
#   define index        strchr
#   define rindex        strrchr
#   define setpgrp        setpgid
#   define __P(x)        x
#endif /* _BSDCOMPAT */

#ifdef _DLL
#    define _DLL_BLD        1
#endif
#if 0
        /* GCC supports pre-processing assembly input, so take care. */
#endif
#if !defined(__GNUC__) || (defined(__GNUC__) && !defined(__ASSEMBLER__))
#   if defined(__GNUC__)
#        define __IMPORT__        __declspec(dllimport) extern
#   else
#        define __IMPORT__        __declspec(dllimport)
#   endif
#   ifdef _DLL_BLD
#        if !defined(__GNUC__) || (defined(__GNUC__) && defined(__declspec))
#            define __EXPORT__        __declspec(dllexport)
#        endif
        struct _astdll
        {
                int        *_ast_errno;
                char        ***_ast_environ;
                void        *_ast_stdin;
                void        *_ast_stdout;
                void        *_ast_stderr;
                char        **_ast_tzname;
                int        _ast_libversion;
                int        *_ast_daylight;
                long        *_ast_timezone;
                int        *_ast_exitfn;
                int        *_ast__exitfn;
                char        **_ast__argv;
                int        *_ast_herrno;
                int        _ast_flags;
                void        *_ast__iob;
        };

#        define _ast_dll        _ast_getdll()
#   ifdef __cplusplus
        extern "C" struct _astdll *_ast_getdll(void);
#   else
        extern struct _astdll *_ast_getdll(void);
#   endif /* __cplusplus */
#   endif /* _DLL_BLD */
#endif
我也没看到有strnicmp这个函数的说明

[ 本帖最后由 miaoxins 于 2006-3-3 16:33 编辑 ]

论坛徽章:
0
10 [报告]
发表于 2006-03-03 16:51 |只看该作者
我想问一下,你是不是换到windos系统上编译了?
在linux下是没有提供这样的函数的,像windos有没有我不知道
strnicmp是不分大小写比较字符串
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP