Need to compile large C++ code with gcc/4.7.2. Getting "undefined reference" errors that I don't understand

Hello, I'm trying to compile a large C++ code with gcc/4.7.2. There are a few C files sprinkled throughout the code. I first compile several individual libraries. Then I run a calculation that uses the libraries. When I run the calculation, I have trouble with one of the libraries (the rest of them are fine).

I have to use gcc/4.7.2 because it is the only compiler I can use for what I need on a Linux cluster. I have been compiling the code with g++ and running it on a Mac.

I have many errors, but here are the first ones, to demonstrate what the problem is.
Code.o: In function `_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.part.8':
Code.cpp:(.text+0x12): undefined reference to `std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
Code.o: In function `_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.constprop.101':
Code.cpp:(.text+0x35): undefined reference to `std::cout'
Code.cpp:(.text+0x3a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
Code.cpp:(.text+0x3f): undefined reference to `std::cout'
Code.cpp:(.text+0x49): undefined reference to `std::cout'
Code.cpp:(.text+0x53): undefined reference to `std::cout'


When I was compiling the libraries, I got these kinds of errors when C++ headers were used instead of C headers. Or when a C file needed to be used. But in this case, I have no idea what the problem is. All the files that make up this library at C++ files, the headers look fine.

My question is, how can I even start figuring out where the problem is arising? Code.cpp is an enormous file and I have no idea which function is affected. Do these weird codes mean anything--e.g., 0x53?

If someone could be so kind as to get me started, I would be very grateful. I'm completely stuck! I don't have much experience at compiler/linker issues; I use the code for engineering purposes.
Last edited on
closed account (Dy7SLyTq)
using namespace std?
$ g++ Code.cpp
$ gcc Code.cpp -lstdc++
Last edited on
Hi everyone, thanks for your replies.

I have added "using namespace standard" and I have added "-lstdc++" to my makefile "CXXFLAGS."

I took a closer look at all the errors and have done more searching online, and I think that the standard libraries are not being found. I don't understand how they are not being found because I have specified paths in my makefile. If anyone could take a look at them and let me know whether there's a problem, I would be very grateful!

First I did:
module load gcc/4.7.2


This is part of the makefile:
CC = gcc
DEFINES = -DIPMGEMPLUGIN -DNOPARTICLEARRAY -D__unix
CFLAGS = -c -g -O2 -pedantic -fno-nonansi-builtins -D__unix
CXXFLAGS = -pipe -O2 -Wall -W -fPIC $(DEFINES) -lstdc++ -m64
INCPATH = -I../GEMS3K -I../GEMS3K -I../GEMS3K -I. \
-I/mounts/apps/gcc/4.7.2/ \
-I/mounts/apps/gcc/4.7.2/bin/ \
-I/mounts/apps/gcc/4.7.2/bin/x86_64-unknown-linux-gnu/4.7.2 \
-I/mounts/apps/gcc/4.7.2/lib64 \
-I/mounts/apps/4.7.2/bin/include \
-I/mounts/apps/gcc/4.7.2/bin/include/c++ \
-I/mounts/apps/gcc/4.7.2/bin/include/c++/4.7.2 \
http://stackoverflow.com/questions/2481269/how-to-make-simple-c-makefile
CXXFLAGS are compilation flags, so -lstdc++ would be ignored.
You should put it in the linking stage
Topic archived. No new replies allowed.