hello,
i want to execute hello world using cross compiler ppc_4xx-gcc. i have this makefile:
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:
#include <iostream.h>
#include "hello.h"
using namespace std;
int main(){
hello();
cout << endl;
return 0;
}
hello.h:
#include <iostream.h>
using namespace std;
void hello(){
cout << "Hello World!";
}
i get many errors of this kind:
main.cpp:(.text+0x21a): undefined reference to `std::cout'
can any one help me
thank you
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++.
i make this change:
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:
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:
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
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