Error when using make file.


 
Thread Tools Search this Thread
Operating Systems Linux Error when using make file.
# 1  
Old 07-13-2011
Error when using make file.

hello,

i want to execute hello world using cross compiler ppc_4xx-gcc. i have this makefile:
Code:
 CC=    $(shell which ppc_4xx-gcc) 
#CC=g++    
CXXFLAGS=-cpp -Wall    
LDFLAGS=    
SOURCES=main.cpp hello.h    
OBJECTS=$(SOURCES:.cpp=.o)    
EXECUTABLE=hello    

all: $(SOURCES) $(EXECUTABLE)    
    
$(EXECUTABLE): $(OBJECTS)    
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@    

.cpp.o:
    $(CC) $(CXXFLAGS) $< -o $@

and the hello.h and main.cpp developped using visuel c++:
main.cpp:

Code:
#include <iostream.h>
#include "hello.h"
using namespace std;
int main(){
    hello();
    cout << endl;
    
    return 0;
}

hello.h:
Code:
#include <iostream.h>
using namespace std;

void hello(){
   cout << "Hello World!";
}

i get many errors of this kind:
Code:
main.cpp:(.text+0x21a): undefined reference to `std::cout'

can any one help me

thank you

Moderator's Comments:
Mod Comment Please use [CODE] tags when posting source listings, console output, ...

Last edited by pludi; 07-13-2011 at 11:57 AM..
# 2  
Old 07-13-2011
gcc will happily compile c++ objects but can't tell the difference between C .o files and c++ .o files. So when you try and link a c++ program with gcc, it won't link in the C++ libraries and things will be missing. link with g++.
# 3  
Old 07-13-2011
i make this change:
Code:
CC=    $(shell which ppc_4xx-g++) 
#CC=g++    
CXXFLAGS=-cpp -Wall    
LDFLAGS=-arch ppc    
SOURCES=main.cpp hello.h    
OBJECTS=$(SOURCES:.cpp=.o)    
EXECUTABLE=hello    

all: $(SOURCES) $(EXECUTABLE)    
    
$(EXECUTABLE): $(OBJECTS)    
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@    

.cpp.o:
    $(CC) $(CXXFLAGS) $< -o $@

a new errors like that:
Code:
ppc_4xx-g++: unrecognized option '-cpp'
In file included from /home/opt/eldk_4.2/ppc_4xx/usr/include/c++/4.2.2/backward/iostream.h:31,
                 from main.cpp:1:

Moderator's Comments:
Mod Comment Please use [CODE] tags when posting source listings, console output, ...
# 4  
Old 07-13-2011
So don't give it -cpp.
# 5  
Old 07-13-2011
thank you,

i change makefile and also i just keep #include <iostream> without "h":

CC= $(shell which ppc_4xx-g++)
CXXFLAGS=-c++ -Wall
LDFLAGS=
SOURCES=main.cpp hello.h
OBJECTS=$(SOURCES:.c++=.o)
EXECUTABLE=hello

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
$(CC) $(CXXFLAGS) $< -o $@

and i obtain this result :/opt/eldk_4.2/usr/bin/ppc_4xx-g++ main.cpp hello.h -o hello

i obtain two files: main.o and hello

is it ok?

because it's the first time that i use the make file.

why i didn't see hello world?

thanks an advance
# 6  
Old 07-13-2011
This is correct, it compiled main.cpp file into an object file, main.o, then linked it into an executable file, 'hello'.

It didn't print "hello world" because you didn't actually run ./hello
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

error while executing make file

hi i am facing a strange error... whenever i try to execute make file it gives the following error bash-3.00$ make usa0300uz1128 sh: syntax error at line 1: `end of file' unexpected mksh: Fatal error: The command `if ; then echo "${COMMON}/src/rules/rules_11.2.0.3.2012Q3"; elif... (1 Reply)
Discussion started by: aishsimplesweet
1 Replies

2. UNIX Desktop Questions & Answers

Gtkmm Make Then Error

I would like to install gtkmm-2.0.1 on solaris 10 platform. To install, I have a dependency libsigc++1.2 successfully install. I can type ./configure without any error. But when I typed make I got the following error. I am newbie who cannot understand the error. Have no idea how to solve... (0 Replies)
Discussion started by: nirin
0 Replies

3. Shell Programming and Scripting

Make file error

I am new to using make command and I keep getting this error time and again please help me Make file is as follows #ARCH := $(shell uname)# # ifeq ($(ARCH), SunOS) DEFINES = -KPIC -DSVR4 -DSOLARIS -DSYSV -D__svr4 -D__svr4__\ -D_REENTRANT -DSOLARIS2_5 -D_SVID_GETTOD -DXP_UNIX -UDEBUG... (1 Reply)
Discussion started by: c.operatingsys
1 Replies

4. Programming

Error with Make File

Hi All, I am using GNU Make and i have a peculiar kind of error, i am not able to understand, Firstly have a look at the make file used by me CFLAGS=-c -Wall CC=gcc .PHONY:clean OBJ=./obj SRC=./src INC=./inc exec: $(OBJ)/*.o $(CC) $^ -o $@ %.o: $(SRC)/*.c $(CC) $(CFLAGS)... (1 Reply)
Discussion started by: niranjanvg
1 Replies

5. Programming

Make error

Hello, Is someone know why this generate an error : all: dt = $(shell date) echo "$(dt)" (5 Replies)
Discussion started by: X-Or
5 Replies

6. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

7. Solaris

Gani Network Driver Won't Install - make: Fatal error: Don't know how to make targ...

I attached a README file that I will refer to. I successfully completed everything in the README file until step 4. # pwd /gani/gani-2.4.4 # ls COPYING Makefile.macros gem.c Makefile Makefile.sparc_gcc gem.h Makefile.amd64_gcc ... (1 Reply)
Discussion started by: Bradj47
1 Replies

8. Linux

Error in issuing a make and make install

Hi, Recently I install a package and try to do a make and make install. However, in the make it gives me below error:- make:Nothing to be done for 'install-exec-am' make:Nothing to be done for 'install-data-am' Can anyone please explain to me what does this mean? I have been trying... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

9. Programming

Error while running C++ make file

The problem is that the original program was compiled using v5.0 MQ client but now we are using MQ client v5.3. Had modified the "make file" options as follows but still i could see the errors. #CLIENT_V5_LIBS = -limqb23ss -limqc23ss -lmqic -lmqmcs -lnsl -ldl CLIENT_V5.3_LIBS =... (1 Reply)
Discussion started by: hram
1 Replies

10. Programming

Error when running make

Hi , I get the following error when i run the make command. cc -Aa -DUNIX -osrcmpmn srcmpmn.c crt0: ERROR couldn't open /usr/lib/dld.sl errno:000000014 *** Error exit code 14 here the file is C program which has been modified. Please help. (1 Reply)
Discussion started by: shashidhara_01
1 Replies
Login or Register to Ask a Question