(.text+0x18): undefined reference to `main'
本帖最后由 只为你飘的雪 于 2012-11-16 00:09 编辑gcc -o main.c path_malloc_2_3.c open_max_2_4.c
/usr/lib/gcc/i686-redhat-linux/4.5.1/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld 返回 1
然后main.c就没有了。这是为什么啊?求高人赐教!
open_max.c:#include "main.h"
#ifdef OPEN_MAX
static long openmax = OPEN_MAX;
#else
static long openmax = 0;
#endif
/*
* if OPEN_MAX is indeterminate, we are not guaranteed that this is adequate*/
#define OPEN_MAX_GUESS 256
long open_max(void)
{
if (openmax == 0)
{
errno = 0;
if ((openmax = sysconf(_SC_OPEN_MAX)) < 0)
if (errno == 0)
openmax = OPEN_MAX_GUESS;
else
perror("sysconf error");
}
return (openmax);
}
path_alloc.c:#include "main.h"
#ifdef PATH_MAX
static int pathmax = PATH_MAX;
#else
static int pathmax = 0;
#endif
#define SUSV3 200112L
static long posix_version = 0;
/*if path_max indeterminate , no guarantee this is adequate */
#define PATH_MAX_GUESS 1024
char *path_alloc(int *sizep) /*also return allocated size, if nonnull */
{
char *ptr;
int size;
if (posix_version == 0)
posix_version = sysconf(_SC_VERSION);
if (pathmax == 0) //first time through
{
errno = 0;
if ((pathmax = pathconf("/", _PC_PATH_MAX)) < 0)
{
if (errno == 0)
pathmax = PATH_MAX_GUESS; //it is indterminats
else
perror("pathmax error for _pc_path_max");
}
else
pathmax++;
}
if (posix_version < SUSV3)
size = pathmax +1;
else size = pathmax;
if ((ptr = malloc(size)) == NULL)
perror("malloc error");
if (sizep != NULL)
*sizep = size;
return (ptr);
}
main.h:#ifndef _MAIN_H_
#define _MAIN_H_
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
char *path_alloc(int *);
long open_max(void);
#endif 没有main函数. 本来有main函数的,用gcc编译之后,就没有了。回复 2# linux_c_py_php
gcc -o main.c path_malloc_2_3.c open_max_2_4.c
你这命令...
-o是指定output name, 你把编译+链接path_malloc_2_3.c open_max_2_4.c 的结果输出到main.c文件了, 并且因为path_malloc_2_3.c open_max_2_4.c 里没有main函数,链接还失败报错了。。。 我擦,我想了好久,原来是命令有问题啊!谢谢了。我以为是一个.C文件必须配对一个.h 文件呢,⊙﹏⊙b汗回复 4# linux_c_py_php
页:
[1]