Library Problem

M

Michael

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\Debug\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\BuildLog.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\BuildLog.htm"

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



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

Build: 3 succeeded, 1 failed, 0 skipped
 
V

Victor Bazarov

Michael said:
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
 
J

John Harrison

Michael said:
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
 
M

Michiel Salters

Victor Bazarov said:
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
 
T

Thomas Matthews

Michiel said:
Victor Bazarov said:
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
 
R

Ron Samuel Klatchko

Michael said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top