473,856 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.cp p"
/*************** *************** *************** *************** *************
* trivialMain.cpp
*************** *************** *************** *************** *************/
#include<iostre am>
#include<vector >

#include<trivia l.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(.tex t+0xc8):trivial Main
..cpp: undefined reference to `std::basic_ost ream<char, std::char_trait s<char> >&
operator<< <int>(std::basi c_ostream<char, std::char_trait s<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 1362
On 3 Dec 2003 02:56:50 -0800, mu*****@yahoo.c om (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<iostre am> // this might help#include<vecto r>

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.goo gle.com:

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.c om (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
1733
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 my Python Code I use threads to communicate over the network and stuff like this. Compilation and linking are working very well under Windows and Linux with the same code. Under the sgi, UNIX machine some errors occur and I don't no why....
0
2368
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 oracle library. I use the following command while linking: ld -L(oracle lib path) -lnetv2 -lnttcp -lnetwork -lncr -lnetv2 -lnttcp -lnetwork -lclient -lcommon -lgeneric -lmm -lnlsrtl3 -lcore4 For each element starting with -l has...
7
5131
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 normal functions in header files results in multiple definition errors even when include guards are used. -- STH Hatton's Law: "There is only One inviolable Law" KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com Mozilla:...
2
1704
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 server tasks by continuously iterating until it figures out the correct library order. Recently we introduced some C++ legacy libraries. I am completely new to C++ linking. Is there some tutorial that can explain the nuances of C++ linking? We do...
20
3248
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 references to functions and objects not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment." What I'm wondering is what exactly...
0
2251
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 that is used to connect to other databases and generate reports. below is sample code of how the database does the linking i hope i give you enough info to help me but if not let me know and i will give more. Sub txtShipDataFileSub() Dim...
6
6590
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 (.lib)". My question: Should the linker incrementally link when I make a change to one of the ..cpps in one of my .lib projects? For VC6 the answer is yes.
0
1678
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 out. Short answer: I should never have expected incremental linking to work. Short answer addendum: Linking is slower in 7.1/.net/2003 than VC++6. ===
0
2560
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 using the /MT compilation option. Our debug solution's /MTd flag works fine and using /MD also seems to work ok. For some reason I can't fathom, when I use /MT, linking the static excutable completely dies (problems resolving symbols in the STL,...
1
5965
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 how can we control the type of linking Hi any one please help me to clarify my doubt
0
9916
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9762
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10782
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10384
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9531
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7094
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5761
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3201
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.