gpt4 book ai didi

c++ - 引用另一个库的c++静态库的链接器错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:26:20 26 4
gpt4 key购买 nike

我是C++的新手,调试链接器错误时遇到问题。我在g++编译器中使用wxDev-c++。我创建了一个静态库,该库链接到一个基本项目。该库最初不包含对外部头文件或库的引用,它只是几个简单的测试函数,将两个double值加在一起并返回值。链接到测试项目时,此方法工作正常。但是,我现在正在尝试将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对象/MingW/DaFTPLib.o -I“C:/程序文件(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:/程序文件(x86)/Dev-Cpp/include/c++/3.4.5“-I” C:/程序文件(x86)/Dev-Cpp/include“-I” C:/程序文件(x86)/Dev-Cpp/“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/msw“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/generic“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/html“-I” C:/Program文件(x86)/Dev-Cpp/include/common/wx/协议(protocol)“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/xml“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/xrc“-I“C:/程序文件(x86)/Dev-Cpp/include/common/wx” -I“C:/程序文件(x86)/Dev-Cpp/include/common”

ar rcu“输出/MingW/libDaFTP.a”“对象/MingW/DaFTPLib.o”

执行终止
编译成功
编译耗时1秒完成

测试项目的编译日志输出(编译失败)

执行make ...
mingw32-make.exe -f“Makefile.win”全部
g++。exe -c main.cpp -o对象/MingW/main.o -I“C:/程序文件(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:/程序文件(x86)/Dev-Cpp/include/c++/3.4.5“-I” C:/程序文件(x86)/Dev-Cpp/include“-I” C:/程序文件(x86)/Dev-Cpp/“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/msw“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/generic“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/html“-I” C:/Program文件(x86)/Dev-Cpp/include/common/wx/协议(protocol)“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/xml“-I” C:/程序文件(x86)/Dev-Cpp/include/common/wx/xrc“-I“C:/程序文件(x86)/Dev-Cpp/include/common/wx” -I“C:/程序文件(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

对象/MingW/main.o:main.cpp:(.rdata$_ZTV20wxThreadHelperThread[wxThreadHelperThread的vtable] + 0xc):对 wxThread::TestDestroy()'
Objects/MingW/main.o:main.cpp:(.text$_ZN20wxThreadHelperThreadD1Ev[wxThreadHelperThread::~wxThreadHelperThread()]+0x16): undefined reference to
的 undefined reference wxThread::〜wxThread()'
对象/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
的 undefined reference 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()的 undefined reference
../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&)'
../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()的 undefined reference
../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&)'
../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的 undefined reference (字符const *,unsigned int,unsigned int)'
collect2:ld返回1退出状态

mingw32-make.exe:* [Output/MingW/LibTest.exe]错误1

执行终止
编译失败。退货2

对于冗长的帖子,我深表歉意,但希望这对于有人向我指出正确的方向提供了足够的信息。我以为问题在于合并wx/protocol/ftp库,但是我的假设是,在编译我的库时,任何支持的库(例如ftp东西)都将与之一起编译。

最佳答案

but I was under the assumption that when compiling my library any supporting libraries such as the ftp stuff would be compiled in with it.



您所说的仅适用于动态链接的库:如果您构建引用其他库的静态库,则链接到您的静态库的应用程序或DLL仍必须链接到其他库。静态库只不过是编译的目标代码的集合。库代码中引用的外部函数尚未链接。

使您的帮助程序库成为DLL并将其链接到wx库,或者使其保持静态并将使用该静态库的每个应用程序链接到wx库。

关于c++ - 引用另一个库的c++静态库的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8273460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com