473,766 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Really bizarre linking error!

Hello! I have the world's strangest linking error, and I'm hoping that
someone can help me sort it out. I recently installed and compiled a
library called LinBox without a problem. I have an object-oriented
software application, and I want it to call the library. When I add
the following 3 lines (copied directly from the library tutorial),

#include <linbox/field/modular.h>
using namespace LinBox;
typedef Modular<shortFi eld;

to a .cpp file, my code compiles perfectly. However, when I add the
same 3 lines to a .h file (where they *must* ultimately go), I get
(among others) the following error:

/tmp/cckvjpY5.o: In function `~edge':/usr/include/gmp.h:1590: multiple
definition of
`LinBox::Modula rBase<Integer>: :write(std::bas ic_ostream<char ,
std::char_trait s<char&) const'

Comments? This is incredibly strange to me. It looks like some sort of
linking error. Namespace conflict? I don't have root access on the
school machines, and so I have compiled and am pointing to a local
copy of the LinBox library. This is so strange... why does the code
work from
the .cpp file but not the .h file?

I hope this is an error in my code and not in the library itself.
Thoughts and suggestions on how to track this down would be carefully
considered and gratefully appreciated!

Very best regards,
Susan

PSHere is a copy of my very simple make file:

grob_heur: gc_heur.cpp Graph.cpp MonExpEnum.cpp SetCombEnum.cpp
GraphLinearSyst e
m.cpp
g++ -Wall -g \
-I/LINBOX_PATH/linbox-1.1.3/include \
-I/usr/include \
-o gc_heur gc_heur.cpp \
Graph.cpp MonExpEnum.cpp SetCombEnum.cpp GraphLinearSyst em.cpp
\
/LINBOX_PATH/linbox-1.1.3/linbox/util/gmp++/.libs/libgmpxx.a \
/usr/lib/libgmp.a \
/LINBOX_PATH/linbox-1.1.3/lib/liblinbox.a

Aug 5 '07 #1
7 1858
Because you have managed to include the header file in the same cpp file
twice, or you have included the header file in the cpp file where you
manually placed the typedef.
Yes, certainly that is the obvious first guess. Unfortuneatly, all of
my header files do have the traditional guards

#ifndef MY_HEADER
#define MY_HEADER

Also, all of the library files have the traditional guards as
expected. Also, as Arun suggested, I am not double declaring the
typedef, although I certainly double checked just to be sure, because
that is another obvious error.
It looks like you're including the header in (at least) two different
source files (not surprising -- that's the usual reason for putting
something into a header). From the looks of things, in modular.h, you
have a _definition_ (not just a declaration) of a function named
'write' that's part of your ModularBase class. That would be all right
IF it was an inline function, but it's apparently not.
I find this comment very interesting. Here is the function itself, as
declared within the library header file (which has guards).

template <>
std::ostream& ModularBase<Int eger>::write (std::ostream &os)
const
{ return os << "GMP integers mod " << _modulus; }

Obviously, if I comment out this function within the library header
file, the code compiles fine, but of course that is not the right
solution AT ALL. Does this function declaration look okay? I think
this is a function definition, not a declaration. Isn't it also
inline? A shouldn't the guards around the header file in the library
prevent any double declaration?

Thanks for your comments!

Susan

Aug 5 '07 #2
ba*******@hotma il.com wrote:

Please don't snip attributions, it is considered rude.
>It looks like you're including the header in (at least) two different
source files (not surprising -- that's the usual reason for putting
something into a header). From the looks of things, in modular.h, you
have a _definition_ (not just a declaration) of a function named
'write' that's part of your ModularBase class. That would be all right
IF it was an inline function, but it's apparently not.

I find this comment very interesting. Here is the function itself, as
declared within the library header file (which has guards).

template <>
std::ostream& ModularBase<Int eger>::write (std::ostream &os)
const
{ return os << "GMP integers mod " << _modulus; }

Obviously, if I comment out this function within the library header
file, the code compiles fine, but of course that is not the right
solution AT ALL. Does this function declaration look okay? I think
this is a function definition, not a declaration.
It is.
Isn't it also inline?
No, only class member functions defined inline have inline linkage, not
normal functions.

Your original linker error shows that this function is not declared as
inline and is should be.
A shouldn't the guards around the header file in the library
prevent any double declaration?
They can't.

--
Ian Collins.
Aug 5 '07 #3
In article <11************ **********@x40g 2000prg.googleg roups.com>,
ba*******@hotma il.com says...

[ ... ]
It looks like you're including the header in (at least) two different
source files (not surprising -- that's the usual reason for putting
something into a header). From the looks of things, in modular.h, you
have a _definition_ (not just a declaration) of a function named
'write' that's part of your ModularBase class. That would be all right
IF it was an inline function, but it's apparently not.

I find this comment very interesting. Here is the function itself, as
declared within the library header file (which has guards).

template <>
std::ostream& ModularBase<Int eger>::write (std::ostream &os)
const
{ return os << "GMP integers mod " << _modulus; }
No -- to be inline, it has to either be written inside of the class
definition, or else explicitly defined as 'inline'. You haven't shown us
the remainder of the class definition to be absolutely certain, but
qualifying the name (i.e. using "ModularBase<In teger>::write" instead of
just "write") suggests that this function is being defined outside of
the class definition.
Obviously, if I comment out this function within the library header
file, the code compiles fine, but of course that is not the right
solution AT ALL. Does this function declaration look okay? I think
this is a function definition, not a declaration. Isn't it also
inline? A shouldn't the guards around the header file in the library
prevent any double declaration?
No -- they prevent it from being declared twice in the same translation
unit (pre-processed source file). It still attempts to define the
function once in each source file where you include the header -- but
unless it's inline, you can only define it once across all the source
files that make up the complete program.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Aug 6 '07 #4
Making the function inline did the trick!!!! Thank you so much. I will
let the people who put out the library know about the error.

Thanks again for your help and comments!

Best,
Susan

Aug 6 '07 #5
On Sun, 05 Aug 2007 18:58:19 -0000, "ar********@gma il.com"
<ar********@gma il.comwrote in comp.lang.c++:

Why are you top posting? Did you not read the signature block in
Alf's post that explains why it is wrong?
Yup this is a multiple decleration problem and is completly to do with
ur program and nothing to do with the library.
Why do you refer to ur's program, when the original poster's name was
"arun.darra ", and the post you replied to was from "Alf P. Steinbach"?
Did you reply to the wrong post by mistake? Actually, since you seem
to be implying that Alf's code is incorrect, even though he is not the
one who posted it, you are replying to the wrong post.
there are 2 reasons for this:

1. because ur programs .h files dont have header guards
and the same header is being included multiple times.
use heade guards in ur header file, some thing like:

# ifndef _FILE_
# define _FILE_
This, of course, is completely wrong because it violates a namespace
reserved for the implementation. All identifiers beginning with an
underscore followed by an upper case letter, and all identifiers
containing two consecutive underscores anywhere within them, are
reserved in all contexts.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Aug 6 '07 #6
This, of course, is completely wrong because it violates a namespace
reserved for the implementation. All identifiers beginning with an
underscore followed by an upper case letter, and all identifiers
containing two consecutive underscores anywhere within them, are
reserved in all contexts.
Well thanks for the info Jack but the idea was show the usage of
header guards... But the point u put across was well taken.. thanks.
Aug 11 '07 #7
On 5 Aug., 18:47, bajich...@hotma il.com wrote:
Hello! I have the world's strangest linking error, and I'm hoping that
someone can help me sort it out. I recently installed and compiled a
library called LinBox without a problem. I have an object-oriented
software application, and I want it to call the library. When I add
the following 3 lines (copied directly from the library tutorial),

#include <linbox/field/modular.h>
using namespace LinBox;
typedef Modular<shortFi eld;

to a .cpp file, my code compiles perfectly. However, when I add the
same 3 lines to a .h file (where they *must* ultimately go), I get
(among others) the following error:

/tmp/cckvjpY5.o: In function `~edge':/usr/include/gmp.h:1590: multiple
definition of
`LinBox::Modula rBase<Integer>: :write(std::bas ic_ostream<char ,
std::char_trait s<char&) const'
Hi,
I've got the same linking error not using "inline". See

http://www.xatlantis.ch/cpp_blog/compiler.html

wbr

bhadorn

Aug 12 '07 #8

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

Similar topics

4
2170
by: Alan Little | last post by:
This is very bizarre. Could someone else have a look at this? Maybe you can see something I'm overlooking. Go here: http://www.newsletters.forbes.com/enews/admin/deliver.php4 U: bugtest P: test Enter 1 for "How many files in this delivery?" and select a file to upload, in one of the listed formats. Scroll down and click "Test Email".
0
1723
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....
7
5122
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:...
3
14547
by: Saurabh Aggrawal | last post by:
Hi, I am porting an application for 64-bit AMD processor and while linking the application i am getting the following errors: Processing directory uidll... Linking DLL G:\NewUIPackers1\drivers\Unser\bin\WIN32\DEBUG\PPKAW1UI.dll .... LINK : warning LNK4224: /PDBTYPE is no longer supported; ignored UIDLL.def : error LNK2001: unresolved external symbol DllCanUnloadNow
7
6553
by: wmkew | last post by:
Hello everyone I'm encountering a R6002 Runtime error and several bugs when trying to generate a simple Managed C++ application with .NET 2003. The main problem seems to arise from linking with LIBCMT(D).DLL. (My requirement is that we can't link with MSVCRT(D).LIB.) Below are steps I've followed, and the resulting problems 1. Using the New Project wizard, generate a Visual C++ .NET Class Library project (call it "Doomed") and a VC++...
4
6412
by: Sanjay Kumar | last post by:
Folks ! I am working with VC++ after a long time and having problem linking latest xerces 2.7 in VC++ 2005 Express Edition. I have done following: 1. downloaded and unpacked the the library: http://www.apache.org/dist/xml/xerces-c/binaries/xerces-c_2_7_0-windows_2000-msvc_60.zip
0
2557
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,...
0
3982
by: xieml2007 | last post by:
Dear Madam or Sir, I encountered one problem which is quite similiar to the discussions launched at the web site: http://www.thescripts.com/forum/thread280324.html
0
2970
by: dotyet | last post by:
Hi Everyone, I am trying to build a DB2 UDB UDF which can perform regex over the table data. The user defined function will call an external .dll file to do the task. I am referring to the following link for doing so: http://www.ibm.com/developerworks/db2/library/techarticle/0301stolze/0301stolze.html While linking the below mentioned code, I am facing some errors. I have installed PCRE and am using Visual C++ 6.0 in 32-bit mode. The
0
9571
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...
1
9959
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
9838
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...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
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
5279
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...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
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.