Advertisement

Disabling linker warnings.

Started by July 08, 2001 08:40 PM
6 comments, last by gimp 23 years, 7 months ago
I need to disable linker warning 4006. This warning is for multiply defined symbols in different lib''s I have. I have them because I use a base ''common'' library in many modules. For example I use things like string manipulation, parsing, file ops etc, they are in the common.lib that is used by many other libraries. The problem occurs when I use multiple libs that all inclue common.lib For me this problem is *BAD*, I''m currently getting around 1000 warnings, it''s now at a point where I ignore all my warning output as it''s too hard finding real warnings. I''ve just turned on ''Warning''s as errors'' as a hack fix but this problem also stops me seeing compile time asserts etc as well. I REALLY wan''t to learn how to turn off certain linker warnings, like pragma''s turn of compiler warnings(mostly). All ideas appreciated... Many thanks Chris Brodie http:\\fourth.flipcode.com
Chris Brodie
Hi,
The idea is not to disable warning but to solve the problem of the redefinition. If you have a header with the functions forward declared there, then maybe you should add the extern keyword.
-- Gilad
Advertisement
Solve the problem... The problem is that I have libs included in lib''s included in libs. Somewhere along the linking journey there comes a point where one of the based libs gets included by to child libs and I get conflicts.

These are all classes, what do you mean about using extern with forward declaration?

Chris Brodie
http:\\fourth.flipcode.com
Chris Brodie
If they are all classes then you should do the following:
in the header of the class in the begining write:
#ifndef classname_h // or any thing like this that will distinguish classes
#define classname_h
and at the end of the class write
#endif
and if this doesn''t help you can always use in your header file
#pragma once
If you really want to disable them (may be MSVC specific) rather than fix the interdependencies, you do:

#pragma warning(disable:4006)


You can push and pop the current state of the warning disable/enable status too so that you can disable the warning only in places where you know its extraneous:

#pragma warning(push)
#pragma warning(disable:4006)
.. Do some code which creates warning you don''t want
#pragma warning(pop)


Also:

#pragma warning(once:4006)
Displays the warning, but only displays it once (rather than 1000 times)

#pragma warning(default:4006)
Sets the default behaviour for that warning.

There are other things (look in the documentation!!) - such as changing the error level of a particular warning etc

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

One thing you might try is to make all of your data structures static.
There are 10 kinds of people in the world: those who get binary, and those who don't...
Advertisement
None of these answers have worked so far... Remember that these are linker warnings not compiler warnings. I looked up the linker doco and couldn''t find anything on warning disabling. msdn.micro* says nothing. MSDN CD says nothing...

I can''t imagine that others have never had this problem....

Chris Brodie
http:\\fourth.flipcode.com
Chris Brodie
If you have variables or class definitions (not declarations) in the header files for your common.lib, you will get this warning. Put the definitions in a .cpp file.

If you absolutely must have the definition in the header file (like when using const variables instead of #define), use something like

#ifdef common_lib
const int myVar = 5;
#else
extern const int myVar
#endif

This will only define the variable in common.lib, and in all the others, it will declare it.



Mark Fassett
Laughing Dragon Entertainment
http://www.laughing-dragon.com

Mark Fassett

Laughing Dragon Games

http://www.laughing-dragon.com

This topic is closed to new replies.

Advertisement