This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++ question


I'm sitting here on Christmas day with not a lot to do until later, so I decided I'd see if I could "sharpen the saw" a bit an work on a bit of C++ (it has been a long time since I wrote any C++, but I've used it before). However, to my astonishment and dismay, I can compile from "program.cpp" to "program.o", but I can't link "program.o" to make "program". So, I decided to return to my "roots", if you will, and write a simple little C++ program named "hello" that simply displays "Hello, World!" in a terminal window (I've attached the source file).

OK, before I go any further, I'm running Red Hat 8.0 (I installed EVERYTHING - yes, it was a huge install, but I had plenty of room). The complier is the GNU compiler that came with the install (gcc version 3.2).

I made a series of "Makefiles" to better document my travails. The first one, "Makefile1", I expected to fail -- and it did (results of the "make -f Makefile1" command are in "make1.txt"). The results indicated that I needed to link to the library that contains "cout" and "ostream". So I proceded to try "Makefile2", the results of which are in "make2.txt".

Becoming a bit frustrated, I built a script that created a combined table of contents of every ".a" file located in the "/usr/lib" directory. A quick search of the resulting file shows no instance of an "ostream.o" object in any of the libraries. Digging a bit deeper into the /usr/lib directory tree, I found /usr/lib/gcc-lib. So I followed it down to "/usr/lib/gcc-lib/i386-redhat-linux/3.2". I added this directory to my /etc/ld.so.conf file and ran ldconfig. I created "Makefile3", the results of which are in "make3.txt". Since that didn't work, I created "Makefile4", the results of which are in "make4.txt".

I'm at a loss -- where should I be looking for the proper link libraries?

--
John Burski

@HOME S.I.M.U. (Well, sometimes I am :) )

... and still searching for the cheese!

// File: hello.cpp

#include <iostream>

int main() 
{
   cout << "Hello, World\n";
}
INCLUDE = /usr/include/g++-3

hello: hello.o
	g++ -ohello hello.o

hello.o: hello.cpp
	g++ -c -I$(INCLUDE) hello.cpp
Script started on Wed Dec 25 13:04:58 2002
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ 
[jburski@natasha c++]$ m
[jburski@natasha c++]$ m
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile1
[jburski@natasha c++]$ make -f Makefile1
g++ -ohello hello.o
hello.o: In function `main':
hello.o(.text+0x19): undefined reference to `cout'
hello.o(.text+0x1e): undefined reference to `ostream::operator<<(char const*)'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ exit

Script done on Wed Dec 25 13:05:09 2002
INCLUDE = /usr/include/g++-3
LIBES = -lstdc++-3-libc6.2-2-2.10.0

hello: hello.o
	g++ -o hello hello.o $(LIBES)

hello.o: hello.cpp
	g++ -c -I$(INCLUDE) hello.cpp
Script started on Wed Dec 25 13:11:24 2002
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ 
[jburski@natasha c++]$ m
[jburski@natasha c++]$ m
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile2
[jburski@natasha c++]$ make -f Makefile2
g++ -o hello hello.o -lstdc++-3-libc6.2-2-2.10.0
hello.o: In function `main':
hello.o(.text+0x1e): undefined reference to `ostream::operator<<(char const*)'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ exit

Script done on Wed Dec 25 13:11:33 2002
INCLUDE = /usr/include/g++-3
LIBES = -lgcc

hello: hello.o
	g++ -o hello hello.o $(LIBES)

hello.o: hello.cpp
	g++ -c -I$(INCLUDE) hello.cpp
Script started on Wed Dec 25 14:13:07 2002
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ 
[jburski@natasha c++]$ m
[jburski@natasha c++]$ m
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Mad
[jburski@natasha c++]$ make -f Mad
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile3
[jburski@natasha c++]$ make -f Makefile3
g++ -o hello hello.o -lgcc
hello.o: In function `main':
hello.o(.text+0x19): undefined reference to `cout'
hello.o(.text+0x1e): undefined reference to `ostream::operator<<(char const*)'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ exit

Script done on Wed Dec 25 14:13:55 2002
INCLUDE = /usr/include/g++-3
LIBES = -lstdc++

hello: hello.o
	g++ -o hello hello.o $(LIBES)

hello.o: hello.cpp
	g++ -c -I$(INCLUDE) hello.cpp
Script started on Wed Dec 25 14:17:31 2002
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ 
[jburski@natasha c++]$ m
[jburski@natasha c++]$ m
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ ma
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ mak
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make 
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f 
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f M
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Ma
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Mak
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Make
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makef
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefi
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefil
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile
[jburski@natasha c++]$ make -f Makefile4
[jburski@natasha c++]$ make -f Makefile4
g++ -o hello hello.o -lstdc++
hello.o: In function `main':
hello.o(.text+0x19): undefined reference to `cout'
hello.o(.text+0x1e): undefined reference to `ostream::operator<<(char const*)'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
]0;jburski@natasha:~/toolkit/postgresql/c++

[jburski@natasha c++]$ 
[jburski@natasha c++]$ exit

Script done on Wed Dec 25 14:17:42 2002

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]