Quantum Random Bit Generator

This is a discussion on Quantum Random Bit Generator within the C++ Programming forums, part of the General Programming Boards category; grrr, more errors ok, i commented out the lines below because they were erroring out and i am running this ...

  1. #31
    Registered User
    Join Date
    May 2008
    Posts
    81
    grrr, more errors



    ok, i commented out the lines below because they were erroring out and i am running this on windows:

    Code:
    #ifdef PLATFORM_LINUX
    	// linux includes
    //#	include <sys/socket.h>
    //#	include <netinet/in.h>
    //#	include <arpa/inet.h> 
    //#	include <netdb.h>
    //#	include <unistd.h>
    still, im getting the errors below:

    Code:
    C:\QRBG\src>cl /EHsc example0.cpp QRBG.cpp
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    example0.cpp
    QRBG.cpp
    QRBG.cpp(198) : error C2065: 'AF_INET' : undeclared identifier
    QRBG.cpp(198) : error C2065: 'SOCK_STREAM' : undeclared identifier
    QRBG.cpp(198) : error C3861: 'socket': identifier not found
    QRBG.cpp(205) : error C2079: 'addr' uses undefined struct 'QRBG::Connect::socka
    dr_in'
    QRBG.cpp(206) : error C3861: 'gethostbyname': identifier not found
    QRBG.cpp(208) : error C2228: left of '.sin_addr' must have class/struct/union
            type is 'int'
    QRBG.cpp(208) : error C2228: left of '.s_addr' must have class/struct/union
    QRBG.cpp(208) : error C3861: 'inet_addr': identifier not found
    QRBG.cpp(210) : error C2228: left of '.sin_addr' must have class/struct/union
            type is 'int'
    QRBG.cpp(210) : error C2027: use of undefined type 'QRBG::Connect::hostent'
            QRBG.cpp(206) : see declaration of 'QRBG::Connect::hostent'
    QRBG.cpp(210) : error C2227: left of '->h_addr' must point to class/struct/unio
    /generic type
    QRBG.cpp(210) : error C2027: use of undefined type 'QRBG::Connect::hostent'
            QRBG.cpp(206) : see declaration of 'QRBG::Connect::hostent'
    QRBG.cpp(210) : error C2227: left of '->h_length' must point to class/struct/un
    on/generic type
    QRBG.cpp(211) : error C2228: left of '.sin_family' must have class/struct/union
            type is 'int'
    QRBG.cpp(211) : error C2065: 'AF_INET' : undeclared identifier
    QRBG.cpp(212) : error C2228: left of '.sin_port' must have class/struct/union
            type is 'int'
    QRBG.cpp(212) : error C3861: 'htons': identifier not found
    QRBG.cpp(214) : error C3861: 'connect': identifier not found
    QRBG.cpp(225) : error C3861: 'shutdown': identifier not found
    QRBG.cpp(231) : error C3861: 'close': identifier not found
    QRBG.cpp(252) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(252) : error C3861: 'gettimeofday': identifier not found
    QRBG.cpp(268) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(268) : error C3861: 'gettimeofday': identifier not found
    QRBG.cpp(352) : error C3861: 'htons': identifier not found
    QRBG.cpp(357) : error C3861: 'htonl': identifier not found
    QRBG.cpp(359) : error C3861: 'send': identifier not found
    QRBG.cpp(397) : error C3861: 'recv': identifier not found
    QRBG.cpp(416) : error C2065: 'u_long' : undeclared identifier
    QRBG.cpp(416) : error C2059: syntax error : ')'
    QRBG.cpp(416) : error C3861: 'ntohl': identifier not found
    QRBG.cpp(452) : error C3861: 'recv': identifier not found
    QRBG.cpp(499) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(499) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(532) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(532) : error C2228: left of '.tv_sec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(532) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(532) : error C2228: left of '.tv_sec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(532) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(532) : error C2228: left of '.tv_usec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(532) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(532) : error C2228: left of '.tv_usec' must have class/struct/union
            type is ''unknown-type''
    Generating Code...

  2. #32
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> i commented out the lines below because they were erroring out and i am running this on windows

    You shouldn't have to comment those lines out. They should be compiled if PLATFORM_LINUX is defined, but that should only be defined if you are on Linux. Search for #define PLATFORM_LINUX and comment that out instead of all the code that are inside the #ifdef PLATFORM_LINUX #endif lines.

    Your errors are because you are missing the socket library includes that declare those things. On windows there is Winsock, or you might be able to use bsd sockets as well, I don't recall. Perhaps if you fix the platform problem it will include the correct headers for Windows.

    Does the documentation for this library have instructions on how to compile it?

  3. #33
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    search for "mersenne twister". This is a very good RNG, tested and proven, and I'm sure you can find code on the internet.

  4. #34
    Registered User
    Join Date
    May 2008
    Posts
    81
    Quote Originally Posted by Daved View Post
    >> i commented out the lines below because they were erroring out and i am running this on windows

    You shouldn't have to comment those lines out. They should be compiled if PLATFORM_LINUX is defined, but that should only be defined if you are on Linux. Search for #define PLATFORM_LINUX and comment that out instead of all the code that are inside the #ifdef PLATFORM_LINUX #endif lines.

    Your errors are because you are missing the socket library includes that declare those things. On windows there is Winsock, or you might be able to use bsd sockets as well, I don't recall. Perhaps if you fix the platform problem it will include the correct headers for Windows.

    Does the documentation for this library have instructions on how to compile it?
    nope, no documentation.

    ok, i'll remove #define PLATFORM_LINUX and leave the rest. hope that works. otherwise, how do I include the socket library? just #include <winsock>?

  5. #35
    Registered User
    Join Date
    May 2008
    Posts
    81
    Quote Originally Posted by KIBO View Post
    search for "mersenne twister". This is a very good RNG, tested and proven, and I'm sure you can find code on the internet.
    interesting! i'll look into it, thanks!

    what would be really interesting would be to get both mersenne and qrbg to work and compare the results. for my simulation (which is quite simple really), the expected results are known...so I should get mostly similar results for both RNGs.

    EDIT: i found the mersenne code online. also the pseudo-code is on wikipedia so i can try to code it myself.

  6. #36
    Registered User
    Join Date
    May 2008
    Posts
    81
    Daved,

    i included winsock and compiled again. there was no #define PLATFORM_LINUX, only #ifdefined PLATFORM_LINUX. The errors from last time have reduced to the following:

    Code:
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    example0.cpp
    QRBG.cpp
    QRBG.cpp(253) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(253) : error C3861: 'gettimeofday': identifier not found
    QRBG.cpp(269) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(269) : error C3861: 'gettimeofday': identifier not found
    QRBG.cpp(500) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(500) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(533) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(533) : error C2228: left of '.tv_sec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(533) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(533) : error C2228: left of '.tv_sec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(533) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(533) : error C2228: left of '.tv_usec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(533) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(533) : error C2228: left of '.tv_usec' must have class/struct/union
            type is ''unknown-type''
    Generating Code...
    
    C:\QRBG\src>
    Last edited by shawnt; 05-24-2008 at 01:24 PM.

  7. #37
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    I don't recognize those names. Could you post the code the error refers to and the lines around it, plus the #includes at the top of the file?

  8. #38
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    You need
    Code:
    #include <sys/time.h>
    for gettimeofday().

  9. #39
    Registered User
    Join Date
    May 2008
    Posts
    81
    Quote Originally Posted by Daved View Post
    I don't recognize those names. Could you post the code the error refers to and the lines around it, plus the #includes at the top of the file?

    Code:
    #include "QRBG.h"
    #include <winsock.h>
    #include <time.h>
    
    #include <sys/types.h>
    #include <string.h>		// memcpy
    
    
    #ifdef PLATFORM_WIN
    	// windows includes
    #	define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
    
    #	include <winsock2.h>
    #	include <WS2tcpip.h>
    #	include <windows.h>
    #	include <errno.h>
    
    
    	// timer start
    251:#	if defined(PLATFORM_WIN)
    252:		timeStart = GetTickCount();
    253:#	elif defined(PLATFORM_LINUX)
    254:		gettimeofday(&timeStart, NULL);
    255:#	endif
    
    QRBG.cpp(254) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(254) : error C3861: 'gettimeofday': identifier not found
    
    
    	// timer end
    267:#	if defined(PLATFORM_WIN)
    268:		timeEnd = GetTickCount();
    269:#	elif defined(PLATFORM_LINUX)
    270:		gettimeofday(&timeEnd, NULL);
    271:#	endif
    
    QRBG.cpp(270) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(270) : error C3861: 'gettimeofday': identifier not found
    
    
    499:void QRBG::EnsureCachedEnough(size_t size) throw(ConnectError, CommunicationError,              ServiceDenied) {
    500:	// timer reset
    501:	timeEnd = timeStart;
    
    QRBG.cpp(501) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(501) : error C2065: 'timeStart' : undeclared identifier
    
    
    530:#elif defined(PLATFORM_LINUX)
    531:// linux version
    532:
    533:double QRBG::getLastDownloadDuration() {
    534:	return (timeEnd.tv_sec - timeStart.tv_sec) + 1e-6 * (timeEnd.tv_usec - timeStart.tv_usec);
    
    QRBG.cpp(534) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(534) : error C2228: left of '.tv_sec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(534) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(534) : error C2228: left of '.tv_sec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(534) : error C2065: 'timeEnd' : undeclared identifier
    QRBG.cpp(534) : error C2228: left of '.tv_usec' must have class/struct/union
            type is ''unknown-type''
    QRBG.cpp(534) : error C2065: 'timeStart' : undeclared identifier
    QRBG.cpp(534) : error C2228: left of '.tv_usec' must have class/struct/union
            type is ''unknown-type''
    Generating Code...
    
    C:\QRBG\src>
    I cant understand why it keeps going to the code which is meant for linux machines. im running this on win xp.
    Last edited by shawnt; 05-25-2008 at 02:51 AM.

  10. #40
    Registered User
    Join Date
    May 2008
    Posts
    81
    Quote Originally Posted by cyberfish View Post
    You need
    Code:
    #include <sys/time.h>
    for gettimeofday().
    please see previous post. i already have <time.h> included. it doesn't recognize <sys/time.h>.

  11. #41
    Registered User
    Join Date
    May 2008
    Posts
    81
    any ideas??

  12. #42
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> I cant understand why it keeps going to the code which is meant for linux machines.
    It will only go there if PLATFORM_LINUX is defined. You have to remove all code that defines it.

  13. #43
    Registered User
    Join Date
    May 2008
    Posts
    81
    k, back to the drawing board

  14. #44
    Registered User
    Join Date
    May 2008
    Posts
    81
    I removed the linux definitions. Now:

    Code:
    C:\QRBG\src>cl /EHsc example0.cpp
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    example0.cpp
    Microsoft (R) Incremental Linker Version 9.00.21022.08
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:example0.exe
    example0.obj
    example0.obj : error LNK2019: unresolved external symbol "public: __thiscall QRB
    G::~QRBG(void)" (??1QRBG@@QAE@XZ) referenced in function _main
    example0.obj : error LNK2019: unresolved external symbol "public: unsigned int _
    _thiscall QRBG::getBytes(unsigned char *,unsigned int)" (?getBytes@QRBG@@QAEIPAE
    I@Z) referenced in function _main
    example0.obj : error LNK2019: unresolved external symbol "public: double __thisc
    all QRBG::getDouble(void)" (?getDouble@QRBG@@QAENXZ) referenced in function _mai
    n
    example0.obj : error LNK2019: unresolved external symbol "public: float __thisca
    ll QRBG::getFloat(void)" (?getFloat@QRBG@@QAEMXZ) referenced in function _main
    example0.obj : error LNK2019: unresolved external symbol "public: long __thiscal
    l QRBG::getLongInt(void)" (?getLongInt@QRBG@@QAEJXZ) referenced in function _mai
    n
    example0.obj : error LNK2019: unresolved external symbol "public: int __thiscall
     QRBG::getInt(void)" (?getInt@QRBG@@QAEHXZ) referenced in function _main
    example0.obj : error LNK2019: unresolved external symbol "public: unsigned char
    __thiscall QRBG::getByte(void)" (?getByte@QRBG@@QAEEXZ) referenced in function _
    main
    example0.obj : error LNK2019: unresolved external symbol "public: void __thiscal
    l QRBG::defineUser(char const *,char const *)" (?defineUser@QRBG@@QAEXPBD0@Z) re
    ferenced in function _main
    example0.obj : error LNK2019: unresolved external symbol "public: void __thiscal
    l QRBG::defineServer(char const *,unsigned int)" (?defineServer@QRBG@@QAEXPBDI@Z
    ) referenced in function _main
    example0.obj : error LNK2019: unresolved external symbol "public: __thiscall QRB
    G::QRBG(unsigned int)" (??0QRBG@@QAE@I@Z) referenced in function _main
    example0.exe : fatal error LNK1120: 10 unresolved externals

  15. #45
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Don't forget to compile QRBG.cpp and/or any other source files, then link them together. Your command line only compiles example0.cpp. That compilation succeeds (congratulations on getting that far), but now you need to link all other source files.

    I don't remember if it was mentioned earlier, but if the library provides source files for you to compile, then add those to the command line (I don't know the exact syntax on the command line). If they provide pre-compiled libraries, then link to those libraries (I don't know the exact syntax on the command line).

Page 3 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with random number generator
    By Niss in forum C Programming
    Replies: 6
    Last Post: 10-01-2008, 06:03 PM
  2. Replies: 1
    Last Post: 09-04-2007, 05:31 AM
  3. Random card generator
    By Loic in forum C++ Programming
    Replies: 13
    Last Post: 08-11-2007, 02:28 PM
  4. Random number generator between 0 and 1
    By Lord CyKill in forum C# Programming
    Replies: 1
    Last Post: 03-29-2007, 08:03 AM
  5. Fast normal random number generator
    By testing123 in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2006, 10:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21