O
oguz mut
hi,
I have a linking problem while living in the following configuration:
. windows 2000
. cygwin
. g++ (GCC) 3.3.1 (cygming special)
I work with the following 3 files
(trivial.hpp, trivial.cpp, trivialMain.cpp):
/*************************************************************************
* trivial.hpp
*************************************************************************/
#ifndef __TRIVIAL__
#define __TRIVIAL__
#include<vector>
template <class T>
std:stream& operator<< (std:stream& os, std::vector<T>& v);
#endif
/*************************************************************************
* trivial.cpp
*************************************************************************/
#include <trivial.hpp>
template <class T>
std:stream& operator<< (std:stream& os, std::vector<T>& v) {
os << "<";
for (unsigned int i=0; i<v.size(); i++)
os << (i ? ", " : "") << v;
os << ">";
return os;
}
// #include "trivialMain.cpp"
/*************************************************************************
* trivialMain.cpp
*************************************************************************/
#include<iostream>
#include<vector>
#include<trivial.hpp>
int main (void) {
std::vector<int> v(3);
v[0] = 1;
v[1] = 2;
v[2] = 3;
std::cout << v << std::endl;
return 0;
}
/************************************************************************/
under these conditions, I do the followings:
bash-2.05b$ g++ -Wall -I. trivial.cpp -c
bash-2.05b$ g++ -Wall -I. trivialMain.cpp trivial.o
I expect the linker to link. however I get:
/cygdrive/c/DOCUME~1/OMUT~1.INT/LOCALS~1/Temp/cc3PPHw8.o(.text+0xc8):trivialMain
..cpp: undefined reference to `std::basic_ostream<char, std::char_traits<char> >&
operator<< <int>(std::basic_ostream<char, std::char_traits<char> >&, std::vecto
r<int, std::allocator<int> >&)'
but, when I uncomment the last line in trivial.cpp and compile
as follows I do not get any error!
bash-2.05b$ g++ -Wall -I. trivial.cpp
what is the problem;
have I coded something wrong, or have I misused g++ ?
thanks in advance!
oguz mut
I have a linking problem while living in the following configuration:
. windows 2000
. cygwin
. g++ (GCC) 3.3.1 (cygming special)
I work with the following 3 files
(trivial.hpp, trivial.cpp, trivialMain.cpp):
/*************************************************************************
* trivial.hpp
*************************************************************************/
#ifndef __TRIVIAL__
#define __TRIVIAL__
#include<vector>
template <class T>
std:stream& operator<< (std:stream& os, std::vector<T>& v);
#endif
/*************************************************************************
* trivial.cpp
*************************************************************************/
#include <trivial.hpp>
template <class T>
std:stream& operator<< (std:stream& os, std::vector<T>& v) {
os << "<";
for (unsigned int i=0; i<v.size(); i++)
os << (i ? ", " : "") << v;
os << ">";
return os;
}
// #include "trivialMain.cpp"
/*************************************************************************
* trivialMain.cpp
*************************************************************************/
#include<iostream>
#include<vector>
#include<trivial.hpp>
int main (void) {
std::vector<int> v(3);
v[0] = 1;
v[1] = 2;
v[2] = 3;
std::cout << v << std::endl;
return 0;
}
/************************************************************************/
under these conditions, I do the followings:
bash-2.05b$ g++ -Wall -I. trivial.cpp -c
bash-2.05b$ g++ -Wall -I. trivialMain.cpp trivial.o
I expect the linker to link. however I get:
/cygdrive/c/DOCUME~1/OMUT~1.INT/LOCALS~1/Temp/cc3PPHw8.o(.text+0xc8):trivialMain
..cpp: undefined reference to `std::basic_ostream<char, std::char_traits<char> >&
operator<< <int>(std::basic_ostream<char, std::char_traits<char> >&, std::vecto
r<int, std::allocator<int> >&)'
but, when I uncomment the last line in trivial.cpp and compile
as follows I do not get any error!
bash-2.05b$ g++ -Wall -I. trivial.cpp
what is the problem;
have I coded something wrong, or have I misused g++ ?
thanks in advance!
oguz mut