尝试使用外部头编译程序时出现问题

发布于 2024-11-29 13:33:12 字数 1047 浏览 1 评论 0原文

我正在学习 C++,我正在尝试在我的程序中使用从互联网下载的库(从这里 https ://mattmccutchen.net/bigint/)。 因为我希望一切都非常整洁,所以我将所有 .hh 文件放在名为“BI”的子文件夹中。 但是,当我尝试使用 g++(Windows XP SP3 上的 MinGW)编译 .cpp 文件时,编译器输出以下错误:

J:\comp proj\FS>J:\Programmi\MinGW\bin\g++.exe "J:\comp proj\FS\test.cpp" -o "J:\comp proj\FS\test.exe" -I “J:\comp proj\FS\BI” E:\DOCUME~1\MrJackV\IMPOST~1\Temp\ccidH1Z6.o:test.cpp:(.text+0x2c): 对 BigInteger::BigInteger(int)' 的未定义引用 E:\DOCUME~1\MrJackV\IMPOST~1\Temp\ccidH1Z6.o:test.cpp:(.text+0x11b): 对运算符的未定义引用<<(std::ostream&, BigInteger const& ;)' E:\DOCUME~1\MrJackV\IMPOST~1\Temp\ccidH1Z6.o:test.cpp:(.text$ZNK10BigIntegermlERKS[BigInteger::operator*(BigInteger const&) const]+0x29 ): 未定义的参考 到 `BigInteger::multiply(BigInteger const&, BigInteger const&)' Collect2: ld 返回 1 退出状态

我尝试使用-I、-l 和-L 开关来解决该问题,但没有成功。 此外,我尝试在 cpp 中添加 #include "BI/BigIntegerLibrary.hh" 但这不起作用。

我做错了什么吗?

提前致谢。

I'm learning c++ and I'm trying to use a library that I've downloaded from internet in my program ( from here https://mattmccutchen.net/bigint/).
Because I want everything to be quite tidy, I put all the .hh files in a subfolder named "BI".
However when I try to compile my .cpp file with g++ (It's MinGW on Windows XP SP3), the compiler outputs the following error:


J:\comp proj\FS>J:\Programmi\MinGW\bin\g++.exe "J:\comp proj\FS\test.cpp" -o "J:\comp proj\FS\test.exe" -I "J:\comp proj\FS\BI"
E:\DOCUME~1\MrJackV\IMPOST~1\Temp\ccidH1Z6.o:test.cpp:(.text+0x2c): undefined reference to BigInteger::BigInteger(int)'
E:\DOCUME~1\MrJackV\IMPOST~1\Temp\ccidH1Z6.o:test.cpp:(.text+0x11b): undefined reference to
operator<<(std::ostream&, BigInteger const&)'
E:\DOCUME~1\MrJackV\IMPOST~1\Temp\ccidH1Z6.o:test.cpp:(.text$ZNK10BigIntegermlERKS[BigInteger::operator*(BigInteger const&) const]+0x29): undefined reference
to `BigInteger::multiply(BigInteger const&, BigInteger const&)'
collect2: ld returned 1 exit status

I've tried using the -I, -l and -L switches to fix the problem but with no success.
Moreover I've tried in the cpp to put #include "BI/BigIntegerLibrary.hh" but that didn't work.

Is there something I'm doing wrong?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

闻呓 2024-12-06 13:33:12

您需要同时使用 -L 和 -l 开关。 -L 指向包含库二进制文件的目录,-l 命名该二进制文件,

例如-L/home/ed/libs -lmath

You need to use both -L and -l switches. -L to point to the directory containing the library binary, -l to name that binary

e.g. -L/home/ed/libs -lmath

谈场末日恋爱 2024-12-06 13:33:12

有两个关键词需要记住。 Undeclared 表示编译器从未听说过它。 未定义表示编译器听说过它,但不知道到底如何使用它。对于这些错误,您需要告诉它与应该随标头一起提供的 BigInteger 库(*.lib 文件)链接,我很确定 gcc 是如何包含链接库的(Ed Heal 说 -L 和 -l,我会这样做)。

There's two keywords to keep in mind. Undeclared means the compiler has never heard of it. Undefined means the compiler has heard of it, but doesn't know exactly how to use it. For those errors you need to tell it to link with the BigInteger library that should have come with the headers (A *.lib file) I'm hot sure exactly how gcc includes link libraries (Ed Heal says -L and -l, I'd do that).

请止步禁区 2024-12-06 13:33:12

您的问题是您没有链接到库代码。
阅读“README”,然后按照其建议修改随附的 Makefile。

Your problem is that you didn't link with the library code.
Read the "README", then follow its advice to adapt the enclosed Makefile.

花开雨落又逢春i 2024-12-06 13:33:12

好吧,经过一番混乱之后,我发现我需要做几件事,

  1. 添加 -L 开关和头文件的目录,
  2. 将所有 .cc 文件(例如 g++ test.cpp BigInteger.txt)添加到 g++ 命令行。 cc 等)
  3. 为了简单起见,将所有内容放入批处理文件中

哇,现在看起来很容易!

Ok, so after some messing around I figured out that I needed to do a couple of things

  1. add the -L switch with the dir of the header files
  2. add to the g++ command line all the .cc files (e.g. g++ test.cpp BigInteger.cc etc.)
  3. put everything in a batch file for semplicity

wow, now it seems quite easy!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文