C++ Static Lib 链接问题
时间:2010-07-22
来源:互联网
Static Lib 里面的代码:
MsgDefs.h:
复制代码
Version1.cpp:
复制代码
Version2.cpp:
复制代码
主程序代码:
复制代码
问题: 注释掉fake_link_var那两行,输出结果为1. 启用任意一行代码后,结果为2. 求达人赐教更好的解决方案.
MsgDefs.h:
- #pragma once
-
- #include <map>
- #include <string>
-
- typedef std::pair<std::string, int> MsgDefKey;
- typedef std::map<MsgDefKey, std::string> MsgDefs;
- extern MsgDefs gHSVFMsgDefs;
- extern int fake_link_var;
- int fake_link_func();
-
- #define MSG_DEF(version, msg_id, msg) \
- namespace version##_##msg_id##_def \
- { \
- MsgDefs::key_type key(#version, msg_id); \
- struct DefsAppender \
- { \
- DefsAppender() \
- { \
- gHSVFMsgDefs.insert(MsgDefs::value_type(key, msg)); \
- } \
- } defs_appender; \
- }
- #include "stdafx.h"
- #include "MsgDefs.h"
- #include <string>
-
- using namespace std;
-
- MsgDefs gHSVFMsgDefs;
- const std::string V1_1 = "A1";
- MSG_DEF(V1, 1, V1_1)
- #include "stdafx.h"
- #include "MsgDefs.h"
- #include <string>
-
- using namespace std;
- int fake_link_var = 0;
- int fake_link_func()
- {
- return 0;
- }
-
- const std::string V2_1 = "B1";
- MSG_DEF(V2, 1, V2_1)
- // LinkTest.cpp : Defines the entry point for the console application.
- //
-
- #include "stdafx.h"
- #include "MsgDefs.h"
- #include <iostream>
-
- int _tmain(int argc, _TCHAR* argv[])
- {
- //fake_link_var();
- //fake_link_var++;
- std::cout << gHSVFMsgDefs.size() << std::endl;
- return 0;
- }
作者: srdgame 发布时间: 2010-07-22
如果代码都是放在主程序中的话就没有任何问题(输出结果为2)
作者: srdgame 发布时间: 2010-07-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28