未解决的外部噩梦 [英] Unresolved Externals Nightmare

查看:145
本文介绍了未解决的外部噩梦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,行业资深人士,



我是大学的初级学生,开始我的第一次夏令营实习,我在我的头。我工作的公司已经从另一家公司购买了一个巨大的应用程序,该公司自90年代初以来一直在不断扩展和修改它。该解决方案包含超过200,000行代码,分布在300多个文件中。整个解决方案据称已写入ANSI-C ++标准。代码几乎完全没有文档,它的大部分看起来像象形文字给我。最终,我的工作是将此代码移植到嵌入式Linux。目前,我的工作是简单地使用Visual Studio 2008在Windows XP上编译。



今天,我遇到链接器错误,如下面这个: / p>


libcmtd.lib(sprintf.obj):error LNK2005:_sprintf已在msvcrtd.lib(MSVCR90D.dll)中定义



我的理解是,当解决方案中的不同项目使用不同的运行时库。在我的解决方案有6个项目。其中4个设置为使用多线程调试DLL运行时库(/ MDd)进行编译,其中一个设置为使用多线程调试库(/ MTd)进行编译,其中一个设置为使用多线程dll运行时库(/ MD)。我收到这个错误消息后,我尝试的第一件事是更改/ MTd和/ MD切换到/ MDd,以便一切都将使用相同的运行时库编译。不幸的是,这导致afx.h中的以下错误:




致命错误C1189:#error: MD [d](CRT dll版本)要求MFC共享dll版本。请#define _AFXDLL或不使用/ MD [d]



经过一番挖掘,我发现它已经告诉我我需要做什么。我继续并改变了使用MFC选项在项目属性 - >配置属性 - >常规在共享DLL中使用MFC。在这一点上,我开始收到几十个未解决的外部错误,例如:




dataPropertySheet.obj:error LNK2019:unresolved external symbol public:__thiscall CRateizableSheet :: CResizableSheet(unsigned short const *,class CWnd *,unsigned int)(?? 0CResizableSheet @@ QAE @ PBGPAVCWnd @@ I @ Z)引用函数public:__thiscall CdataPropertySheet :: CdataPropertySheet (ResizablePage.obj)中,我们可以使用一个简单的const *,class CWnd *,unsigned int)(?? 0CdataPropertySheet @@ QAE @ PBGPAVCWnd @@ I @ Z)



< :error LNK2001:未解析的外部符号public:virtual int __thiscall CWnd :: Create(char const *,char const *,unsigned long,struct tagRECT const&,class CWnd *,unsigned int,struct CCreateContext *) @ CWnd @@ UAEHPBD0KABUtagRECT @@ PAV1 @ IPAUCCreateContext @@@ Z)



在阅读了 LNK2001 LNK2019 ,我意识到我不知道发生了什么。这些不是他们教我们如何在学校处理的问题。我知道我的数据结构,这就是它。



从我的有限的知识,似乎这些模块的各种调试和发布版本都纠结在一个预处理器指令和#include的web。在整个解决方案中,对于环境变量,文件名,宏以及可能的更多,在几乎每个头文件和源文件中都有一些嵌套的#ifdef检查和#define语句。通过对我的编译器设置进行小的更改,我似乎将程序的大部分重定向到具有非常不同的函数定义的不同的库。这是我对发生的事情的模糊概念的理解。



我觉得我需要更好地了解这个代码的工作原理,解决这些编译器错误。为此,我一直尝试逐行浏览许多文件,看看它们在哪里,什么对象和变量在作用域,等等。不幸的是,这不会让我很远,因为每个调用一个外部函数是不明确的,我没有办法通过预处理器的麻烦,知道哪个版本的任何给定的函数应该被调用。



我正在寻找魔术解决方案来绘制程序,并试图使它的意义。我尝试了一个名为 Doxygen 的,但是我不知道如何正确使用它,或者它像预处理器一样混乱,因为我



我的问题是这样:

我的剩余选项是什么?

这里折腾一下:

a。)切换专业

b。)跳下桥梁



这些选择都不会帮助我更好地理解这个代码库,并让它编译。有人有更好的想法吗?类似的经验? Sage智慧分享?



感谢一吨,

-Alex

方案

使用相同的运行时库编译所有内容。结束了故事。


Hello industry veterans,

I am a junior in college embarking on my first summer programming internship, and I am in way over my head. The company I'm working for has purchased a colossal application from another company that has slowly been expanding and modifying it since the early 90's. The solution contains over 200,000 lines of code which are spread across more than 300 files. The entire solution has purportedly been written to ANSI-C++ standards. The code is almost entirely undocumented, and most of it looks like hieroglyphs to me. Ultimately, my job is to port this code to embedded Linux. At the moment, my job is simply to get it compiling using Visual Studio 2008 on Windows XP.

Today, I'm running into linker errors such as this one:

libcmtd.lib(sprintf.obj) : error LNK2005: _sprintf already defined in msvcrtd.lib(MSVCR90D.dll)

My understanding is that this often happens when different projects within a solution are compiled using different runtime libraries. There are 6 projects in my solution. 4 of them were set to compile using the multi-threaded debug DLL runtime library (/MDd), one of them was set to compile using the multi-threaded debug library (/MTd), and one of them was set to compile using the multi-threaded dll runtime library (/MD). The first thing I tried after receiving this error message was to change the /MTd and /MD switches to /MDd so that everything would have compiled with the same runtime libraries. Unfortunately, this led to the following error in afx.h:

fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

After some digging around, I discovered that it had already told me what I needed to do. I went ahead and changed the "Use of MFC" option under Project Properties->Configuration Properties->General to "Use MFC in a Shared DLL". At this point I started receiving dozens of unresolved external errors such as these:

dataPropertySheet.obj : error LNK2019: unresolved external symbol "public: __thiscall CResizableSheet::CResizableSheet(unsigned short const *,class CWnd *,unsigned int)" (??0CResizableSheet@@QAE@PBGPAVCWnd@@I@Z) referenced in function "public: __thiscall CdataPropertySheet::CdataPropertySheet(unsigned short const *,class CWnd *,unsigned int)" (??0CdataPropertySheet@@QAE@PBGPAVCWnd@@I@Z)

ResizableLib.lib(ResizablePage.obj) : error LNK2001: unresolved external symbol "public: virtual int __thiscall CWnd::Create(char const *,char const *,unsigned long,struct tagRECT const &,class CWnd *,unsigned int,struct CCreateContext *)" (?Create@CWnd@@UAEHPBD0KABUtagRECT@@PAV1@IPAUCCreateContext@@@Z)

After reading through the MSDN pages on LNK2001 and LNK2019, I've realized I have no idea what's going on. These are not the sort of issues they've taught us how to deal with in school. I know my data structures, and that's about it. How I ended up where I am now is beyond me!

From my limited knowledge, it seems that the various debug and release versions of these modules are all tangled up in a web of preprocessor directives and #includes. There are a number of nested #ifdef checks and #define statements done in nearly every header and source file throughout the solution for environment variables, file names, macros, and possibly more. By making even small changes to my compiler settings, I seem to be redirecting large parts of the program to different libraries which have very different function definitions. This is my vague conceptual understanding of what's going on.

I feel as though I'm going to need a better understanding of how this code works before I stand any chance of troubleshooting these compiler errors. To that end, I've been trying to step through many of the files line by line to see where they lead, what objects and variables are in scope, and so on. Unfortunately, this doesn't get me very far, because every call to an external function is ambiguous, and I have no way of seeing through the preprocessor mess to know which version of any given function is supposed to be called.

I was looking around for magic solutions to map out the program and try to make sense of it. I tried one called Doxygen, but either I don't know how to use it properly or it's getting just as confused by the preprocessor stuff as I am.

My question is this:
What are my remaining options?

At this point it's a toss up between:
a.) Switch majors
b.) Jump off a bridge

Neither of these choices are going to help me better understand this code base and get it compiling. Does anybody have any better ideas? Similar experiences? Sage wisdom to share?

Thanks a ton,
-Alex

解决方案

Compile everything with the same runtime libraries. End of story.

这篇关于未解决的外部噩梦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆