编译C错误-CS50课程 - 第1周-Linux

发布于 2025-02-05 10:26:01 字数 453 浏览 2 评论 0原文

我正在尝试通过遵循教授所做的步骤来编译一个简单的代码,但是我

cc     calculator.c   -o calculator
/usr/bin/ld: /tmp/ccznJMZB.o: in function `main':
calculator.c:(.text+0x19): undefined reference to `get_int'
/usr/bin/ld: calculator.c:(.text+0x2d): undefined reference to `get_int'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: calculator] Error 1

使用的是Linux Mint BTW的问题,已经在安装CS50库时遇到了问题,但这已经完成了。我很乐意收到一个新的错误,但是我需要修复它。 谢谢!

i'm trying to compile a simple code by following the steps that the professor made but I have this issue

cc     calculator.c   -o calculator
/usr/bin/ld: /tmp/ccznJMZB.o: in function `main':
calculator.c:(.text+0x19): undefined reference to `get_int'
/usr/bin/ld: calculator.c:(.text+0x2d): undefined reference to `get_int'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: calculator] Error 1

I'm using Linux mint btw, already had problems installing cs50 library but that's done. I'm happy to get a new error tho, but I need to fix it.
Thanks!

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

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

发布评论

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

评论(1

随波逐流 2025-02-12 10:26:01

参见 https://cs50.readthedocs.io/libraries/cs50/cs50/c/

要使用这些功能,请确保包括#include&lt; cs50.h&gt;在您的文件上方并使用-LCS50 flag进行编译。

#include&lt; cs50.h&gt;需要标题文件cs50.h在编译器的包含路径中。

#include“ cs50.h”期望标题文件cs50.h与您的.c .c文件处于同一目录。

上面的链接还告诉您如何安装库:

$ curl -s https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | sudo bash
$ sudo apt install libcs50

故障排除

如果编译程序时,您会看到:

/usr/bin/ld:找不到-lcs50:
将导出library_path =/usr/local/lib添加到您的.bashrc。

致命错误:未找到'CS50.H'文件:
添加导出c_include_path =/usr/local/include indor your .bashrc。

无法打开共享对象文件:没有这样的文件或目录:
将fort ld_library_path =/usr/local/lib添加到.bashrc。

See https://cs50.readthedocs.io/libraries/cs50/c/

To use these functions, make sure to include #include <cs50.h> atop your file and compile with the -lcs50 flag.

#include <cs50.h> requires the header file cs50.h to be in the include path of your compiler.

#include "cs50.h" expects the header file cs50.h to be in the same directory as your .cfile.

The link above also tells you how to install the library:

$ curl -s https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | sudo bash
$ sudo apt install libcs50

Troubleshooting

If when compiling your program, you see:

/usr/bin/ld: cannot find -lcs50:
Add export LIBRARY_PATH=/usr/local/lib to your .bashrc.

fatal error: 'cs50.h' file not found:
Add export C_INCLUDE_PATH=/usr/local/include to your .bashrc.

cannot open shared object file: No such file or directory:
Add export LD_LIBRARY_PATH=/usr/local/lib to your .bashrc.

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