我有一些旧的 C 代码,我想将它们与一些 C++ 代码结合起来。
以前的C代码有以下内容:
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "mysql.h"
现在我试图让它使用 C++ 和 iostream,如下所示:
#include <windows.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include "mysql.h"
但编译时我不断收到以下链接器错误:
[链接器错误] 对 `std::string::size() const' 的未定义引用
[链接器错误] 对 `std::string::operator[](unsigned int) const' 的未定义引用
[链接器错误] 对 `std::string::operator[](unsigned int) const' 的未定义引用
[链接器错误] 对 `std::string::operator[](unsigned int) const' 的未定义引用
[链接器错误] 对 `std::ios_base::Init::Init()' 的未定义引用
[链接器错误] 对 `std::ios_base::Init::~Init()' 的未定义引用
ld 返回 1 退出状态
我该如何解决这个问题?
编辑:我的编译器是Dev-C++ 4.9.9.2
The C string.h
标头和 C++string
标头不可互换。
但总的来说,您的问题是文件已正确编译,但链接了错误的运行时库。
Dev-C++ 使用 GCC。 GCC 可以根据文件扩展名正确确定文件中的语言,但不会链接正确的运行时库,除非您特别要求它(在命令行中使用 -lstdc++)。将 GCC 调用为“g++”(或者在您的情况下为“mingwin32-g++”)也将获得正确的语言,并将链接所需的库。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)