我对c ++很新,我在调试链接器错误时遇到问题。我正在使用wxDev-c ++和g ++编译器。我创建了一个静态库,我将其链接到一个基本项目。该库最初不包含对外部头文件或库的引用,它只是一些简单的测试函数,将2个双精度数组合在一起并返回值。这与链接到测试项目时工作正常。但是我现在正试图将FTP合并到该库中,现在我正在收到链接器错误。
目前测试功能只是试图访问相同的简单添加功能进行测试,我甚至没有调用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;
}
库的编译日志输出(编译好):
执行make ... mingw32-make.exe -f“Makefile.win”全部 g ++。exe -c DaFTPLib.cpp -o Objects / MingW / DaFTPLib.o -I“C:/ Program Files(x86)/Dev-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(x86)/ Dev-Cpp / include / common / wx / html“-I”C:/ Program Files(x86)/ Dev-Cpp / include / common / wx /协议“-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”
ar rcu“Output / MingW / libDaFTP.a”“Objects / MingW / DaFTPLib.o”
执行终止 编译成功 编译需要1秒钟才能完成
测试项目的编译日志输出(编译失败)
执行make ... mingw32-make.exe -f“Makefile.win”全部 g ++。exe -c main.cpp -o Objects / MingW / main.o -I“C:/ Program Files(x86)/Dev-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(x86)/ Dev-Cpp / include / common / wx / html“-I”C:/ Program Files(x86)/ Dev-Cpp / include / common / wx /协议“-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 wxThreadHelperThread] + 0xc):未定义引用wxThread::TestDestroy()'
Objects/MingW/main.o:main.cpp:(.text$_ZN20wxThreadHelperThreadD1Ev[wxThreadHelperThread::~wxThreadHelperThread()]+0x16): undefined reference to
wxThread :: ~wxThread()'
Objects / MingW / main.o:main.cpp :(。text $ _ZN20wxThreadHelperThreadD0Ev [wxThreadHelperThread :: ~wxThreadHelperThread()] + 0x16):对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):未定义引用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 :: Connect(wxString const&amp;)'
../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:(.text+0x45a):未定义引用wxFTP::~wxFTP()'
../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text$_ZN8wxStringaSERKS_[wxString::operator=(wxString const&)]+0x14): undefined reference to
wxStringBase :: operator =(wxStringBase const&amp;)'
../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text$_ZN12wxStringBaseC2EPKc[wxStringBase::wxStringBase(char const *)] + 0x7):对wxStringBase::npos'
../libDaFTP/Output/MingW/libDaFTP.a(DaFTPLib.o):DaFTPLib.cpp:(.text$_ZN12wxStringBaseC2EPKc[wxStringBase::wxStringBase(char const*)]+0x25): undefined reference to
的未定义引用wxStringBase :: InitWith(char const *,unsigned int,unsigned int)'
collect2:ld返回1退出状态
mingw32-make.exe: * [输出/ MingW / LibTest.exe]错误1
执行终止 编译失败。返回2
<小时/> 我为这篇长篇文章道歉,但希望这足以让有人指出我正确的方向。我假设问题在于合并wx / protocol / ftp库,但我假设在编译我的库时,任何支持库(如ftp的东西)都会用它编译。<p>
答案 0 :(得分:6)
但我假设在编译我的库时,任何支持库(如ftp的东西)都会用它编译。</ p>
您所说的只适用于动态链接库:如果构建引用其他库的静态库,则链接到静态库的应用程序或DLL仍必须链接到其他库。静态库只不过是编译对象代码的集合。库代码中引用的外部函数已将 not 链接在其中。
将助手库设为DLL并将其链接到wx库,或将其保持静态,并将使用静态库的每个应用程序链接到wx库。