簡體   English   中英

鏈接器錯誤 - 未定義參考

[英]Linker errors-Undefined Reference to

我有一個項目,當我構建這個其他項目時,它具有日志項目的依賴項,我得到以下鏈接器錯誤:

日志項目很好地構建,但是當我使用此項目中的日志項目作為鏈接器選項中的庫時,它會生成以下錯誤,在我的日志記錄項目中,我確實有一個logger.cpp,其中定義了wxRegKey。

../logging/dist/Debug/MinGW_1-Windows/liblogging.a(Logger.o): In function `ZN7Logging6Logger17CreateRegistryKeyEv':
c:\logging/impl/Logger.cpp:125: undefined reference to `_imp___ZN8wxRegKeyC1ENS_6StdKeyERK8wxString'
c:\logging/impl/Logger.cpp:127: undefined reference to `_imp___ZN8wxRegKeyC1ENS_6StdKeyERK8wxString'
c:\logging/impl/Logger.cpp:129: undefined reference to `_imp___ZNK8wxRegKey6ExistsEv'
c:\logging/impl/Logger.cpp:135: undefined reference to `_imp___ZN8wxRegKeyD1Ev'
c:\logging/impl/Logger.cpp:140: undefined reference to `_imp___ZN8wxRegKeyC1ENS_6StdKeyERK8wxString'
c:\logging/impl/Logger.cpp:142: undefined reference to `_imp___ZNK8wxRegKey6ExistsEv'
c:\logging/impl/Logger.cpp:143: undefined reference to `_imp___ZN8wxRegKey6CreateEb'
c:\logging/impl/Logger.cpp:149: undefined reference to `_imp___ZNK8wxRegKey6ExistsEv'
c:\logging/impl/Logger.cpp:152: undefined reference to `_imp___ZN8wxRegKeyD1Ev'
c:\logging/impl/Logger.cpp:155: undefined reference to `_imp___ZN8wxRegKeyC1ENS_6StdKeyERK8wxString'
c:\logging/impl/Logger.cpp:156: undefined reference to `_imp___ZNK8wxRegKey6ExistsEv'
c:\logging/impl/Logger.cpp:157: undefined reference to `_imp___ZN8wxRegKey6CreateEb'
../logging/dist/Debug/MinGW_1-Windows/liblogging.a(Logger.o): In function 
`ZN7Logging6Logger13GetLoggStatusEv':
c:\logging/impl/Logger.cpp:169: undefined reference to     
`_imp___ZNK8wxRegKey8HasValueEPKc'
c:\logging/impl/Logger.cpp:170: undefined reference to 
`_imp___ZNK8wxRegKey10QueryValueEPKcPl'
c:\logging/impl/Logger.cpp:176: undefined reference to 
`_imp___ZN8wxRegKey8SetValueEPKcl'


../logging/dist/Debug/MinGW_1-Windows/liblogging.a(Logger.o): In function  
`ZN7Logging6Logger12SetLoggLevelEv':
c:\logging/impl/Logger.cpp:186: undefined reference to    
`_imp___ZNK8wxRegKey8HasValueEPKc'
 c:\logging/impl/Logger.cpp:193: undefined reference to 
`_imp___ZN8wxRegKey8SetValueEPKcRK8wxString'
c:\logging/impl/Logger.cpp:200: undefined reference to `_imp__wxConvUTF8'
../logging/dist/Debug/MinGW_1-Windows/liblogging.a(Logger.o): In function 
`ZN12wxStringBase4InitEv':
C:/wxWidgets-2.8.12/include/wx/string.h:270: undefined reference to   
`_imp__wxEmptyString'
../logging/dist/Debug/MinGW_1-Windows/liblogging.a(Logger.o): In function `wxStringBase':
C:/wxWidgets-2.8.12/include/wx/string.h:368: undefined reference to   
`_imp___ZN12wxStringBase4nposE'
C:/wxWidgets-2.8.12/include/wx/string.h:368: undefined reference to 
`_imp___ZN12wxStringBase8InitWithEPKcjj'
../logging/dist/Debug/MinGW_1-Windows/liblogging.a(Logger.o): In function 
 `ZNK8wxRegKey10QueryValueEPKcR8wxString':
C:/wxWidgets-2.8.12/include/wx/msw/registry.h:167: undefined reference to    
`_imp___ZNK8wxRegKey10QueryValueEPKcR8wxStringb'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/MinGW_1-Windows/abcproject.dll] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/c/abcproject'
make[1]: Leaving directory `/c/abcproject'


 BUILD FAILED (exit value 2, total time: 34s)

logger.h中包含文件的順序

 #include <vector>
 #include <sstream>
 #include <string>
 #include <ctime>
 #include <windows.h>
 #include <winbase.h>
 #include <wx/wx.h>
 #include <wx/thread.h>
 #include <wx/log.h>
 #include <wx/app.h>
 #include <wx/msw/registry.h>
 #include <wx/utils.h>
 #include <map>

請幫忙

您顯然忽略了包含定義wxRegKey類的幾個函數的庫。 這就是鏈接器無法找到的內容。 你確定logger.cpp定義了wxRegKey 及其所有方法嗎?

我懷疑你的源代碼實際上沒有定義任何與wxRegKey相關的東西,因為它實際上是來自外部庫的一個類。 您已經包含了一個聲明該類的頭文件,而不是定義該類。 定義位於外部文件中,您需要告訴構建系統哪個文件。

您有鏈接錯誤,而不是編譯錯誤,因此#include語句的順序無關緊要。 當您看到此處報告的錯誤時,編譯器已完成編譯。 編譯器已將您的文本源代碼轉換為二進制目標代碼,現在鏈接器正在嘗試將所有二進制文件收集在一起以形成最終的可執行程序。 二進制文件指的是編譯器被告知將在其他地方定義的一些函數,現在鏈接器正在嘗試查找這些定義,但它不能。

如果您不知道函數的定義位置,或者如何告訴構建系統在哪里找到它們,那么您可能需要發布另一個問題:我需要鏈接什么才能使用wxRegKey? 如何在NetBeans項目中鏈接wxWidgets? 我不知道這些問題的答案,因為我從未使用過這些工具。

你似乎使用wxwidgets 您確定在鏈接最終可執行文件時鏈接正確的庫嗎? 請查看傳遞給鏈接器的命令。

看來你忘了添加庫wxBase到鏈接器命令行,besause甚至wxString -symbols aren`t解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM