problems with g++ compiling
Hi all,
I have a problem compiling c++ programs using g++. I have installed gcc 3.4.3-9EL4 on a red hat 2.6.9-5.ELsmp. When trying to compile the simple 'helloworld.cpp' I get error messages for every line. the problems appeared after I tried to install two different versions of gcc (did not work, and now nothing works when compiling c++) g++ hello.cpp hello.cpp:1:19: iostream: No such file or directory hello.cpp: In function `int main()': hello.cpp:7: error: `cout' undeclared (first use this function) hello.cpp:7: error: (Each undeclared identifier is reported only once for each function it appears in.) it looks like c++ code is not recognized properly. I have tried to install gcc again (3.4.3), configuration works, but when typing 'make' I get the following error message: if [ -f stmp-dirs ]; then true; else touch stmp-dirs; fi /home/klaus/Desktop/gcc-3.4.3/gcc/xgcc -B/home/klaus/Desktop/gcc-3.4.3/gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -shared -nodefaultlibs -Wl,--soname=libgcc_s.so.1 -Wl,--version-script=libgcc/32/libgcc.map -o 32/libgcc_s.so.1.tmp -m32 libgcc/32/_muldi3.o libgcc/32/_negdi2.o libgcc/32/_lshrdi3.o libgcc/32/_ashldi3.o libgcc/32/_ashrdi3.o libgcc/32/_cmpdi2.o libgcc/32/_ucmpdi2.o libgcc/32/_floatdidf.o libgcc/32/_floatdisf.o libgcc/32/_fixunsdfsi.o libgcc/32/_fixunssfsi.o libgcc/32/_fixunsdfdi.o libgcc/32/_fixdfdi.o libgcc/32/_fixunssfdi.o libgcc/32/_fixsfdi.o libgcc/32/_fixxfdi.o libgcc/32/_fixunsxfdi.o libgcc/32/_floatdixf.o libgcc/32/_fixunsxfsi.o libgcc/32/_fixtfdi.o libgcc/32/_fixunstfdi.o libgcc/32/_floatditf.o libgcc/32/_clear_cache.o libgcc/32/_enable_execute_stack.o libgcc/32/_trampoline.o libgcc/32/__main.o libgcc/32/_absvsi2.o libgcc/32/_absvdi2.o libgcc/32/_addvsi3.o libgcc/32/_addvdi3.o libgcc/32/_subvsi3.o libgcc/32/_subvdi3.o libgcc/32/_mulvsi3.o libgcc/32/_mulvdi3.o libgcc/32/_negvsi2.o libgcc/32/_negvdi2.o libgcc/32/_ctors.o libgcc/32/_ffssi2.o libgcc/32/_ffsdi2.o libgcc/32/_clz.o libgcc/32/_clzsi2.o libgcc/32/_clzdi2.o libgcc/32/_ctzsi2.o libgcc/32/_ctzdi2.o libgcc/32/_popcount_tab.o libgcc/32/_popcountsi2.o libgcc/32/_popcountdi2.o libgcc/32/_paritysi2.o libgcc/32/_paritydi2.o libgcc/32/_divdi3.o libgcc/32/_moddi3.o libgcc/32/_udivdi3.o libgcc/32/_umoddi3.o libgcc/32/_udiv_w_sdiv.o libgcc/32/_udivmoddi4.o libgcc/32/unwind-dw2.o libgcc/32/unwind-dw2-fde-glibc.o libgcc/32/unwind-sjlj.o libgcc/32/gthr-gnat.o libgcc/32/unwind-c.o -lc && rm -f libgcc_s_32.so && if [ -f 32/libgcc_s.so.1 ]; then mv -f 32/libgcc_s.so.1 32/libgcc_s.so.1.`basename `; else true; fi && mv 32/libgcc_s.so.1.tmp 32/libgcc_s.so.1 && ln -s 32/libgcc_s.so.1 libgcc_s_32.so /usr/bin/ld: crti.o: No such file: No such file or directory collect2: ld returned 1 exit status make[2]: *** [32/libgcc_s_32.so] Error 1 make[2]: Leaving directory `/home/klaus/Desktop/gcc-3.4.3/gcc' make[1]: *** [stmp-multilib] Error 2 make[1]: Leaving directory `/home/klaus/Desktop/gcc-3.4.3/gcc' make: *** [all-gcc] Error 2 ... since I am also quite new in Linux, I don't really know what to do... thanks in advance, klaus |
Removed. Just understood question.
|
Post your hello world code. It should look something like:
#include <iostream> int main() { using namespace std; cout << "Hello World" << endl; return 0; } The error you are getting is usually indicative of forgetting to put in the "using namespace std" line. |
Quote:
This program should compile and run successfully: Code:
#include <iostream> Code:
$ make program |
hi,
thank you all in advance! I have a helloworld file like #include<iostream> using namespace std; int main() { cout<<"hello world"; } Generally, I can not compile any c++ program, I just wanted to test it with a simple one. if I do: [klaus@ICHE198 ~/Desktop]$ make programm %%as suggested g++ programm.cpp -o programm programm.cpp:1: error: expected constructor, destructor, or type conversion before '<' token programm.cpp:1: error: expected `,' or `;' before '<' token make: *** [programm] Error 1 A friend told me, if nothing works with c++, I should remove gcc. Do you know, how I can do that? I did not install it with rpm... thank you for your suggestions! klaus |
Quote:
Code:
#include<iostream> Code:
cout<<"hello world"; If you will fix your syntax errors and follow standard coding practices, chances are your program will compile and run. I emphasize these are issues that should be addressed, they aren't necessarily the cause of your present problems. Quote:
|
Quote:
I'm not at a Centos system now to check the name of the overall package that will install the header and library packages you need. In another thread at LQ, talking about a different distribution, I just saw someone say that package is build-essential. That might be correct an might apply to Red Hat as well. Alternately, as you discover individual files missing, such as iostream, you can switch to root and give the yum command to find out what package that file is in: Code:
yum provides "*/iostream" |
hi again,
thanks for your suggestions. I corrected the helloworld, but errors stayed the same. Well, when the red hat was installed, 'we' put the gcc also there. It looks like it is installed via rpm, doesnt it?: [klaus@ICHE198 ~]$ rpm -q gcc gcc-3.4.3-9.EL4 I removed the gcc package via --nodeps Now gcc is removed, I can not find it anymore, but looks like g++ is still there?: [root@ICHE198 klaus]# gcc bash: gcc: command not found [root@ICHE198 klaus]# g++ g++: no input files [root@ICHE198 klaus]# [root@ICHE198 Desktop]# rpm -q gcc package gcc is not installed [root@ICHE198 Desktop]# rpm -q g++* package g++* is not installed [root@ICHE198 Desktop]# g++ yields the same errors as before. Should I just install a new gcc now? thanks in advance, klaus |
'gcc' should not be removed !
# yum provides */iostream # yum install gcc-c++ .. will do. 'gcc-c++' provides /usr/include/c++/3.x.x/iostream . ..... |
Quote:
libstdc++ provides /usr/include/c++/VariousVersions/iostream I'm not exactly an expert in Yum. But I can't see how gcc-c++ provides iostream. If the OP removed gcc-c++, he should certainly reinstall it. But I'm not convinced that is enough. I suggest Code:
yum install gcc-c++ |
Code:
gcc 3.4.3-9EL4 on a red hat 2.6.9-5.ELsmp OP, do the following: Code:
up2date -i "@ Development Tools" |
Quote:
I've never installed any RHEL system, (just Centos 5.1 and 5.3) and I'm not involved in maintaining those RHEL4 systems. So I have no real guess how far they have diverged from normal RHEL4. At some point soon they will be reinstalled as Centos. |
Hydrazin, post the output of:
$ rpm -qa | grep gcc that should list all the packages installed with gcc in their name. Typically, you should have gcc itself, a preprocessor package having "gcc-cpp" in the package name, a libgcc package and for c++ support, a gcc-c++ package. In most distros, it's not possible to have g++ installed without the supporting c++ standard libraries, i.e. they're included in the gcc-c++ package. At least that's the case in mandriva but RH may package differently. |
hi all again,
as written, I removed the gcc... if I do the up2date command, I get some error (Error Class Code: 70 Error Class Info: All available subscriptions for the requested channel have been exhausted. Please contact a Red Hat Network Sales associate. Explanation: An error has occurred while processing your request. If this problem persists please enter a bug report at bugzilla.redhat.com. If you choose to submit the bug report, please be sure to include details of what you were trying to do when this error occurred and details on how to reproduce this problem.) I think the system is now to old and there is no service included anymore? I tried the following (hopefully harmless) procedure: Code:
[klaus@ICHE198 ~/Desktop]$ rpm -Uhv gcc-3.4.3-4.i386.rpm Code:
[root@ICHE198 Desktop]# rpm -Uhv libgcc-3.4.3-3.i586.rpm thanks again for your help, as you see, I don't really know what i am doing when installing these libraries... thanx klaus |
sorry, i did not see the last post before mine,
Code:
[klaus@ICHE198 ~/Desktop]$ rpm -qa | grep gcc but still, I got Code:
[klaus@ICHE198 ~/Desktop]$ which gcc |
All times are GMT -5. The time now is 06:38 PM. |