Compiling C++ code on Red Hat Linux
I am new to doing command line C++ compiling and linking in Linux. I have been a Developer Studio programmer for years in the Windows environment, so I am spoiled. We are porting a group of C++ programs from Solaris 10 to Red Hat version 5 and I am having trouble getting the include and library paths correct in the make file. Getting a "make Error 127" - Command not found when I run the make file. The makefile is shown below.
*************************************************************************** *************************************************************************** #################################################################### APP_HOME=/home/payroll/c EXE_HOME=${APP_HOME}/exe GOBJ=$(EXE_HOME) GEXE=$(EXE_HOME) #CC=gcc CC=g++ # Options to be passed to your C++ compiler: CCOPTIONS= -O # Where the library is located: LIBDIR=-I/usr/lib/ # STL header include path STLINCL=-I/usr/include/ # USER's header include path USERINCL=-I/home/payroll/c/include/ # Full path to the library: LIBFULL= $(LIBDIR) # Link directives for the library: LIBLINK= # Compile flags: CPPFLAGS= $(STLINCL) $(USERINCL) $(CCOPTIONS) -library=iostream ######################## Executables ####################### # STL based examples: STL= mmapptr dequeval # Template example programs: TEMPLATE= tvdlist tpdlist # Internationalization example programs: I18N= i18n ########################## Targets ######################## CONVERTCIPS_OBJ=cipsfile.o convertengine.o convertcipsapp.o convertcipsmain.o all: convertcips convertcips: $(EXE_HOME)/convertcips # clean: $(RM) *.o ########################## Conversions ######################## .SUFFIXES: .cpp .C .cc .cxx .o ################################################## # general case for compilation %.o: %.cpp $(CCC) $(CPPFLAGS) -c -o $@ $< $(EXE_HOME)/convertcips: $(CONVERTCIPS_OBJ) $(CC) $(CPPFLAGS) -o $(EXE_HOME)/convertcips $(CONVERTCIPS_OBJ) $(LIBFULL) rm *.o Any help is greatly appreciated. |
ALways paste the whole error, even if you don't know what it all means. It should be telling you what line in your Makefile has a problem.
Here's what I see: There is an extra space after '=' on several lines. Remove them. Makefiles are not free-form. There are no instructions in the rule to make convertcips. I don't see where CCC is defined. |
Here is the error. I found the error with CCC, I left off a c in the makefile definition.
********************************************************************************************** [rpegram@finn c]$ make -f makelinux.mk I/usr/include/ SERINCL -O -library=iostream -c -o cipsfile.o cipsfile.cpp make: I/usr/include/: Command not found make: [cipsfile.o] Error 127 (ignored) I/usr/include/ SERINCL -O -library=iostream -c -o convertengine.o convertengine.cpp make: I/usr/include/: Command not found make: [convertengine.o] Error 127 (ignored) I/usr/include/ SERINCL -O -library=iostream -c -o convertcipsapp.o convertcipsapp.cpp make: I/usr/include/: Command not found make: [convertcipsapp.o] Error 127 (ignored) I/usr/include/ SERINCL -O -library=iostream -c -o convertcipsmain.o convertcipsmain.cpp make: I/usr/include/: Command not found make: [convertcipsmain.o] Error 127 (ignored) g++ -I/usr/include/ SERINCL -O -library=iostream -o /home/payroll/c/exe/convertcips cipsfile.o convertengine.o convertcipsapp.o convertcipsmain.o -I/usr/lib/ g++: SERINCL: No such file or directory g++: cipsfile.o: No such file or directory g++: convertengine.o: No such file or directory g++: convertcipsapp.o: No such file or directory g++: convertcipsmain.o: No such file or directory make: *** [/home/payroll/c/exe/convertcips] Error 1 |
Made some progress, objects are being created now. Now need to work on linking objects. Here is the make file again.
********************************************** APP_HOME=/home/payroll/c EXE_HOME=${APP_HOME}/exe GOBJ=$(EXE_HOME) GEXE=$(EXE_HOME) #CCC=gcc CCC=g++ # Options to be passed to your C++ compiler: CCOPTIONS= -O # Where the library is located: LIBDIR=-I/usr/lib/ # STL header include path STLINCL=-I/usr/include/ # USER's header include path USERINCL=-I/home/payroll/c/include/ # Full path to the library: LIBFULL= $(LIBDIR) # Link directives for the library: LIBLINK= # Compile flags: CPPFLAGS= $(STLINCL) $(USERINCL) $(CCOPTIONS) -library=iostream ######################## Executables ####################### # STL based examples: STL= mmapptr dequeval # Template example programs: TEMPLATE= tvdlist tpdlist # Internationalization example programs: I18N= i18n ########################## Targets ######################## CONVERTCIPS_OBJ=cipsfile.o convertengine.o convertcipsapp.o convertcipsmain.o all: convertcips convertcips: $(EXE_HOME)/convertcips # clean: $(RM) *.o ########################## Conversions ######################## .SUFFIXES: .cpp .C .cc .cxx .o ################################################## # general case for compilation %.o: %.cpp $(CCC) $(CPPFLAGS) -c -o $@ $< $(EXE_HOME)/convertcips: $(CONVERTCIPS_OBJ) $(CCC) $(CPPFLAGS) -o $(EXE_HOME)/convertcips $(CONVERTCIPS_OBJ) $(LIBFULL) rm *.o ********************************************** Output results from current makefile ********************************************************** make -f makelinux.mk g++ -I/usr/include/ -I/home/payroll/c/include/ -O -library=iostream -c -o cipsfile.o cipsfile.cpp cipsfile.cpp: In member function âint CipsFile::GetNextLine(unsigned char*, int)â: cipsfile.cpp:327: warning: NULL used in arithmetic g++: -library=iostream: linker input file unused because linking not done g++ -I/usr/include/ -I/home/payroll/c/include/ -O -library=iostream -c -o convertengine.o convertengine.cpp g++: -library=iostream: linker input file unused because linking not done g++ -I/usr/include/ -I/home/payroll/c/include/ -O -library=iostream -c -o convertcipsapp.o convertcipsapp.cpp g++: -library=iostream: linker input file unused because linking not done g++ -I/usr/include/ -I/home/payroll/c/include/ -O -library=iostream -c -o convertcipsmain.o convertcipsmain.cpp g++: -library=iostream: linker input file unused because linking not done g++ -I/usr/include/ -I/home/payroll/c/include/ -O -library=iostream -o /home/payroll/c/exe/convertcips cipsfile.o convertengine.o convertcipsapp.o convertcipsmain.o -I/usr/lib/ /usr/bin/ld: cannot find -library=iostream collect2: ld returned 1 exit status make: *** [/home/payroll/c/exe/convertcips] Error 1 |
did you install the development tools ? ( looks like it ? BUT ???? you might be missing things ?
and did you install from source / or the *-devel.rpm's for ALL prerequisites most are not installed by default in RHEL having them on a server is a security risk ( a "bad guy" could then build the spy software on the server) please USE code tags Code:
make -f makelinux.mk Autotools are a bit better , but for a small program ?? maybe not Quote:
where is that coming from ? it is causing one of the errors |
No I did not install from development tools. I have no reference documentation for compiles as this is a new process here and the other developers have not experience with the platform. I am basically shooting in the dark trying to create a basic makefile that works and can be put into a Source Code Control system so the next person after me does not have to feel the pain like I do if changes have and will be made in the future.
|
Are you trying to build a 32-bit executable or a 64-bit? If you have a 32-bit RHEL, you must be building 32-bit and you can ignore this concern. But if you have 64-bit RHEL, I'm not sure whether the g++ default is 32-bit or 64-bit.
/usr/lib/ is 32-bit even on 64-bit RHEL, so if the g++ default is 64-bit, your choice of usr/lib instead of /usr/lib64 might be an issue (EDIT: after you fix other syntax problems that I didn't initially notice that make your choice of lib vs. lib64 not yet relevant). I always prefer to have one of -m32 or -m64 in my CPPFLAGS, so there is no ambiguity about what I am trying to build. |
so you are moving over to RHEL
is there a reason to use the now, starting to age ,older RHEL5.9 ( it is rhel5.9 ? and not 5.1 ?) and not the current RHEL6.3 The 5 series is supported but it is also starting to show sings of it's old age With RHEL requiring a support contract your company is paying for the license and the support that comes with it you can start with the Red hat knowledge base ( loging in to red hat will be required) https://access.redhat.com/search/quick? and there is the open to EVERYONE documentation https://access.redhat.com/knowledge/...erprise_Linux/ the docs for the older 5 are near the bottom Other references http://www.tldp.org/ and look on Amazon for the older "red hat enterprise linux 5 "bible" " |
All times are GMT -5. The time now is 03:43 AM. |