青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

vc編譯鏈接錯誤--LNK2001,LNK2019,

--??LINK2001
學習VC++時經常會遇到鏈接錯誤LNK2001,該錯誤非常討厭,因為對于
編程者來說,最好改的錯誤莫過于編譯錯誤,而一般說來發生連接錯誤時,
編譯都已通過。產生連接錯誤的原因非常多,尤其LNK2001錯誤,常常使人不
明其所以然。如果不深入地學習和理解VC++,要想改正連接錯誤LNK2001非
常困難。
  初學者在學習VC++的過程中,遇到的LNK2001錯誤的錯誤消息主要為:
  unresolved external symbol “symbol”(不確定的外部“符號”)。
  如果連接程序不能在所有的庫和目標文件內找到所引用的函數、變量或
標簽,將產生此錯誤消息。一般來說,發生錯誤的原因有兩個:一是所引用
的函數、變量不存在、拼寫不正確或者使用錯誤;其次可能使用了不同版本
的連接庫。
  以下是可能產生LNK2001錯誤的原因:
  一.由于編碼錯誤導致的LNK2001。
  1.不相匹配的程序代碼或模塊定義(.DEF)文件能導致LNK2001。例如,
如果在C++ 源文件內聲明了一變量“var1”,卻試圖在另一文件內以變量
“VAR1”訪問該變量,將發生該錯誤。
  2.如果使用的內聯函數是在.CPP文件內定義的,而不是在頭文件內定
義將導致LNK2001錯誤。
  3.調用函數時如果所用的參數類型同函數聲明時的類型不符將會產生
LNK2001。
  4.試圖從基類的構造函數或析構函數中調用虛擬函數時將會導致LNK2001。
  5.要注意函數和變量的可公用性,只有全局變量、函數是可公用的。
  靜態函數和靜態變量具有相同的使用范圍限制。當試圖從文件外部訪問
任何沒有在該文件內聲明的靜態變量時將導致編譯錯誤或LNK2001。
  函數內聲明的變量(局部變量) 只能在該函數的范圍內使用。
  C++ 的全局常量只有靜態連接性能。這不同于C,如果試圖在C++的
多個文件內使用全局變量也會產生LNK2001錯誤。一種解決的方法是需要時在
頭文件中加入該常量的初始化代碼,并在.CPP文件中包含該頭文件;另一種
方法是使用時給該變量賦以常數。
  二.由于編譯和鏈接的設置而造成的LNK2001
  1.如果編譯時使用的是/NOD(/NODEFAULTLIB)選項,程序所需要的運行
庫和MFC庫在連接時由編譯器寫入目標文件模塊, 但除非在文件中明確包含
這些庫名,否則這些庫不會被鏈接進工程文件。在這種情況下使用/NOD將導
致錯誤LNK2001。
  2.如果沒有為wWinMainCRTStartup設定程序入口,在使用Unicode和MFC
時將得到“unresolved external on _WinMain@16”的LNK2001錯誤信息。
  3.使用/MD選項編譯時,既然所有的運行庫都被保留在動態鏈接庫之內,
源文件中對“func”的引用,在目標文件里即對“__imp__func” 的引用。
如果試圖使用靜態庫LIBC.LIB或LIBCMT.LIB進行連接,將在__imp__func上發
生LNK2001;如果不使用/MD選項編譯,在使用MSVCxx.LIB連接時也會發生LNK2001。
  4.使用/ML選項編譯時,如用LIBCMT.LIB鏈接會在_errno上發生LNK2001。
  5.當編譯調試版的應用程序時,如果采用發行版模態庫進行連接也會產
生LNK2001;同樣,使用調試版模態庫連接發行版應用程序時也會產生相同的
問題。
  6.不同版本的庫和編譯器的混合使用也能產生問題,因為新版的庫里可
能包含早先的版本沒有的符號和說明。
  7.在不同的模塊使用內聯和非內聯的編譯選項能夠導致LNK2001。如果
創建C++庫時打開了函數內聯(/Ob1或/Ob2),但是在描述該函數的相應頭
文件里卻關閉了函數內聯(沒有inline關鍵字),這時將得到該錯誤信息。
為避免該問題的發生,應該在相應的頭文件中用inline關鍵字標志內聯函數。
  8.不正確的/SUBSYSTEM或/ENTRY設置也能導致LNK2001。
  其實,產生LNK2001的原因還有很多,以上的原因只是一部分而已,對初
學者來說這些就夠理解一陣子了。但是,分析錯誤原因的目的是為了避免錯
誤的發生。LNK2001錯誤雖然比較困難,但是只要注意到了上述問題,還是能
夠避免和予以解決的。

LNK2019
函數只有申明,沒有實現時,或是DLL中的東東沒有export啊

unresolved external symbol 'symbol' referenced in function 'function'

An undefined external symbol (symbol) was found in function. To resolve this error, provide a definition for symbol or remove the code that references it.

In Visual C++ .NET 2003, this error will be generated when /clris used and the CRT is not linked into your executable. Any object code generated by the compiler that is not built with /clr:initialAppDomain contains a reference to the _check_commonlanguageruntime_version function, which is defined in the C Runtime Library (CRT). This function provides for an error message if your application is run on version 1 of the runtime. Code generated by the current compiler is not compatible with version 1 of the common language runtime. So, if you compile without the CRT in Visual C++ .NET 2003, you should include a definition of the _check_commonlanguageruntime_version function in your code. As an alternative to using the _check_commonlanguageruntime_version function, you can link with nochkclr.obj, which contains an empty version of the function and does not provide for an error message if you run your application on version 1 of the runtime. To build an application with the current compiler version to run on the previous version of the runtime, use /clr:InitialAppDomain.

To build a pure MSIL executable (does not link with the CRT), you must define the function in your project; you cannot use nochkclr.obj (the .obj is native code). See Producing Verifiable Components with Managed Extensions for C++for more information about verifiable code. For more information on creating a pure MSIL output file from your Managed C++ project, see Converting Managed Extensions for C++ Projects from Mixed-Mode to Pure IL.

The rest of this topic discusses other causes of LNK2019.

Consider the following sample:

extern int i;
extern void g();
void f()
{
   i++;
   g();
}
int main()
{
}

If i and g are not defined in one of the files included in the build, the linker will generate LNK2019. These definitions can be added by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass .obj or .lib files that contain the definitions to the linker.

For C++ projects from previous releases that were upgraded to the current version, if __UNICODE was defined and the entry point was WinMain, you need to change the name of the entry point function to either _tWinMain or _tmain.

Common problems that cause LNK2019 include:

  • The declaration of the symbol contains a spelling mistake, such that, it is not the same name as the definition of the symbol.
  • A function was used but the type or number of the parameters did not match the function definition.
  • The calling convention (__cdecl, __stdcall, or __fastcall) differs on the use of the function declaration and the function definition.
  • Symbol definitions are in a file that was compiled as a C program and symbols are declared in a C++ file without an extern "C" modifier. In that case, modify the declaration, for example, instead of:
    extern int i;
    extern void g();

    use:

    extern "C" int i;
    extern "C" void g();

    Similarly, if you define a symbol in a C++ file that will be used by a C program, use extern "C" in the definition.

  • A symbol is defined as static and then later referenced outside the file.
  • A static member of a class is not defined. For example, member variable si in the class declaration below should be defined separately:
    #include <stdio.h>
    struct X {
       static int si;
    };
    
    // int X::si = 0;   // uncomment this line to resolve
    
    void main()
    {
       X *px = new X[2];
       printf("\n%d",px[0].si);   // LNK2019
    }

This error can also be generated as a result of conformance work that was done for Visual Studio .NET 2003: template friends and specialization. In Visual Studio?.NET 2003, a friend declaration that declares a new non-template function must be defined.

For code that is valid in both the Visual Studio?.NET 2003 and Visual Studio?.NET versions of Visual C++, explicitly specify the friend function's template argument list.

// LNK2019.cpp
// LNK2019 expected
template<class T>
void f(T)
{
}

template<class T>
struct S
{
   friend void f(T);
   // Try the folowing line instead:
   // friend void f<T>(T);
};

int main()
{
   S<int> s;
   f(1);   // unresolved external
}

The /VERBOSE linker option will help you see which files the linker is referencing. The /EXPORT and /SYMBOLS options of the DUMPBIN utility can also help you see which symbols are defined in your dll and object/library files.

posted on 2006-08-17 10:08 夢在天涯 閱讀(4270) 評論(0)  編輯 收藏 引用 所屬分類: CPlusPlus

公告

EMail:itech001#126.com

導航

統計

  • 隨筆 - 461
  • 文章 - 4
  • 評論 - 746
  • 引用 - 0

常用鏈接

隨筆分類

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1815124
  • 排名 - 5

最新評論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              久久激情五月婷婷| 在线观看视频免费一区二区三区| 亚洲欧美日韩国产中文在线| 亚洲视频精选在线| 国产欧美日韩伦理| 久久久久在线| 快播亚洲色图| 中文在线资源观看视频网站免费不卡| 一区二区免费在线观看| 国产欧美日韩综合精品二区| 久久夜色精品国产欧美乱| 麻豆久久精品| 亚洲午夜精品在线| 欧美有码视频| 亚洲精品国久久99热| 国产精品99久久99久久久二8| 国产亚洲欧美日韩日本| 欧美高清视频在线播放| 欧美视频中文一区二区三区在线观看 | 亚洲国产精品一区二区第一页| 亚洲成人在线视频播放| 狠狠久久亚洲欧美| 亚洲国产精品久久久久秋霞影院| 欧美午夜电影在线| 久久综合免费视频影院| 欧美精品一区二区三区在线看午夜| 午夜精品久久| 另类尿喷潮videofree| 亚洲永久在线| 久久久久久久久久久久久久一区| 夜夜精品视频| 久久国产精品99久久久久久老狼| 亚洲精品久久久久久一区二区| 亚洲一区二区久久| 亚洲国产精品精华液2区45| 亚洲少妇一区| 亚洲激情在线播放| 亚洲综合视频1区| 亚洲精品视频啊美女在线直播| 亚洲一区精品电影| 亚洲精品乱码久久久久久按摩观| 亚洲免费在线观看视频| 亚洲精品一区中文| 欧美一区二区三区四区夜夜大片| 亚洲精品一区二区网址 | 先锋亚洲精品| 亚洲三级影院| 欧美亚洲尤物久久| 亚洲网友自拍| 女女同性女同一区二区三区91| 性欧美超级视频| 欧美激情第五页| 玖玖国产精品视频| 国产精品久久久亚洲一区| 欧美激情黄色片| 国产日韩欧美二区| 99在线热播精品免费99热| 在线成人中文字幕| 亚洲一区视频在线观看视频| 日韩视频免费| 久久一区二区精品| 久久激情综合网| 国产精品xvideos88| 亚洲成人在线视频网站| 黄色欧美成人| 午夜精品久久久久久久白皮肤 | 亚洲精品视频啊美女在线直播| 国语自产在线不卡| 亚洲欧美99| 亚洲香蕉网站| 欧美巨乳波霸| 欧美激情乱人伦| 一区二区在线观看视频在线观看| 亚洲永久免费视频| 亚洲午夜免费视频| 欧美乱大交xxxxx| 欧美激情亚洲精品| 尤物精品在线| 久久精品日韩欧美| 久久久精品tv| 国产区二精品视| 亚洲亚洲精品在线观看| 亚洲线精品一区二区三区八戒| 欧美日韩不卡一区| 亚洲人精品午夜| 亚洲精品在线一区二区| 免费不卡在线观看| 欧美国产综合一区二区| 影音先锋国产精品| 久久露脸国产精品| 久久裸体视频| 黄色成人免费网站| 久久精品视频网| 久久综合给合| 精久久久久久| 久久久久久亚洲精品杨幂换脸| 久久一区中文字幕| 一区在线电影| 久久在线精品| 欧美电影在线观看完整版| 亚洲第一在线| 免费一级欧美在线大片| 欧美激情一区二区三区在线视频| 亚洲高清不卡在线| 美女精品自拍一二三四| 免费视频一区| 91久久线看在观草草青青| 久久久久久综合网天天| 欧美xart系列在线观看| 亚洲高清色综合| 久久青青草原一区二区| 免费观看30秒视频久久| 国语自产在线不卡| 久久综合色播五月| 欧美激情亚洲视频| 日韩午夜三级在线| 欧美日韩亚洲综合在线| 亚洲欧美日韩一区二区在线 | 99av国产精品欲麻豆| 国产精品99久久久久久www| 国产精品v亚洲精品v日韩精品| 亚洲一区二区三区免费在线观看| 欧美一区二区私人影院日本| 国产深夜精品福利| 久久久久久网站| 亚洲激情小视频| 亚洲一区二区三区精品动漫| 国产精品蜜臀在线观看| 欧美在线免费视频| 欧美大胆人体视频| av不卡在线| 国产精品中文在线| 久久久久久999| 91久久久久久久久| 亚洲尤物影院| 国产亚洲制服色| 麻豆精品网站| 一区二区欧美视频| 久久久久久久久久久成人| 在线看国产一区| 欧美成人精品一区| 一本一道久久综合狠狠老精东影业| 欧美一区二区啪啪| 在线不卡中文字幕| 欧美精品v国产精品v日韩精品| 亚洲午夜羞羞片| 麻豆久久久9性大片| 一本一本久久a久久精品综合妖精 一本一本久久a久久精品综合麻豆 | 欧美日韩一区二区在线| 亚洲欧美日韩高清| 另类天堂视频在线观看| 亚洲美女视频| 国产精品手机在线| 久久在线免费视频| 中文精品视频一区二区在线观看| 久久久www| 99pao成人国产永久免费视频| 国产精品乱码一区二三区小蝌蚪| 久久精视频免费在线久久完整在线看| 91久久夜色精品国产九色| 欧美伊人久久久久久午夜久久久久 | 日韩视频在线观看一区二区| 国产精品亚洲片夜色在线| 久久综合九色九九| 99伊人成综合| 免费观看在线综合| 亚洲女爱视频在线| 亚洲国产天堂久久综合| 国产精品高潮在线| 美女诱惑黄网站一区| 亚洲综合不卡| 亚洲黄色在线视频| 久久久久久亚洲精品杨幂换脸| 99国产一区二区三精品乱码| 国内精品视频666| 欧美视频专区一二在线观看| 久久亚洲免费| 亚洲一区二区三区在线播放| 亚洲国产精品传媒在线观看| 久久精品国产久精国产一老狼| 一本大道久久a久久精品综合| 黄色成人免费网站| 国产精品尤物| 欧美日韩一区二区三区| 久热精品在线| 午夜精品久久久久久| 99ri日韩精品视频| 欧美黄色视屏| 久久噜噜噜精品国产亚洲综合| 亚洲免费视频在线观看| 亚洲欧洲精品一区二区三区波多野1战4| 国产欧美日韩亚洲| 欧美午夜免费影院| 欧美激情视频网站| 久久久久综合| 久久av红桃一区二区小说| 亚洲乱码国产乱码精品精| 欧美黑人在线观看| 蜜臀91精品一区二区三区| 欧美在线观看视频一区二区三区 |