rand() linker error


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: rand() linker error

  1. #1
    Join Date
    May 2005
    Posts
    5

    rand() linker error

    I´ve made a new classes library project in c++ .net, in one of the .cpp
    I use the rand() function from C, and when I compile, I get the following exception:

    error LNK2001: símbolo externo "int __cdecl rand(void)" (?
    rand@@$$J0YAHXZ) sin resolver

    I include the correct .h and even tried:
    extern "C"
    {
    #include <stdlib.h>
    }
    but I continue get the same exception...

    Thanks ;)

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    try to use <cstdlib> instead. Don't use the enclosing extern "C" block, if it's necessary it should already be in the header itself. Alaos, make sure that your project has the right settings (Console App, unmanaged etc.) and that your files have the right extension, .cpp. Finally, try std::rand() instead of rand().
    Danny Kalev

  3. #3
    Join Date
    May 2005
    Posts
    5
    I´ve done these changes but I am getting the same exception :confused:

  4. #4
    Join Date
    Dec 2003
    Posts
    3,366
    check your project settings. make sure default libs are on, etc. It has to be something like that -- rand works in .net, I use it a lot.
    If nothing else make a new project and try it using default settings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center