473,472 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

why doesn't the compiler recognize the function although I included the right libs?

10 New Member
this is the code
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main () {
int b ;
randomize () ;
b = random (61) + 40 ;
printf ("This is b: %d\n", b ) ;
}
These are the errors:

error LNK2019:unresolved external symbol_random referenced in function_main

error LNK2019:unresolved external symbol_randomize referenced in function_main
Aug 6 '10 #1
6 4351
Banfa
9,065 Recognized Expert Moderator Expert
You haven't included the right libs at all because libs aren't included they are linked to.

random and randomize are not standard library functions but assuming that they extensions for the compiler you are using and declared in one of the standard headers you have included all you have done is tell the compiler that the functions exist somewhere, which is enough for the compiler to compile.

However when the linker runs it tries to actually find the functions in one of the supplied object or library files and when it fails it emits LNK2019.

That suggests you haven't included the correct object or library into your link.
Aug 6 '10 #2
David727
10 New Member
Thanks for the answer Banfa but
1.By your explanation I should pass the compiler phase--and I didn't. The fail wasn't in the Run phase but in the compiler phase.
2. As much as I know, random function belongs to stdlib library. If not...Do you know about another library it belongs to?
Aug 6 '10 #3
Banfa
9,065 Recognized Expert Moderator Expert
No you did pass the compiler phase, you error starts with LNK indicating it is in the link phase of creating the program.

If it was a compiler error it would have started C....

You compile every c/cpp file in your program and then link all the objects together with any libraries you need using the linker. That produces an executable that you can run.
Aug 6 '10 #4
David727
10 New Member
When I try to run it, I fail and get a message error that "The system cannot finf the file specified".

Allright then, I wrote now all the errors I got (not only the 2 I wrote before).

error LNK1120: 2 unresolved externals

error LNK2019:unresolved external symbol_random referenced in function_main

error LNK2019:unresolved external symbol_randomize referenced in function_main

intelliSense: identifier "random" is undefined.
IntelliSense: identifier "randomize" is undefined


May you tell me what should I do for using the function "random"? and in general, What should I do for including libraries and using all the functions inside them?
Aug 6 '10 #5
donbock
2,426 Recognized Expert Top Contributor
What led you to believe that functions random and randomize exist, and that their prototypes are as shown below?
Expand|Select|Wrap|Line Numbers
  1. void randomize(void);
  2. int random(int);
Where ever you found about about these functions should also have specified the header file to #include in your source file and the library to specify on your command line or in your IDE.
Aug 7 '10 #6
David727
10 New Member
Ok friends, I found it: The correct names are :rand(int) and srand().
Thank you.
Aug 7 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: pablo | last post by:
Dear Newsgroupers, The 'main' page contains a call to a function in an included file. This function puts a html-form on the screen. Before the form gets posted (to the 'main' page) some prior...
2
by: SAN CAZIANO | last post by:
can you help me please because I can't understand why the code doesn't seems to function very well: in onkeypress it must verify if insert number or string value in the fiels, but it doesn't...
3
by: Chris Perkins | last post by:
Random idea of the day: How about having syntax support for currying/partial function application, like this: func(..., a, b) func(a, ..., b) func(a, b, ...) That is: 1) Make an Ellipsis...
3
by: KathyB | last post by:
Hi, I've tried everything I can think of. Using the script below, I thought on submit my ConfirmSave function would run, then if true returned, would run my form action. At this point it appears...
13
by: Neil Zanella | last post by:
Hello, I wonder whether anyone has ever come across the following g++ compiler error message. I don't recall ever seeing it before. I solved my problem but I am still not sure about what this...
5
by: Active8 | last post by:
vector<double> signal; vector<double>::iterator iter; in_file.load_vector(signal); in_file.load_vector(signal.begin()); those calls give the compiler error: "could not deduce template...
22
by: Ian | last post by:
The title says it all. I can see the case where a function is to be called directly from C, the name mangling will stuff this up. But I can't see a reason why a template function can't be...
4
by: Martinfnp | last post by:
Hello all, I'm completely new in theory of C compiler and it's support for multi-core hardware. Does anybody know whether compiler for multi-core and SMP/AMP/BMP does need some special internal...
18
by: sam_cit | last post by:
Hi Everyone, int main() { printf("not included stdio.h"); } Yes, i haven't included stdio.h and my compiler would generate a warning and would assume that it would return a int, my question...
1
by: Mike | last post by:
Hi, I have a WCF service that works perfectly. I added a new function (returning typed Dataset) and now, my service doesn't work anymore. I got a lot of "CODEGEN" warning inside the proxy file...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.