编译和链接 32 位架构的 C 程序
因此,我正在完成斯坦福大学 CS107 课程的作业,但我无法编译未完成的程序(项目文件和原始 makefile 可以是在课程页面上找到,我正在做作业 4 RSS。)
经过大量研究,我认为< /em> 问题是我在 64 位架构(Mac OS 10.6)上使用 gcc 以及 assn-4-rss-news-search-lib/linux
下的预编译库代码适用于 32 位架构。我尝试将 gcc 设置为使用 i386 和 -m36,但没有任何效果,我只是猜测。
所以这是我运行 make
时得到的输出:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lnsl -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: library not found for -lnsl
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
这是当我删除 -lnsl
时得到的输出,其中提到了架构差异:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: warning: in /Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux/librssnews.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols:
"_URLConnectionDispose", referenced from:
_ProcessFeed in rss-news-search.o
_ParseArticle in rss-news-search.o
... several more undefined symbols mentioned ...
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
所以我询问有关的任何想法我能做些什么来解决这个问题。我已经调整设置好几个小时了,谷歌搜索也无济于事。
So I'm working through an assignment for Stanford's CS107 course and I can't get past compiling the unfinished program (project files and the original makefile can be found on the course page, I'm working on assignment 4 RSS.)
After much research, I think the problem is I'm using gcc on a 64-bit architecture (Mac OS 10.6) and the pre-compiled library code under assn-4-rss-news-search-lib/linux
is for a 32-bit architecture. I tried setting gcc to use i386 and -m36, but nothings working and I'm kind of just guessing.
So here's the output I get when I run make
:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lnsl -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: library not found for -lnsl
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
Here's the output I get when I remove -lnsl
where architecture differences are mentioned:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: warning: in /Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux/librssnews.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols:
"_URLConnectionDispose", referenced from:
_ProcessFeed in rss-news-search.o
_ParseArticle in rss-news-search.o
... several more undefined symbols mentioned ...
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
So I'm asking for any ideas on what I could do to resolve this. I've been at it for hours tweaking settings and Google'ing around to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
万一像我这样的人在这么长时间过去后仍在寻找答案......
通过安装 32 位 Ubuntu 的 wubi 版本,问题很容易解决。在64位系统上运行良好。您只需要编辑 makefile,以便它知道在哪里查找提供的库。
In case someone like me will be looking for answer after all this time passed...
Problem is easy solved by installing wubi version of 32bit Ubuntu. It works fine on 64bit system. You only need to edit makefile so it knows where to look for the libraries provided.
我非常确定,在 MacOS 上使用 Linux 的预编译库,无论位数如何,都行不通(好吧,可能可以在 MacOS 上针对 Linux 进行交叉编译,并且也许可以在MacOS 上的兼容性框,但这与您想要做的完全不同)。
libnsl是Linux上的一个标准库(它提供了一些网络相关的功能)
I'm pretty sure that using a precompiled library for linux on macos, whatever the bitness, won't work (well, it is probably possible to cross-compile on MacOS for Linux and perhaps possible to run Linux executable in a compatibility box on MacOS, but that's quite different than what you are trying to do).
libnsl is a standard library on Linux (it provides some networking related functions)