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; }
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
That should compile fine. What error / warnings are you getting with g++?
This is the entire message:Originally Posted by Thantos
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
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.
"g++ --version" displays this:Originally Posted by Salem
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
> 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 didn't post it because it looks really similar to the messages I got before, but here it is:Originally Posted by Salem
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
This is a big red flag for me
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
I would reinstall it. If you can check and see if they are in /usr/include. tryCode:g++ -o test test.c -I /usr/include or g++ -o test test.c -I /usr/386-redhat-linux/include
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