By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Library Problem

P: n/a
I'm trying to compile on VC++ and am having a linking error.

I basically have a library for all my maths functions: 3DMaths.lib, and a
library for my for my engine and also my game, but get the following
problems:

I try and include tnt/tnt.h and tnt/jama/jama.h inside 2 cpp's in my 3DMaths
library, but get the following erros:

What Am I doing wrong, As it undertand the error messages, the librarys
defines a function in the first include, but then tries to do it again??

Surely it should have guard headers to prevent this?

Thanks

Mike

------ Build started: Project: 3DMaths, Configuration: Debug Win32 ------

Compiling...

MPlane3D.cpp

Creating library...

BoundingBox3D.obj : warning LNK4006: "public: __thiscall
TNT::Stopwatch::Stopwatch(void)" (??0Stopwatch@TNT@@QAE@XZ) already defined
in MPlane3D.obj; second definition ignored

Build Time 0:00

Build log was saved at "file://c:\Documents and
Settings\Michael\Desktop\Ixium3D\Engine\3DMaths\De bug\BuildLog.htm"

3DMaths - 0 error(s), 1 warning(s)

------ Build started: Project: resReaderASE, Configuration: Debug
Win32 ------

resReaderASE - up-to-date.

Build Time 0:00

------ Build started: Project: Engine, Configuration: Debug Win32 ------

Creating library...

Replacing .\Debug\stdafx.obj

3DMaths.lib(MPlane3D.obj) : warning LNK4006: "public: __thiscall
TNT::Stopwatch::Stopwatch(void)" (??0Stopwatch@TNT@@QAE@XZ) already defined
in 3DMaths.lib(BoundingBox3D.obj); second definition ignored

Build Time 0:00

Build log was saved at "file://c:\Documents and
Settings\Michael\Desktop\Ixium3D\Engine\Debug\Buil dLog.htm"

Engine - 0 error(s), 1 warning(s)

------ Build started: Project: Game3D, Configuration: Debug Win32 ------

Linking...

Engine.lib(BoundingBox3D.obj) : error LNK2005: "public: __thiscall
TNT::Stopwatch::Stopwatch(void)" (??0Stopwatch@TNT@@QAE@XZ) already defined
in Engine.lib(MPlane3D.obj)

Debug/Game3D.exe : fatal error LNK1169: one or more multiply defined symbols
found

Build Time 0:00

Build log was saved at "file://c:\Documents and
Settings\Michael\Desktop\Ixium3D\Game3D\Debug\Buil dLog.htm"

Game3D - 2 error(s), 0 warning(s)

---------------------- Done ----------------------

Build: 3 succeeded, 1 failed, 0 skipped
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Michael wrote:
I'm trying to compile on VC++ and am having a linking error.


Linking is compiler-specific and not part of the language. You should
post to a VC++ newsgroup: microsoft.public.vc.language.

V
Jul 22 '05 #2

P: n/a

"Michael" <sl***********@hotmail.com> wrote in message
news:c8*********@sparta.btinternet.com...
I'm trying to compile on VC++ and am having a linking error.

I basically have a library for all my maths functions: 3DMaths.lib, and a
library for my for my engine and also my game, but get the following
problems:

I try and include tnt/tnt.h and tnt/jama/jama.h inside 2 cpp's in my 3DMaths library, but get the following erros:

What Am I doing wrong, As it undertand the error messages, the librarys
defines a function in the first include, but then tries to do it again??

Surely it should have guard headers to prevent this?

Thanks


No its got nothing at all to do with include guards. Include guards prevent
a header file from being included twice in the same source file, they do not
and cannot prevent the header file being included twice in different source
files.

The trick is not to put anything into a header file that will cause problems
if it is included in two different source files.

john
Jul 22 '05 #3

P: n/a
Victor Bazarov <v.********@comAcast.net> wrote in message news:<9X****************@dfw-read.news.verio.net>...
Michael wrote:
I'm trying to compile on VC++ and am having a linking error.


Linking is compiler-specific and not part of the language. You should
post to a VC++ newsgroup: microsoft.public.vc.language.


Linkers perform steps 8 and 9 of [lex.phases] 2.1 Phases of translation.
That is on-topic here; there is no charter which limits this group to
steps 1-7. By the very same logic, the preprocessor also is not part of
the language. Do you really want to discuss only 7 of 9? (Pun intended)

Practically, ODR violations are definitely on topic yet they're usually
detected by the linker. This also sounds like such an error.

Regards,
Michiel Salters
Jul 22 '05 #4

P: n/a
Michiel Salters wrote:
Victor Bazarov <v.********@comAcast.net> wrote in message news:<9X****************@dfw-read.news.verio.net>...
Michael wrote:
I'm trying to compile on VC++ and am having a linking error.


Linking is compiler-specific and not part of the language. You should
post to a VC++ newsgroup: microsoft.public.vc.language.

Linkers perform steps 8 and 9 of [lex.phases] 2.1 Phases of translation.
That is on-topic here; there is no charter which limits this group to
steps 1-7. By the very same logic, the preprocessor also is not part of
the language. Do you really want to discuss only 7 of 9? (Pun intended)

Practically, ODR violations are definitely on topic yet they're usually
detected by the linker. This also sounds like such an error.

Regards,
Michiel Salters


But the point is that each linker may perform the process
differently. Each may have different command line arguments.
Some implementations may not have a separate linker.

The generic talking of linking is tolerated in this group.
However, the specific details of how to use one implementation
to link, is not. For example, I would not bother you with
listing how to link the OP's program using the ARM compiler,
the Metaware compiler, the Greenhills, GNU or Sun compilers.
All of which are compilers that have separate linking steps.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #5

P: n/a
"Michael" <sl***********@hotmail.com> wrote in message news:<c8*********@sparta.btinternet.com>...
What Am I doing wrong, As it undertand the error messages, the librarys
defines a function in the first include, but then tries to do it again??

Surely it should have guard headers to prevent this?

------ Build started: Project: 3DMaths, Configuration: Debug Win32 ------

Compiling...

MPlane3D.cpp

Creating library...

BoundingBox3D.obj : warning LNK4006: "public: __thiscall
TNT::Stopwatch::Stopwatch(void)" (??0Stopwatch@TNT@@QAE@XZ) already defined
in MPlane3D.obj; second definition ignored


The issue is that the function definition for TNT::Stopwatch::Stopwatch()
is included in two separate translation units and is not declared as
inline.

Guard headers do not fix this because guard headers only work within in
single translation unit not across multiple ones.

Without knowing exactly how you use your #include statements and exactly
source is in each file, it is impossible to know what your exact mistake
is.

To troubleshoot this, the first thing I would look for is the definition
of TNT::Stopwatch::Stopwatch(). If it is in a header file, make sure
it is declared as inline, either implicitly by being in the class
definition or explicitly by having the inline specifier. If it isn't in
a header file, make sure that the file is not getting included by other
files.

samuel
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.