Thread: sourceforge project not compiling

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    63

    sourceforge project not compiling

    The source from this project is not that old
    QBasic to C++ translator | SourceForge.net
    but it will not compile with the compilers I use.
    Visual Studio 2013 Community (using a batch file not ide) and TDM-GCC. The errors are a bit over my head at this stage in my learning process.
    Any suggestions?


    James

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There is already a pre-compiled version. Why not use that?
    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
    Mar 2013
    Posts
    63
    Quote Originally Posted by Elysia View Post
    There is already a pre-compiled version. Why not use that?
    I want to understand the coding not use the app.

    James

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I would suggest that you start by investigating the errors, but if you are convinced that "the errors are a bit over (over) head at this stage in (your) learning process", then perhaps you should find another similiar project that works, or at least become more skilled in C++ before you attempt this.

    If you would like to try anyway, do as per normal: take the first error, go to the line at the given line number, then see what is the problem. Perhaps by fixing it the remaining errors will "magically" disappear. You might need to read documentation, or otherwise read the other parts of the program, to understand enough to even begin fixing the problem, but that would be in line with your goal of understanding the code
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by jcfuller View Post
    I want to understand the coding not use the app.

    James
    Fair enough.
    You may get more help if you were to post the compile errors, though, as otherwise one would be required to compile the library oneself.
    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.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Posts
    63
    Quote Originally Posted by Elysia View Post
    Fair enough.
    You may get more help if you were to post the compile errors, though, as otherwise one would be required to compile the library oneself.
    I did give it a go you know.
    VC is much more forgiving than MinGW.
    I appears this post may be a futile effort if no one will download the source but I'll give it a try anyway.
    These are the VC error messages:


    Code:
    Compiling "main.cpp" To a "Windows Console App"
    Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    main.cpp
    main.cpp(54) : error C2668: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string' : ambiguous call to overloaded function
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xstring(949): could be 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)'
            with
            [
                _Elem=char
            ]
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xstring(885): or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&) throw()'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xstring(778): or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const _Elem *)'
            with
            [
                _Elem=char
            ]
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xstring(742): or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const std::allocator<char> &)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xstring(719): or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)'
            while trying to match the argument list '(token)'
    main.cpp(317) : error C2668: 'stoi' : ambiguous call to overloaded function
            c:\qb2cpp\org\QBasic.h(24): could be 'int stoi(std::string)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(360): or       'int std::stoi(const std::wstring &,size_t *,int)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(226): or       'int std::stoi(const std::string &,size_t *,int)'
            while trying to match the argument list '(std::string)'
    main.cpp(445) : error C2668: 'stoi' : ambiguous call to overloaded function
            c:\qb2cpp\org\QBasic.h(24): could be 'int stoi(std::string)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(360): or       'int std::stoi(const std::wstring &,size_t *,int)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(226): or       'int std::stoi(const std::string &,size_t *,int)'
            while trying to match the argument list '(std::string)'
    main.cpp(462) : error C2440: 'initializing' : cannot convert from 'token' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
            No constructor could take the source type, or constructor overload resolution was ambiguous
    Finished

    James

  7. #7
    Guest
    Guest
    I think the problem might have to do with casting the token struct to std::string.

    The custom operator on line 40...
    Code:
    operator string() { return name; }
    ... is supposed to allow for that, but it might not work as intended.

    On like 54, you could try...
    Code:
    var(List<token> lst, int y, varType def) : name(lst[y].name), type(def), isConst(false), isArray(false), defined(false) { (...) }
    ... and see if that moves the error downwards, or even fixes it. Just a hunch.
    Last edited by Guest; 04-13-2015 at 08:40 AM.

  8. #8
    Registered User
    Join Date
    Mar 2013
    Posts
    63
    Guest,
    Thank you. It did indeed work.
    Now we have:


    Code:
    Compiling "main.cpp" To a "Windows Console App"
    Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    main.cpp
    main.cpp(318) : error C2668: 'stoi' : ambiguous call to overloaded function
            c:\qb2cpp\jcf\QBasic.h(24): could be 'int stoi(std::string)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(360): or       'int std::stoi(const std::wstring &,size_t *,int)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(226): or       'int std::stoi(const std::string &,size_t *,int)'
            while trying to match the argument list '(std::string)'
    main.cpp(446) : error C2668: 'stoi' : ambiguous call to overloaded function
            c:\qb2cpp\jcf\QBasic.h(24): could be 'int stoi(std::string)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(360): or       'int std::stoi(const std::wstring &,size_t *,int)'
            C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string(226): or       'int std::stoi(const std::string &,size_t *,int)'
            while trying to match the argument list '(std::string)'
    main.cpp(463) : error C2440: 'initializing' : cannot convert from 'token' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
            No constructor could take the source type, or constructor overload resolution was ambiguous
    Finished

    These are lines 262-358
    Code:
    int Parse(int& LOC, fstream& fin, List<List<token>>& file) {
        string word="", buffer="";
        char readin;
        bool remFlag=false, quoteFlag=false;
        int lines=0;
        List<token> line;
        /*line.pushback("#include <iostream>");
        file.pushback(line);
        line[0]="#include <windows.h>");
        file.pushback(line);
        line[0]="#include <conio.h>");
        file*/
        while(!fin.eof()) {
            readin=fin.get();
            //handle remark/comment lines
            if(remFlag) {
                //end of a remark and end of a line
                if(readin=='\n') {
                    line.pushback(token(word, COMMENT));
                    file.pushback(line);
                    word="";
                    line.erase();
                    lines++;
                    remFlag=false;
                }
                else word+=readin;
            }
            //handle quotes
            else if(quoteFlag) {
                //end of a quote
                if(readin=='"') {
                    word+=readin;
                    line.pushback(token(word, QUOTE));
                    word="";
                    quoteFlag=false;
                }
                else word+=readin;
            }
            //handle operators
            else if(operators.found(buffer=readin)) {
                    if(word!="" && word!=" ") line.pushback(word);
                    word=readin;
                    line.pushback(token(word, OPERATOR));
                    word="";
            }
            //handle specific characters
            else {
                //handle end of word characters
                switch(readin) {
                case '\'':
                case '"':
                case ' ':
                case '\n':
                    if(word!="" && word!=" ") {
                        if(specials.found(word))
                            line.pushback(token(word, KEYWORD));
    (line 318)                    else if(itos(stoi(word))==word)
                            line.pushback(token(word, WINTEGER, true));
                        else
                            line.pushback(token(word, UNKNOWN));
                    }
                }
    
    
                switch(readin) {
                //start remark/comment line
                case '\'':
                    remFlag=true;
                    word="'";
                    break;
                //start quote
                case '"':
                    quoteFlag=true;
                    word='"';
                    break;
                //end of a word
                case ' ':
                    word="";
                    break;
                //end of a word and end of a line
                case '\n':
                    word="";
                    if (line.size()!=0) LOC++;
                    file.pushback(line);
                    line.erase();
                    lines++;
                    cout<<'.';
                    break;
                //everything else
                default:
                    word+=readin;
                    if(word=="REM") remFlag=true;
                }
            }
        }
        fin.clear();
        return lines;
    }

    James

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    My guess is that someone used "using namespace std" somewhere, and assumed that the name "stoi" isn't used, or wouldn't be used, in the standard library.
    Anyway, try prefixing all calls to stoi with "::", so "::stoi" or rename stoi in QBasic.h to something else.
    As you can see, the compiler is confused as to which overload it should be calling. There are two in the standard library and one i QBasic.h.
    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.

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Elysia View Post
    My guess is that someone used "using namespace std" somewhere, and assumed that the name "stoi" isn't used, or wouldn't be used, in the standard library.
    Very good guess; both of the header files are doing that.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  11. #11
    Registered User
    Join Date
    Mar 2013
    Posts
    63
    Thank you all.
    One more change in Translate procedure:
    string word=file[x][y];
    to
    string word=file[x][y].name;


    and all appears to be working.


    Now to see if I can follow the logic and if that logic is a good base??


    Feel free to comment on the quality of the code!


    James

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Very poor quality is my guess; I am a C Programmer so not really a good judge of C++ code.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by jcfuller View Post
    Feel free to comment on the quality of the code!
    I did a quick skim.

    It's not bad. I'm not sure how full-featured it is, or if it even works. But if it does work, it certainly gets a lot done with not a lot of code. And it isn't an eyesore. So, short, readable code, that works? It's decent.

    I was going to complain that it's not commented, but that's good news for you, because you get to understand it and put the comments in yourself. I'd certainly spend more time studying this if I were you.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem linking a sourceforge project
    By eloy in forum C Programming
    Replies: 15
    Last Post: 05-03-2011, 07:15 PM
  2. EMFPrinter Sourceforge Project Build from Source Code
    By stanlvw in forum Windows Programming
    Replies: 3
    Last Post: 05-27-2008, 02:58 PM
  3. Sourceforge project
    By Scarvenger in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-15-2007, 06:23 PM
  4. Starting a SourceForge project - need team members
    By ChadJohnson in forum Projects and Job Recruitment
    Replies: 8
    Last Post: 01-05-2006, 02:36 AM