我很新的C++,我有調試鏈接錯誤的問題。我正在使用g ++編譯器使用wxDev-C++。我創建了一個靜態庫,我將其鏈接到一個基本項目。該庫最初不包含對外部頭文件或庫的引用,它只是一些簡單的測試函數,它們將2個雙精度值相加並返回值。鏈接到測試項目時,此工作正常。不過,我現在正試圖將FTP併入該庫中,現在我正在收到鏈接器錯誤。與C++靜態庫鏈接錯誤,引用另一個庫
目前測試功能只是試圖訪問同一個簡單的添加功能進行測試,我還沒有調用FTP功能,但因爲我只是想測試項目正確編譯。
庫代碼:
DaFTPLib.h:
#ifndef WAVE_H
#define WAVE_H
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/protocol/ftp.h>
namespace Wave
{
class DaFTP
{
public:
DaFTP(char *url, char *login, char *password);
~DaFTP();
const int Download(char* fileName);
static const void DownloadNCWD(char *url, char *fileName, char *login, char *password);
static const void DownloadLAMP();
static double FuncA(double a, double b);
static double FuncB(double a, double b);
private:
char* url, login, password;
wxFTP ftp;
};
}
#endif
DaFTP.cpp:
#include "DaFTPLib.h"
using namespace std;
char* _url;
char* _login;
char* _password;
wxFTP ftp;
namespace Wave
{
DaFTP::DaFTP(char *url, char *login, char *password)
{
_url = url;
_login = login;
_password = password;
}
DaFTP::~DaFTP(){}
const int DaFTP::Download(char *fileName)
{
int fileSize;
ftp.SetPassive(true);
ftp.SetUser(_login);
ftp.SetPassword(_password);
ftp.Connect(_url);
fileSize = ftp.GetFileSize(fileName);
return fileSize;
}
const void DaFTP::DownloadNCWD(char *url, char *fileName, char *login, char *password)
{
DaFTP daftp(url, login, password);
daftp.Download(fileName);
}
const void DaFTP::DownloadLAMP() {}
double DaFTP::FuncA(double a, double b)
{
return a + b;
}
double DaFTP::FuncB(double a, double b)
{
return a - b;
}
}
測試項目代碼:
#include <cstdlib>
#include <iostream>
#include "../libDaFTP/DaFTPLib.h"
using namespace std;
int main(int argc, char *argv[])
{
double a, b, c;
a = 23.32;
b = 26.68;
c = Wave::DaFTP::FuncA(a, b);
cout << "FuncA val: " << c << endl;
c = Wave::DaFTP::FuncB(a, b);
cout << "FuncB val: " << c << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
的編譯LO克輸出的庫(編譯OK):
執行使... 的mingw32-的make.exe -f 「Makefile.win」 所有 克++ EXE -c DaFTPLib.cpp -o對象/ MingW平臺/ DaFTPLib。的.o -I 「C:/程序文件(x86)/Dev-Cpp/lib/gcc/mingw32/3.4.5/include」 -I「C:/程序文件(x86)/開發-CPP /包括/ C++/3.4.5 /向後「-I」C:/ Program Files(x86)/ Dev-Cpp/include/C++/3.4.5/mingw32「-I」C:/ Program Files(x86)/ Dev-Cpp/include/C++/3.4.5「-I」C:/ Program Files(x86)/ Dev-Cpp/include「-I」C:/ Program Files(x86)/ Dev-Cpp /「-I」 86)/開發-CPP /包括/普通/ WX/MSW 「-I 」C:/ Program Files文件(86)/開發-CPP /包括/普通/ WX /通用「 -I」 C:/ Program Files文件(86)/dev-cpp/include/common/wx/html「-I」C:/ Program Files(x86)/ Dev-Cpp/include/common/wx/protocol「-I」C:/ Program Files(x86)/ Dev -Cpp/include/common/wx/xml「-I」C:/ Program Files(x8 6)/開發-CPP /包括/普通/ WX/XRC 「-I 」C:/程序文件(x86)/開發-CPP /包括/普通/ WX「 -I」 C:/程序文件(x86)/開發-cpp /包含/共同」
AR RCU 「輸出/ MingW平臺/ libDaFTP.a」, 「對象/ MingW平臺/ DaFTPLib.o」
執行終止 編譯成功 編譯耗時1秒鐘完成
測試項目的編譯日誌輸出(編譯失敗)
執行make ... 的mingw32-的make.exe -f 「Makefile.win」 所有 克++ EXE -c的main.cpp -o對象/ MingW平臺/ main.o -I「C:/程序文件(x86)/開發-CPP/LIB/GCC /mingw32/3.4.5/include「-I」C:/ Program Files(x86)/ Dev-Cpp/include/C++/3.4.5/backward「-I」C:/ Program Files(x86)/ Dev-Cpp /include/c++/3.4.5/mingw32「-I」C:/ Program Files(x86)/ Dev-Cpp/include/C++/3.4。5「-I」C:/ Program Files(x86)/ Dev-Cpp/include「-I」C:/ Program Files(x86)/ Dev-Cpp /「-I」C:/ Program Files(x86)/ Dev -Cpp/include/common/wx/msw「-I」C:/ Program Files(x86)/ Dev-Cpp/include/common/wx/generic「-I」C:/ Program Files/include/common/wx/html「-I」C:/ Program Files(x86)/ Dev-Cpp/include/common/wx/protocol「-I」C:/ Program Files(x86)/ Dev-Cpp/include/common/wx/xml「-I」C:/ Program Files(x86)/ Dev-Cpp/include/common/wx/xrc「-I」C:/ Program Files(x86)/ Dev-Cpp/include/common/wx「-I」C:/ Program Files(x86)/ Dev-Cpp/include/common「
g ++。exe」Objects/MingW/main.o「-o」Output/MingW/LibTest.exe「 -L「C:/ Program Files(x86)/ Dev-Cpp/Lib」../libDaFTP/Output/MingW/libDaFTP.a
Objects/MingW/main.o:main.cpp :(。rdata $ _ZTV20wxThreadHelperThread [vtable for wxThrea wxThread ::〜wxThread()' Objects/MingW/main.o:main.cpp :(。text $ _ZN20wxThreadHelperThreadD0Ev [wxThreadHelperThread ::〜wxThreadHelperThread()] + 0x16):undefined參考wxThread::TestDestroy()' Objects/MingW/main.o:main.cpp:(.text$_ZN20wxThreadHelperThreadD1Ev[wxThreadHelperThread::~wxThreadHelperThread()]+0x16): undefined reference to
wxThread ::〜wxThread參考wxThread::~wxThread()' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text+0x10): undefined reference to
wxFTP :: wxFTP()' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:((text+0x3e):undefined reference to wxFTP::wxFTP()' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text+0x6c): undefined reference to
wxFTP ::〜wxFTP( ) ' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text+0x82):未定義參照wxFTP::~wxFTP()' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text+0x1e3): undefined reference to
wxFTP ::連接(wxString常量&)' ../ libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp :(.text + 0x24e):未定義的參考wxFTP::GetFileSize(wxString const&)' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text+0x43f): undefined reference to
wxFTP :: wxFTP()' ../libDaFTP/Output/MingW/libDaFTP.a (DaFTPLib.o):DaFTPLib.cpp :(文字+爲0x4圖5a):未定義參照wxFTP::~wxFTP()' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text$_ZN8wxStringaSERKS_[wxString::operator=(wxString const&)]+0x14): undefined reference to
wxStringBase ::運算符=(const的wxStringBase &)」 ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text$_ZN12wxStringBaseC2EPKc[wxStringBase :: wxStringBase(字符常量*)] +爲0x7):未定義參照wxStringBase::npos' ../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text$_ZN12wxStringBaseC2EPKc[wxStringBase::wxStringBase(char const*)]+0x25): undefined reference to
wxStringBase :: InitWith(字符常量*,無符號整型,無符號整型)」 collect2:LD返回1退出狀態
的mingw32-的make.exe:* [Output/MingW/LibTest.exe]錯誤1
執行終止 編譯失敗。 Make returned 2
對於這篇長文章我很抱歉,但希望這是足夠的信息讓某人指向正確的方向。我認爲問題在於合併了wx/protocol/ftp庫,但我的設想是,編譯我的庫時,任何支持庫(如ftp)都將與它一起編譯。
得到它的工作基礎 - 我似乎無法找到一種方式來確定哪些文件確實需要鏈接,但我已經通過鏈接在似乎涵蓋所有基地的大量文件列表中進行編譯。 – TheOx