静态库重复链接导致的LNK4006警告怎么解决?

Herro 2005-01-10 07:53:50

结构是这样的

a调x,y库,而 x,y 库都调了z库

----x<---
| |
a<- z
| |
----y<---

这样导致x,y库都包含了z库,编译a库就等于输入了2次z库,出现LNK4006警告:xxx已经在xxx中定义,忽略第二个定义。

虽然大致知道原理,但。。。请问这种问题怎么解决?

谢谢各位。
...全文
607 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Herro 2005-01-11
  • 打赏
  • 举报
回复
运行一切正常
oyljerry 2005-01-11
  • 打赏
  • 举报
回复
既然是个warning,先运行一下,看看什么情况
Herro 2005-01-11
  • 打赏
  • 举报
回复
试过了,加#pragma once没用。。。
xuzheng318 2005-01-11
  • 打赏
  • 举报
回复
#pragma once
Herro 2005-01-11
  • 打赏
  • 举报
回复
msdn已经看过很多遍了

还是无法解决。。。。。
kingzai 2005-01-10
  • 打赏
  • 举报
回复
symbol already defined in object; second definition ignored

The given symbol, displayed in its decorated form, was multiply defined. When this warning is encountered, symbol will be added twice, but only its first form will be used
Tips

The given symbol may be a packaged function, created by compiling with /Gy. This symbol was included in more than one file but was changed between compilations. Recompile all files that include the symbol.


The given symbol may have been defined differently in two member objects in different libraries.


An absolute may have been defined twice, with a different value in each definition.


If the error message is received when combining libraries, symbol already exists in the library being added to.
If you are rebuilding the C run-time library, you can ignore this message.


Herro 2005-01-10
  • 打赏
  • 举报
回复
头文件的那些东西我有写,没用... 因为这个和头文件无关啊

x.lib(z.obj) : warning LNK4006: "public: void __thiscall z::Init(void)" 已在 z.lib(z.obj) 中定义;已忽略第二个定义

gomi 2005-01-10
  • 打赏
  • 举报
回复
可以不用解决,不影响什么。
不过这种情况出现,显然代码有需要优化的地方。
检查一下为什么那个函数或全局变量会在多个地方定义。
oyljerry 2005-01-10
  • 打赏
  • 举报
回复
恩,用头文件避免重复包含
或#pragma once
RockHwnd 2005-01-10
  • 打赏
  • 举报
回复
100分的这种问题竟然没有人来回答,难道另有玄机...:-S
RockHwnd 2005-01-10
  • 打赏
  • 举报
回复
在Z.h中定义
#if !defined(Z_H)
#define Z_H
//Z.h的内容
#endif
就可以避免重复include了

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧