473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

linking problem ...

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::ostream& operator<< (std::ostream& os, std::vector<T>& v);

#endif
/************************************************** ***********************
* trivial.cpp
************************************************** ***********************/
#include <trivial.hpp>

template <class T>
std::ostream& operator<< (std::ostream& os, std::vector<T>& v) {
os << "<";
for (unsigned int i=0; i<v.size(); i++)
os << (i ? ", " : "") << v[i];
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
Jul 22 '05 #1
4 1347
On 3 Dec 2003 02:56:50 -0800, mu*****@yahoo.com (oguz mut) wrote:
I have a linking problem while living in the following configuration:
Not a linking problem, a compile problem
/************************************************** ***********************
* trivial.hpp
************************************************** ***********************/
#ifndef __TRIVIAL__
#define __TRIVIAL__
#include<iostream> // this might help#include<vector>

template <class T>
std::ostream& operator<< (std::ostream& os, std::vector<T>& v);

#endif
/************************************************** ***********************


Cheers!

Jul 22 '05 #2
oguz mut wrote in news:4a**************************@posting.google.c om:

I work with the following 3 files
(trivial.hpp, trivial.cpp, trivialMain.cpp):


Since you dont use export (you compiler doesn't support it) you need
to put you template defenition's in the header file.

That is put the contents of trivial.cpp in trivial.hpp.

The declaration that is currently in trivial.hpp can be removed, as
a definition is also a declaration.

Assuming you don't have any non-template code in trivial.cpp remove it
from your build / make or stop typing it on your g++ command line.

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3
mu*****@yahoo.com (oguz mut) writes:
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__


This is illegal - identifiers containing two consecutive underscores or
starting with an underscore followed by an uppercase letter are reserved
to the implementation.
Apart from that, Rob answered your question nicely.

kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 22 '05 #4
"Frank Schmitt" <in*****@see-signature.info> wrote in message
news:4c************@scxw21.4sc...
[SNIP]
#ifndef __TRIVIAL__
#define __TRIVIAL__


This is illegal - identifiers containing two consecutive underscores or
starting with an underscore followed by an uppercase letter are reserved
to the implementation.

[SNIP]

This is most probably knitpicking but I wouldn't go so far to say that it is
illegal. According to the standard (17.4.3.1.2) names containing two
consecutive underscores are reserved for the implementation which does not
imply that their use is illegal but their use is of course strongly
discouraged.

Chris
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Wolfgang | last post by:
I have a problem with linking my CPP Code under a irix6 machine (sgi, UNIX). In my CPP code I use some Functions which are written in Python. So its a kind of CPP wrapper for my Python functions In...
0
by: Dibyendu Roy | last post by:
Hi All, I build an object called "dblorcle" to connect to oracle database in Sun solaris box. This is built linking with various oracle ".a" (archived, for static linking) files come with standard...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
2
by: sunil | last post by:
Hi, We have lot of c and fortran archive libraries that have complex dependencies. We have different server tasks that use some of these libraries. We have developed a tool inhouse that links...
20
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external...
0
by: gasturbtec | last post by:
please help im new at access programming and i just got this project dropped in my lap because the old programmer quit. i've been doing ok so far but now i need to add code to an existing database...
6
by: Rudy Ray Moore | last post by:
I work with a multi-project workspace. One project (the "startup" project) has a "Configuration Type" of "Application (.exe)". The other 40 projects have a "Configuration Type" of "Static Library...
0
by: Rudy Ray Moore | last post by:
I've been having trouble getting incremental linking to work under Visual C++ .net 2003 7.1 for my multi-project workspace. Ronald Laeremans and Carl Daniel (and a few others) helped me figure it...
0
by: Philip Lowman | last post by:
I am in the process of trying to migrate a couple of build solutions to Visual Studio Express 2005 from VS 2003 Professional and I am running into a weird C/C++ runtime library linking issue when...
1
by: srikar | last post by:
what is the difference between static linking & dynamic linking, what are the advantages of each? How to perform static linking & Dynamic linking by using gcc -o liniking will be done , but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.