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

<tfoot id='bD94d'></tfoot>
    • <bdo id='bD94d'></bdo><ul id='bD94d'></ul>

    1. <small id='bD94d'></small><noframes id='bD94d'>

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

        如何解決錯誤 LNK2019:未解析的外部符號 - 函數?

        How can I solve the error LNK2019: unresolved external symbol - function?(如何解決錯誤 LNK2019:未解析的外部符號 - 函數?)

            <tfoot id='cByJP'></tfoot>
            • <bdo id='cByJP'></bdo><ul id='cByJP'></ul>
                <tbody id='cByJP'></tbody>

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

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

                  <legend id='cByJP'><style id='cByJP'><dir id='cByJP'><q id='cByJP'></q></dir></style></legend>

                  本文介紹了如何解決錯誤 LNK2019:未解析的外部符號 - 函數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我收到此錯誤,但我不知道如何解決.

                  I get this error, but I don't know how to fix it.

                  我使用的是 Visual Studio 2013.我將解決方案命名為 MyProjectTest這是我的測試解決方案的結構:

                  I'm using Visual Studio 2013. I made the solution name MyProjectTest This is the structure of my test solution:

                  -function.h

                  #ifndef MY_FUNCTION_H
                  #define MY_FUNCTION_H
                  
                  int multiple(int x, int y);
                  #endif
                  

                  -function.cpp

                  #include "function.h"
                  
                  int multiple(int x, int y){
                      return x*y;
                  }
                  

                  -main.cpp

                  #include <iostream>
                  #include <cstdlib>
                  #include "function.h"
                  
                  using namespace std;
                  
                  int main(){
                      int a, b;
                      cin >> a >> b;
                      cout << multiple(a, b) << endl;
                  
                      system("pause");
                      return 0;
                  }
                  

                  我是初學者;這是一個簡單的程序,它運行沒有錯誤.網上看了看,對單元測試產生了興趣,于是創建了一個測試項目:

                  I'm a beginner; this is a simple program and it runs without error. I read on the Internet and became interested in the unit test, so I created a test project:

                  菜單文件新建項目...已安裝模板Visual C++測試本機單元測試項目

                  Menu FileNewProject...InstalledTemplatesVisual C++TestNative Unit Test Project

                  名稱:UnitTest1
                  解決方案:添加到解決方案

                  然后位置自動切換到當前打開解決方案的路徑.

                  Then the location auto-switched to the path of the current open solution.

                  這是解決方案的文件夾結構:

                  This is the folder structure of the solution:

                  我只編輯了文件unittest1.cpp:

                  #include "stdafx.h"
                  #include "CppUnitTest.h"
                  #include "../MyProjectTest/function.h"
                  
                  using namespace Microsoft::VisualStudio::CppUnitTestFramework;
                  
                  namespace UnitTest1
                  {
                      TEST_CLASS(UnitTest1)
                      {
                      public:
                  
                          TEST_METHOD(TestEqual)
                          {
                              Assert::AreEqual(multiple(2, 3), 6);
                              // TODO: Your test code here
                          }
                  
                      };
                  }
                  

                  但我明白了:

                  錯誤 LNK2019:未解析的外部符號.

                  error LNK2019: unresolved external symbol.

                  我知道缺少函數 multiple 的實現.我試圖刪除 function.cpp 文件,我用定義替換了聲明,它運行了.但是不建議將聲明和定義寫在同一個文件中.

                  I know that the implementation of function multiple is missing. I tried to delete the function.cpp file and I replaced the declaration with the definition, and it ran. But writing both declaration and definition in the same file is not recommended.

                  如何在不這樣做的情況下修復此錯誤?我應該用文件 unittest.cpp 中的 #include "../MyProjectTest/function.cpp" 替換它嗎?

                  How can I fix this error without doing that? Should I replace it with #include "../MyProjectTest/function.cpp" in file unittest.cpp?

                  推薦答案

                  一種選擇是將 function.cpp 包含在您的 UnitTest1 項目中,但這可能不是最理想的解決方案結構.對您的問題的簡短回答是,在構建 UnitTest1 項目時,編譯器和鏈接器不知道 function.cpp 存在,并且也沒有任何鏈接包含multiple 的定義.解決此問題的一種方法是使用鏈接庫.

                  One option would be to include function.cpp in your UnitTest1 project, but that may not be the most ideal solution structure. The short answer to your problem is that when building your UnitTest1 project, the compiler and linker have no idea that function.cpp exists, and also have nothing to link that contains a definition of multiple. A way to fix this is making use of linking libraries.

                  由于您的單元測試在不同的項目中,我假設您的意圖是使該項目成為一個獨立的單元測試程序.如果您正在測試的函數位于另一個項目中,則可以將該項目構建為動態或靜態鏈接的庫.靜態庫在構建時鏈接到其他程序,擴展名為.lib,動態庫在運行時鏈接,擴展名為.dll.對于我的回答,我更喜歡靜態庫.

                  Since your unit tests are in a different project, I'm assuming your intention is to make that project a standalone unit-testing program. With the functions you are testing located in another project, it's possible to build that project to either a dynamically or statically linked library. Static libraries are linked to other programs at build time, and have the extension .lib, and dynamic libraries are linked at runtime, and have the extension .dll. For my answer I'll prefer static libraries.

                  您可以通過在項目屬性中更改您的第一個程序來將其轉換為靜態庫.在常規"選項卡下應該有一個選項,將項目設置為生成可執行文件 (.exe).您可以將其更改為 .lib..lib 文件將構建到與 .exe 相同的位置.

                  You can turn your first program into a static library by changing it in the projects properties. There should be an option under the General tab where the project is set to build to an executable (.exe). You can change this to .lib. The .lib file will build to the same place as the .exe.

                  在您的 UnitTest1 項目中,您可以轉到其屬性,然后在類別 Additional Library Directories 的 Linker 選項卡下,添加 MyProjectTest 構建的路徑.然后,對于鏈接器 - 輸入選項卡下的附加依賴項,添加靜態庫的名稱,很可能是 MyProjectTest.lib.

                  In your UnitTest1 project, you can go to its properties, and under the Linker tab in the category Additional Library Directories, add the path to which MyProjectTest builds. Then, for Additional Dependencies under the Linker - Input tab, add the name of your static library, most likely MyProjectTest.lib.

                  這應該允許您的項目構建.請注意,這樣做后,MyProjectTest 將不會成為獨立的可執行程序,除非您根據需要更改其構建屬性,這會不太理想.

                  That should allow your project to build. Note that by doing this, MyProjectTest will not be a standalone executable program unless you change its build properties as needed, which would be less than ideal.

                  這篇關于如何解決錯誤 LNK2019:未解析的外部符號 - 函數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                  When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)
                  • <bdo id='UFm2o'></bdo><ul id='UFm2o'></ul>
                  • <tfoot id='UFm2o'></tfoot>

                        <tbody id='UFm2o'></tbody>

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

                          <legend id='UFm2o'><style id='UFm2o'><dir id='UFm2o'><q id='UFm2o'></q></dir></style></legend>

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

                            主站蜘蛛池模板: 日韩影院在线 | 日韩中文字幕视频 | 91精品国产91久久久 | 国产精品视频 | 91素人| 一级片免费视频 | 中文字幕日韩欧美一区二区三区 | 亚洲在线一区二区 | 国产精品爱久久久久久久 | 精品日本久久久久久久久久 | 日韩欧美亚洲 | 国产欧美一区二区三区久久手机版 | 国产精品毛片一区二区三区 | 日韩在线中文字幕 | 亚洲精品毛片av | 国产精品福利一区二区三区 | 国产精品不卡 | 国产清纯白嫩初高生在线播放视频 | 草久网| 99精品久久久久久 | 91黄在线观看 | 国产精品久久久久无码av | 精品国产一区二区三区av片 | 91爱爱·com| 日韩精品国产精品 | 99成人在线视频 | 国产精品一区久久久 | 国产一区二区三区 | av小说在线 | 国产精品久久777777 | 日日操夜夜操天天操 | 国产日韩精品在线 | 高清黄色毛片 | 欧美精品一区二区三区视频 | 久久一二区 | 亚洲一区二区在线免费观看 | www.国产.com | 精品久久久久久久久久久久久久 | 国产精品中文字幕在线 | 99热最新| 精品视频在线一区 |