mingw undefined reference to `random'问题

uling 2013-07-11 01:24:49
makefile内容如下
CC = gcc
CFLAGS = -Wall -g -D_STDCALL_SUPPORTED -D_M_IX86
#LIBS = -lglew32 -lfreeglut -lopengl32 -lglu32
LIBS = -lmingw32 -lopengl32 -lglu32 glut32.lib -lopengl32 -lglu32
OBJ = Polaris.exe
SOURCEFILE = Polaris.c
$(OBJ): $(SOURCEFILE)
$(CC) -o $(OBJ) $(SOURCEFILE) $(CFLAGS) $(LIBS)



错误内容:如下
D:\opengl>make
gcc -o Polaris.exe Polaris.c -Wall -g -D_STDCALL_SUPPORTED -D_M_IX86 -lmingw32 -lopengl32 -lglu32 glut32.lib -lopengl32 -lglu32
Polaris.c: In function 'sierpinsky_render':
Polaris.c:51:24: warning: left-hand operand of comma expression has no effect [-Wunused-value]
Polaris.c:51:2: warning: missing braces around initializer [-Wmissing-braces]
Polaris.c:51:2: warning: (near initialization for 'T[0]') [-Wmissing-braces]
Polaris.c:51:34: warning: left-hand operand of comma expression has no effect [-Wunused-value]
Polaris.c:51:44: warning: left-hand operand of comma expression has no effect [-Wunused-value]
Polaris.c:52:2: warning: implicit declaration of function 'random' [-Wimplicit-function-declaration]
C:\DOCUME~1\123\LOCALS~1\Temp\ccwyj04m.o: In function `sierpinsky_render':
D:\opengl/Polaris.c:52: undefined reference to `random'
D:\opengl/Polaris.c:58: undefined reference to `random'
collect2: ld returned 1 exit status
make: *** [Polaris.exe] Error 1



不知道 random运行的链接的静态库在哪里

...全文
915 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
图灵狗 2013-07-12
  • 打赏
  • 举报
回复
libc是C语言标准库,一般编译器会自动链接,找不到的话,可能是配置问题。
引用 6 楼 withoutpe 的回复:
[quote=引用 2 楼 turingo 的回复:] 应该是libc.a库中。
有没有一些文档说明之类的 谢谢 [/quote]
赵4老师 2013-07-11
  • 打赏
  • 举报
回复
random <STDLIB.H> Macro that returns an integer Declaration: Macro: random(num); Function: int random(int num); Remarks: random returns a random number between 0 and (num-1). random(num) is a macro defined in STDLIB.H. Return Value: Returns an integer between 0 and (num - 1). Portability: DOS UNIX Windows ANSI C C++ Only Yes Yes See Also: rand randomize srand Example: #include <stdlib.h> #include <stdio.h> #include <time.h> /* prints a random number in the range 0 to 99 */ int main(void) { randomize(); printf("Random number in the 0-99 range: %d\n", random (100)); return 0; } Windows下没有。
uling 2013-07-11
  • 打赏
  • 举报
回复
引用 2 楼 turingo 的回复:
应该是libc.a库中。
有没有一些文档说明之类的 谢谢
uling 2013-07-11
  • 打赏
  • 举报
回复
引用 2 楼 turingo 的回复:
应该是libc.a库中。
这个libc.a在什么地方啊
uling 2013-07-11
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
INITSTATE Section: POSIX Programmer's Manual (P) Updated: 2003 -------------------------------------------------------------------------------- NAME initstate, random, setstate, srandom - pseudo-random number functions SYNOPSIS #include <stdlib.h> char *initstate(unsigned seed, char *state, size_t size); long random(void); char *setstate(const char *state); void srandom(unsigned seed); DESCRIPTION The random() function shall use a non-linear additive feedback random-number generator employing a default state array size of 31 long integers to return successive pseudo-random numbers in the range from 0 to 2**31-1. The period of this random-number generator is approximately 16 x (2**31-1). The size of the state array determines the period of the random-number generator. Increasing the state array size shall increase the period. With 256 bytes of state information, the period of the random-number generator shall be greater than 2**69. Like rand(), random() shall produce by default a sequence of numbers that can be duplicated by calling srandom() with 1 as the seed. The srandom() function shall initialize the current state array using the value of seed. The initstate() and setstate() functions handle restarting and changing random-number generators. The initstate() function allows a state array, pointed to by the state argument, to be initialized for future use. The size argument, which specifies the size in bytes of the state array, shall be used by initstate() to decide what type of random-number generator to use; the larger the state array, the more random the numbers. Values for the amount of state information are 8, 32, 64, 128, and 256 bytes. Other values greater than 8 bytes are rounded down to the nearest one of these values. If initstate() is called with 8<=size<32, then random() shall use a simple linear congruential random number generator. The seed argument specifies a starting point for the random-number sequence and provides for restarting at the same point. The initstate() function shall return a pointer to the previous state information array. If initstate() has not been called, then random() shall behave as though initstate() had been called with seed=1 and size=128. Once a state has been initialized, setstate() allows switching between state arrays. The array defined by the state argument shall be used for further random-number generation until initstate() is called or setstate() is called again. The setstate() function shall return a pointer to the previous state array. RETURN VALUE If initstate() is called with size less than 8, it shall return NULL. The random() function shall return the generated pseudo-random number. The srandom() function shall not return a value. Upon successful completion, initstate() and setstate() shall return a pointer to the previous state array; otherwise, a null pointer shall be returned. ERRORS No errors are defined. The following sections are informative. EXAMPLES None. APPLICATION USAGE After initialization, a state array can be restarted at a different point in one of two ways: 1. The initstate() function can be used, with the desired seed, state array, and size of the array. 2. The setstate() function, with the desired state, can be used, followed by srandom() with the desired seed. The advantage of using both of these functions is that the size of the state array does not have to be saved once it is initialized. Although some implementations of random() have written messages to standard error, such implementations do not conform to IEEE Std 1003.1-2001. Issue 5 restored the historical behavior of this function. Threaded applications should use erand48(), nrand48(), or jrand48() instead of random() when an independent random number sequence in multiple threads is required. RATIONALE None. FUTURE DIRECTIONS None. SEE ALSO drand48() , rand() , the Base Definitions volume of IEEE Std 1003.1-2001, <stdlib.h> COPYRIGHT Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . --------------------------------------------------------------------------------
没有找到 跟编译相关的信息。 想知道怎么能找到windows下对应的dll文件
赵4老师 2013-07-11
  • 打赏
  • 举报
回复
INITSTATE Section: POSIX Programmer's Manual (P) Updated: 2003 -------------------------------------------------------------------------------- NAME initstate, random, setstate, srandom - pseudo-random number functions SYNOPSIS #include <stdlib.h> char *initstate(unsigned seed, char *state, size_t size); long random(void); char *setstate(const char *state); void srandom(unsigned seed); DESCRIPTION The random() function shall use a non-linear additive feedback random-number generator employing a default state array size of 31 long integers to return successive pseudo-random numbers in the range from 0 to 2**31-1. The period of this random-number generator is approximately 16 x (2**31-1). The size of the state array determines the period of the random-number generator. Increasing the state array size shall increase the period. With 256 bytes of state information, the period of the random-number generator shall be greater than 2**69. Like rand(), random() shall produce by default a sequence of numbers that can be duplicated by calling srandom() with 1 as the seed. The srandom() function shall initialize the current state array using the value of seed. The initstate() and setstate() functions handle restarting and changing random-number generators. The initstate() function allows a state array, pointed to by the state argument, to be initialized for future use. The size argument, which specifies the size in bytes of the state array, shall be used by initstate() to decide what type of random-number generator to use; the larger the state array, the more random the numbers. Values for the amount of state information are 8, 32, 64, 128, and 256 bytes. Other values greater than 8 bytes are rounded down to the nearest one of these values. If initstate() is called with 8<=size<32, then random() shall use a simple linear congruential random number generator. The seed argument specifies a starting point for the random-number sequence and provides for restarting at the same point. The initstate() function shall return a pointer to the previous state information array. If initstate() has not been called, then random() shall behave as though initstate() had been called with seed=1 and size=128. Once a state has been initialized, setstate() allows switching between state arrays. The array defined by the state argument shall be used for further random-number generation until initstate() is called or setstate() is called again. The setstate() function shall return a pointer to the previous state array. RETURN VALUE If initstate() is called with size less than 8, it shall return NULL. The random() function shall return the generated pseudo-random number. The srandom() function shall not return a value. Upon successful completion, initstate() and setstate() shall return a pointer to the previous state array; otherwise, a null pointer shall be returned. ERRORS No errors are defined. The following sections are informative. EXAMPLES None. APPLICATION USAGE After initialization, a state array can be restarted at a different point in one of two ways: 1. The initstate() function can be used, with the desired seed, state array, and size of the array. 2. The setstate() function, with the desired state, can be used, followed by srandom() with the desired seed. The advantage of using both of these functions is that the size of the state array does not have to be saved once it is initialized. Although some implementations of random() have written messages to standard error, such implementations do not conform to IEEE Std 1003.1-2001. Issue 5 restored the historical behavior of this function. Threaded applications should use erand48(), nrand48(), or jrand48() instead of random() when an independent random number sequence in multiple threads is required. RATIONALE None. FUTURE DIRECTIONS None. SEE ALSO drand48() , rand() , the Base Definitions volume of IEEE Std 1003.1-2001, <stdlib.h> COPYRIGHT Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . --------------------------------------------------------------------------------
图灵狗 2013-07-11
  • 打赏
  • 举报
回复
应该是libc.a库中。
赵4老师 2013-07-11
  • 打赏
  • 举报
回复
RANDOM Section: Linux Programmer's Manual (3 ) Updated: 2000-08-20 -------------------------------------------------------------------------------- NAME random, srandom, initstate, setstate - random number generator SYNOPSIS #include <stdlib.h> long int random(void); void srandom(unsigned int seed); char *initstate(unsigned int seed, char *state, size_t n); char *setstate(char *state); DESCRIPTION The random() function uses a non-linear additive feedback random number generator employing a default table of size 31 long integers to return successive pseudo-random numbers in the range from 0 to RAND_MAX. The period of this random number generator is very large, approximately 16*((2**31)-1). The srandom() function sets its argument as the seed for a new sequence of pseudo-random integers to be returned by random(). These sequences are repeatable by calling srandom() with the same seed value. If no seed value is provided, the random() function is automatically seeded with a value of 1. The initstate() function allows a state array state to be initialized for use by random(). The size of the state array n is used by initstate() to decide how sophisticated a random number generator it should use - the larger the state array, the better the random numbers will be. seed is the seed for the initialization, which specifies a starting point for the random number sequence, and provides for restarting at the same point. The setstate() function changes the state array used by the random() function. The state array state is used for random number generation until the next call to initstate() or setstate(). state must first have been initialized using initstate() or be the result of a previous call of setstate(). RETURN VALUE The random() function returns a value between 0 and RAND_MAX. The srandom() function returns no value. The initstate() and setstate() functions return a pointer to the previous state array, or NULL on error. ERRORS EINVAL A state array of less than 8 bytes was specified to initstate(). NOTES Current "optimal" values for the size of the state array n are 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to the nearest known amount. Using less than 8 bytes will cause an error. CONFORMING TO BSD 4.3 SEE ALSO rand(3), srand(3) --------------------------------------------------------------------------------

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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