simple program on linux

This is a discussion on simple program on linux within the Linux Programming forums, part of the Platform Specific Boards category; How do I have to change the following program so it will work in linux (g++)? Code: #include <iostream> using ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    51

    simple program on linux

    How do I have to change the following program so it will work in linux (g++)?

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    cout<<"Hello, world!";
    cin.get();
    return 0;
    }
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    That should compile fine. What error / warnings are you getting with g++?

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    51
    Quote Originally Posted by Thantos
    That should compile fine. What error / warnings are you getting with g++?
    This is the entire message:

    Code:
    hello.cpp:1: error: syntax error before `for'
    hello.cpp:1:36: missing terminating ' character
    hello.cpp:1:36: warning: character constant too long for its type
    hello.cpp:2: error: syntax error before `to'
    hello.cpp:3: error: syntax error before `text'
    hello.cpp:3:36: missing terminating ' character
    hello.cpp:3:36: warning: character constant too long for its type
    In file included from /usr/include/c++/3.3.3/i386-redhat-linux/bits/c++locale.h:42,
                     from /usr/include/c++/3.3.3/iosfwd:46,
                     from /usr/include/c++/3.3.3/ios:44,
                     from /usr/include/c++/3.3.3/ostream:45,
                     from /usr/include/c++/3.3.3/iostream:45,
                     from hello.cpp:4:
    /usr/include/langinfo.h:48: error: `__LC_TIME' was not declared in this scope
    /usr/include/langinfo.h:48: error: enumerator value for `ABDAY_1' not integer
       constant
    /usr/include/langinfo.h:241: error: `__LC_COLLATE' was not declared in this
       scope
    /usr/include/langinfo.h:241: error: enumerator value for `_NL_COLLATE_NRULES'
       not integer constant
    /usr/include/langinfo.h:265: error: `__LC_CTYPE' was not declared in this scope
    /usr/include/langinfo.h:265: error: enumerator value for `_NL_CTYPE_CLASS' not
       integer constant
    /usr/include/langinfo.h:357: error: `__LC_MONETARY' was not declared in this
       scope
    /usr/include/langinfo.h:357: error: enumerator value for `__INT_CURR_SYMBOL'
       not integer constant
    /usr/include/langinfo.h:471: error: `__LC_NUMERIC' was not declared in this
       scope
    /usr/include/langinfo.h:471: error: enumerator value for `__DECIMAL_POINT' not
       integer constant
    /usr/include/langinfo.h:492: error: `__LC_MESSAGES' was not declared in this
       scope
    /usr/include/langinfo.h:492: error: enumerator value for `__YESEXPR' not
       integer constant
    /usr/include/langinfo.h:507: error: `__LC_PAPER' was not declared in this scope
    /usr/include/langinfo.h:507: error: enumerator value for `_NL_PAPER_HEIGHT' not
       integer constant
    /usr/include/langinfo.h:512: error: `__LC_NAME' was not declared in this scope
    /usr/include/langinfo.h:512: error: enumerator value for `_NL_NAME_NAME_FMT'
       not integer constant
    /usr/include/langinfo.h:521: error: `__LC_ADDRESS' was not declared in this
       scope
    /usr/include/langinfo.h:521: error: enumerator value for `
       _NL_ADDRESS_POSTAL_FMT' not integer constant
    /usr/include/langinfo.h:536: error: `__LC_TELEPHONE' was not declared in this
       scope
    /usr/include/langinfo.h:536: error: enumerator value for `
       _NL_TELEPHONE_TEL_INT_FMT' not integer constant
    /usr/include/langinfo.h:543: error: `__LC_MEASUREMENT' was not declared in this
       scope
    /usr/include/langinfo.h:543: error: enumerator value for `
       _NL_MEASUREMENT_MEASUREMENT' not integer constant
    /usr/include/langinfo.h:547: error: `__LC_IDENTIFICATION' was not declared in
       this scope
    /usr/include/langinfo.h:547: error: enumerator value for `
       _NL_IDENTIFICATION_TITLE' not integer constant
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    What command line did you type to get that?

    What does
    g++ --version
    show for you?

    It looks a lot like you missed some installation step

    Also paste what you get when you compile with
    g++ -v prog.cpp
    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.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    51
    Quote Originally Posted by Salem
    What command line did you type to get that?

    What does
    g++ --version
    show for you?

    It looks a lot like you missed some installation step

    Also paste what you get when you compile with
    g++ -v prog.cpp
    "g++ --version" displays this:

    g++ (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
    Copyright (C) 2003 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    and "g++ -v hello.cpp" just shows loads of errors

    By the way, I haven't compiled anything with g++ before so it could be some installation-error...
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Definatly re-install it

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > and "g++ -v hello.cpp" just shows loads of errors
    Gee, ya think posting them would help?
    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.

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    51
    Quote Originally Posted by Salem
    > and "g++ -v hello.cpp" just shows loads of errors
    Gee, ya think posting them would help?
    I didn't post it because it looks really similar to the messages I got before, but here it is:

    Code:
    Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
    Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --disable-libunwind-exceptions --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
    Thread model: posix
    gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
     /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/cc1plus -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -D_GNU_SOURCE hello.cpp -D__GNUG__=3 -quiet -dumpbase hello.cpp -auxbase hello -version -o /tmp/ccjV6rAC.s
    GNU C++ version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) (i386-redhat-linux)
            compiled by GNU C version 3.3.3 20040412 (Red Hat Linux 3.3.3-7).
    GGC heuristics: --param ggc-min-expand=38 --param ggc-min-heapsize=15891
    ignoring nonexistent directory "/usr/i386-redhat-linux/include"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/include/c++/3.3.3
     /usr/include/c++/3.3.3/i386-redhat-linux
     /usr/include/c++/3.3.3/backward
     /usr/local/include
     /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/include
     /usr/include
    End of search list.
    hello.cpp:1: error: syntax error before `for'
    hello.cpp:1:36: missing terminating ' character
    hello.cpp:1:36: warning: character constant too long for its type
    hello.cpp:2: error: syntax error before `to'
    hello.cpp:3: error: syntax error before `text'
    hello.cpp:3:36: missing terminating ' character
    hello.cpp:3:36: warning: character constant too long for its type
    In file included from /usr/include/c++/3.3.3/i386-redhat-linux/bits/c++locale.h:42,
                     from /usr/include/c++/3.3.3/iosfwd:46,
                     from /usr/include/c++/3.3.3/ios:44,
                     from /usr/include/c++/3.3.3/ostream:45,
                     from /usr/include/c++/3.3.3/iostream:45,
                     from hello.cpp:4:
    /usr/include/langinfo.h:48: error: `__LC_TIME' was not declared in this scope
    /usr/include/langinfo.h:48: error: enumerator value for `ABDAY_1' not integer
       constant
    /usr/include/langinfo.h:241: error: `__LC_COLLATE' was not declared in this
       scope
    /usr/include/langinfo.h:241: error: enumerator value for `_NL_COLLATE_NRULES'
       not integer constant
    /usr/include/langinfo.h:265: error: `__LC_CTYPE' was not declared in this scope
    /usr/include/langinfo.h:265: error: enumerator value for `_NL_CTYPE_CLASS' not
       integer constant
    /usr/include/langinfo.h:357: error: `__LC_MONETARY' was not declared in this
       scope
    /usr/include/langinfo.h:357: error: enumerator value for `__INT_CURR_SYMBOL'
       not integer constant
    /usr/include/langinfo.h:471: error: `__LC_NUMERIC' was not declared in this
       scope
    /usr/include/langinfo.h:471: error: enumerator value for `__DECIMAL_POINT' not
       integer constant
    /usr/include/langinfo.h:492: error: `__LC_MESSAGES' was not declared in this
       scope
    /usr/include/langinfo.h:492: error: enumerator value for `__YESEXPR' not
       integer constant
    /usr/include/langinfo.h:507: error: `__LC_PAPER' was not declared in this scope
    /usr/include/langinfo.h:507: error: enumerator value for `_NL_PAPER_HEIGHT' not
       integer constant
    /usr/include/langinfo.h:512: error: `__LC_NAME' was not declared in this scope
    /usr/include/langinfo.h:512: error: enumerator value for `_NL_NAME_NAME_FMT'
       not integer constant
    /usr/include/langinfo.h:521: error: `__LC_ADDRESS' was not declared in this
       scope
    /usr/include/langinfo.h:521: error: enumerator value for `
       _NL_ADDRESS_POSTAL_FMT' not integer constant
    /usr/include/langinfo.h:536: error: `__LC_TELEPHONE' was not declared in this
       scope
    /usr/include/langinfo.h:536: error: enumerator value for `
       _NL_TELEPHONE_TEL_INT_FMT' not integer constant
    /usr/include/langinfo.h:543: error: `__LC_MEASUREMENT' was not declared in this
       scope
    /usr/include/langinfo.h:543: error: enumerator value for `
       _NL_MEASUREMENT_MEASUREMENT' not integer constant
    /usr/include/langinfo.h:547: error: `__LC_IDENTIFICATION' was not declared in
       this scope
    /usr/include/langinfo.h:547: error: enumerator value for `
       _NL_IDENTIFICATION_TITLE' not integer constant
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    This is a big red flag for me
    ignoring nonexistent directory "/usr/i386-redhat-linux/include"

  10. #10
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I would reinstall it. If you can check and see if they are in /usr/include. try
    Code:
    g++ -o test test.c -I /usr/include
    or 
    g++ -o test test.c -I /usr/386-redhat-linux/include

  11. #11
    Registered User
    Join Date
    May 2002
    Posts
    51
    I've reinstalled it and it works. I guess some error occured because the linux installation program installed it the first time.

    Thanks for your help
    I abuse:

    Borland C++ Builder 6 Enterprise Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need a simple program
    By Peter Griffin in forum C++ Programming
    Replies: 7
    Last Post: 12-04-2005, 03:23 PM
  2. Replies: 5
    Last Post: 11-27-2005, 08:50 PM
  3. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM
  4. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

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