久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='wm1Et'></tfoot>

      <i id='wm1Et'><tr id='wm1Et'><dt id='wm1Et'><q id='wm1Et'><span id='wm1Et'><b id='wm1Et'><form id='wm1Et'><ins id='wm1Et'></ins><ul id='wm1Et'></ul><sub id='wm1Et'></sub></form><legend id='wm1Et'></legend><bdo id='wm1Et'><pre id='wm1Et'><center id='wm1Et'></center></pre></bdo></b><th id='wm1Et'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wm1Et'><tfoot id='wm1Et'></tfoot><dl id='wm1Et'><fieldset id='wm1Et'></fieldset></dl></div>
        <bdo id='wm1Et'></bdo><ul id='wm1Et'></ul>

      <small id='wm1Et'></small><noframes id='wm1Et'>

    1. <legend id='wm1Et'><style id='wm1Et'><dir id='wm1Et'><q id='wm1Et'></q></dir></style></legend>

      .lib 中的 C++ 靜態變量未初始化

      C++ static variable in .lib does not initialize(.lib 中的 C++ 靜態變量未初始化)
      <tfoot id='ZMGAO'></tfoot>

      <small id='ZMGAO'></small><noframes id='ZMGAO'>

      <legend id='ZMGAO'><style id='ZMGAO'><dir id='ZMGAO'><q id='ZMGAO'></q></dir></style></legend>
        <bdo id='ZMGAO'></bdo><ul id='ZMGAO'></ul>

        <i id='ZMGAO'><tr id='ZMGAO'><dt id='ZMGAO'><q id='ZMGAO'><span id='ZMGAO'><b id='ZMGAO'><form id='ZMGAO'><ins id='ZMGAO'></ins><ul id='ZMGAO'></ul><sub id='ZMGAO'></sub></form><legend id='ZMGAO'></legend><bdo id='ZMGAO'><pre id='ZMGAO'><center id='ZMGAO'></center></pre></bdo></b><th id='ZMGAO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ZMGAO'><tfoot id='ZMGAO'></tfoot><dl id='ZMGAO'><fieldset id='ZMGAO'></fieldset></dl></div>

              <tbody id='ZMGAO'></tbody>
                本文介紹了.lib 中的 C++ 靜態變量未初始化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我在 VS2010 中有靜態庫 (.lib) 并將其鏈接到我的測試項目.

                I have static library (.lib) in VS2010 and am linking it to my test project.

                該庫有一個我使用以下宏創建的工廠:

                The lib has a factory that I create using the below MACRO:

                #define REGISTER_FACTORY(mType, my_class) 
                class Factory##my_class : public CAbstractFactory
                {
                public:
                    Factory##my_class() : CAbstractFactory(mType){}
                    CBaseClass *Create()
                    { return new my_class(); }
                };
                static Factory##my_class StaticFactory##my_class;
                

                應該發生的是,在 CAbstractFactory 中,新工廠通過 mtype 注冊.但是當我檢查工廠時,工廠不存在.

                What is supposed to happen is that in the CAbstractFactory the new factory gets registered by mtype. But when I check the factory the factory does not exist.

                當我使用 DLL 而不是 .lib 時它工作正常.我的猜測是鏈接器不包含靜態變量,因為它沒有被引用,或者靜態變量甚至沒有包含在庫中.

                It works fine when I use a DLL instead of a .lib. My guess is that the linker does not include the static variable as it is not referenced or the static variable was not even included in the library.

                如何強制鏈接器將靜態庫中的所有對象包含在我的 .exe 中.

                How can I force the linker to include all objects from the static library in my .exe.

                我像這樣使用宏:

                // Register factory that can create CMyObject with ID=100
                REGISTER_FACTORY(100, CMyObject);
                
                class CMyObject
                {
                };
                

                CAbstractFactory 看起來像這樣:

                The CAbstractFactory looks like this:

                class CAbstractFactory {
                    CAbstractFactory(int id) {
                        CFactory::instance().add(id, this);
                    }
                }
                

                然后是代碼中的其他地方,我使用的主要 .exe:

                Then some where else in the code, my main .exe I use:

                CBaseClass *pObject = CFactory::instance().Create(100);
                

                這會給我一個新的CMyObject.這個想法是我有許多不同種類的對象,我有一個包含指定我需要的對象種類的 id 的數據庫.100 只是一個例子.

                This will then give my a new CMyObject. The idea is that I have many different kind object and I have a database containing the id specifying the kind of objects I need. 100 is just an example.

                確實,我沒有直接從 .lib 中引用任何內容,但我希望能夠使用我的工廠創建對象

                So indeed, I do not reference anything from the .lib directly but I want to be able to create the objects using my factory

                CFactory 類是一個簡單的類,它保存所有 CAbstractFactory 類的寄存器(在映射中)并將 create 方法委托給正確的工廠.

                The CFactory class is a simple class that keeps a register (in a map) of all the CAbstractFactory classes and delegates the create method to the correct factory.

                CFactory &CFactory::Instance()
                {
                    static CFactory instance;
                    return instance;
                }
                

                主要問題在于我沒有從 .lib 中引用任何內容,因為它都是通過 CFactory 完成的.如果我將其設置為 DLL 并確保我添加了對這個 DLL 的一些引用以確保它被加載,它就可以工作.但是對于 .lib,我什至添加了一個虛擬函數,以確保我至少有一個不包含其余代碼的引用.

                The main problem lies in the fact that I do not reference anything from the .lib as it is all done through the CFactory. It works if I make it a DLL and make sure I add some reference to this DLL to make sure it is loaded. But for a .lib, I even added a dummy function to make sure I have at least one reference that doesn't include the rest of the code.

                推薦答案

                我遇到了類似的問題,通過將 lib 項目設置為主應用項目的依賴項,然后設置鏈接庫依賴項"和使用庫"來解決主要項目的依賴項輸入'為是.

                I had a similar problem and solved it by setting the lib project as a dependency of the main app project and then setting 'Link Library Dependencies' and 'Use Library Dependency Inputs' to Yes for the main project.

                更新:

                最近我發現 Visual Studio 2015 現在支持 /WHOLEARCHIVE 鏈接器標志.我無法通過鏈接器選項找到它,但您可以將其添加為附加命令行選項.它的工作原理類似于 GCC 標志 -whole-archive 并將其添加到目標鏈接器標志(而不是靜態庫標志).

                Recently I discovered that Visual Studio 2015 now supports a /WHOLEARCHIVE linker flag. I can't find it through the linker options, but you can add it as an additional command line option. It works similar to the GCC flag -whole-archive and you add it to your target linker flags (not to the static lib flags).

                例如,指定 /WHOLEARCHIVE:lib_name 作為附加鏈接器命令行選項,它將包含該庫中的所有符號.您也可以執行多個庫.

                For example, specify /WHOLEARCHIVE:lib_name as an additional linker command line option and it will include all symbols from that lib. You can do this more than one lib as well.

                如果您使用此 /WHOLEARCHIVE:lib_name,則不再需要將鏈接庫依賴項"和使用庫依賴項輸入"設置為是".這非常適合通過 CMAKE 生成的解決方案.在此處查看相關答案:https://stackoverflow.com/a/42083877/1151329

                If you use this /WHOLEARCHIVE:lib_name you no longer need the 'Link Library Dependencies' and 'Use Library Dependency Inputs' set to Yes. This is perfect for solutions generated through CMAKE. See a related answer here: https://stackoverflow.com/a/42083877/1151329

                這篇關于.lib 中的 C++ 靜態變量未初始化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Why do two functions have the same address?(為什么兩個函數的地址相同?)
                Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                mixing templates with polymorphism(混合模板與多態性)
                When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)
                  <tfoot id='LIo6V'></tfoot>

                  <small id='LIo6V'></small><noframes id='LIo6V'>

                    <tbody id='LIo6V'></tbody>
                    <bdo id='LIo6V'></bdo><ul id='LIo6V'></ul>
                  • <legend id='LIo6V'><style id='LIo6V'><dir id='LIo6V'><q id='LIo6V'></q></dir></style></legend>

                    <i id='LIo6V'><tr id='LIo6V'><dt id='LIo6V'><q id='LIo6V'><span id='LIo6V'><b id='LIo6V'><form id='LIo6V'><ins id='LIo6V'></ins><ul id='LIo6V'></ul><sub id='LIo6V'></sub></form><legend id='LIo6V'></legend><bdo id='LIo6V'><pre id='LIo6V'><center id='LIo6V'></center></pre></bdo></b><th id='LIo6V'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LIo6V'><tfoot id='LIo6V'></tfoot><dl id='LIo6V'><fieldset id='LIo6V'></fieldset></dl></div>

                        • 主站蜘蛛池模板: 成人国产精品久久久 | 成年人精品视频 | 免费影视在线观看 | 日本三级网址 | 成人h动漫精品一区二区器材 | 日韩三级一区 | 九九国产 | 91免费观看 | 国产成人久久精品一区二区三区 | www.夜夜骑.com| 亚洲高清免费观看 | 男女羞羞网站 | 91久久北条麻妃一区二区三区 | 国产精品久久久久久久久免费相片 | 日韩毛片在线视频 | 日韩有码一区 | 国产欧美二区 | 99久久久无码国产精品 | 婷婷久久综合 | 日韩欧美一区二区三区 | 精品国产一二三区 | 天天射天天干 | 天天干夜夜拍 | 亚洲一区二区三区视频 | 久久中文字幕一区 | 亚洲经典一区 | 国产高清在线精品一区二区三区 | 精品日韩在线观看 | 国产高清性xxxxxxxx | 日本亚洲欧美 | 一区二区三区四区不卡视频 | 中文字幕一区二区三区四区 | 天堂一区二区三区 | 亚洲午夜精品视频 | 国产精品一二三区 | 国产精品视频一区二区三区四蜜臂 | 色99视频 | 成人精品国产 | 国产精品欧美一区二区三区不卡 | 日韩一区二区福利视频 | 日本电影网站 |