Need help with compilers and their libraries

This is a discussion on Need help with compilers and their libraries within the C++ Programming forums, part of the General Programming Boards category; Hi! I have next to no experience programming in C++ but was recently sent some code which I need to ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    4

    Need help with compilers and their libraries

    Hi!
    I have next to no experience programming in C++ but was recently sent some code which I need to compile on my (Windows XP) machine. I installed the first free IDE I found - Bloodshed's Dev C++ - which I am told uses mingw as its default compiler. The program refuses to compile for two reasons. The first is that it generates the following error message at the first output line (e.g. std::cout << "... ) in the code:

    In instantiation of `std::basic_ios<wchar_t, std::char_traits<wchar_t> >': 59 C:\Dev-Cpp\include\c++\3.4.2\ostream instantiated from `std::basic_ostream<wchar_t, std::char_traits<wchar_t> >'
    17 C:\Documents and Settings\User\My Documents\C++ code (orignal + newlines)\main.cpp instantiated from here
    67 C:\Dev-Cpp\include\c++\3.4.2\bits\basic_ios.h no type named `pos_type' in `struct std::char_traits<wchar_t>'

    Commenting out that line just makes the next output line down generate the same error. Code which I write myself and which includes calls to cout seems to work normally though. I realize that there must be a difference between the two somewhere, but I hoped someone could tell me what I was looking for instead of me posting the 1000 or so lines of foreign code in the hopes that someone else can spot the problem.


    My second problem is that the code uses arc4random(), a "strong" pseudorandom number generator which is not included in my compiler's library. Substituting C++'s basic "rand()" unfortunately does not suit the purposes of the program.
    Does anyone know how I can get the code which runs arc4random() (or any similarly robust pseudorandom number generator) and get my compiler to recognize that code?
    I think the code's original writer used g++ as his compiler. I can find "man" pages for arc4random() online which seem to have something to do with FreeBSD and OpenBSD. Can I get g++ for windows, and does anyone know if it will include the code for arc4random() by default?

    I really appreciate any help I can get in this matter. I'm sorry if some of my questions are poorly worded or confusing - I'm not trying to be difficult, I'm just thoroughly confused.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,772
    It sounds like the code relies on some compiler-specific stuff.
    What is the line of error?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    4
    You're probably right about the problems being compiler-specific. Is getting the same compiler as the coder the best way to solve this, then?

    If by line of error you mean the line at which the error occurs, it looks like this:

    std::cout << "c = " << c << "\n";

    Which isn't very helpful. I only get the error once, but commenting out that line just makes the next line further down with cout generate the same error.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,772
    Getting the same compiler as the one who made the code will probably correct the error, but I can't say it's the best solution.
    Unfortunately, that line doesn't tell me much either. What's the type of "c"?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Well if you've just downloaded the "foo" package from some website (or as you say, have been sent), and expecting to compile it using the "bar" compiler, then expect a lot of trouble.

    The first thing to do is check on the foo website whether anyone has even attempted to compile it with the bar compiler, and what sort of success they had. Initial ports of software (from one OS/Compiler to another) are usually attempted by experienced people with a lot of detailed knowledge about the foo software.

    Second, using other resources at the foo site (like a message board or a mailing list) will generally gather a lot more useful and detailed responses.

    It's all the more difficult for us, since you haven't even told us what 'foo' is yet.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    4
    The program generates graphs (In the Graph theory sense of the word, i.e. nodes connected to each other by edges) and performs some basic operations like finding paths from one node to the other and evaluating the connectedness of the graph when some nodes are randomly removed.
    Unfortunately foo has no site. The code was sent by an acquantaince whom I am currently unable to contact, although obviously I'll have some questions to ask him when we get back in touch.
    The code is simple enough, with lots of basic math, use of STL containers, and exception handling, so it's not clear to me what parts of it would be compiler-specific.

    Elysia - c is a double. I doubt this matters, since *all* std::cout lines generate problems, regardless of whether they contain just text, variables, or whatever.

    Since this cross-platform compilation stuff seems to be out of my depth, I suppose I'll have to put it on hold until I can contact the coder. Thanks for your input on the matter though, guys.

    On the other hand, getting a function like arc4random() to work should be something I can handle, I hope. Does anyone know what I should do to get the code for this function and get it working on a windows machine? If not, is there a better place where I could ask this question?

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Could pos_type need to be namespace-qualified in the code to ios::pos_type?
    Last edited by rags_to_riches; 07-04-2008 at 12:50 PM.

  8. #8
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It is strange that your error messages should mention wchar_t, though. Perhaps some included header has defined something to change cout to use wchar or something?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  9. #9
    Registered User
    Join Date
    May 2008
    Posts
    4
    I found what I needed to fix the pos_type error, with some help from an earlier post.

    So far I've gathered that arc4random() comes standard in the OpenBSD implementations of g++ (if that makes any sense) and I can find relevant files
    online. However, I'm not sure where I should put them or what else they would need it order to run. I've never tried "adding" content to a compiler library before, and my current approach, copy-pasting the code into the library as a header file, failed. What am I supposed to do?

Popular pages Recent additions subscribe to a feed

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