Harvard CS50 Library , Need Help Installing on Mac OS X

给你一囗甜甜゛ 提交于 2020-01-06 04:55:05

问题


I'm taking this course from cs50.tv, which is Harvard extension school and in the course they are using a library they made called cs50 , on this link its available for download

https://manual.cs50.net/CS50_Library#Mac_OS

I downloaded the zip file and unzipped it, and then I open the terminal and cd my way to the library directory, but every time I follow the steps in the manual.

Right after I do this command gcc -c -ggdb -std=c99 cs50.c -o cs50.o

I get this error in the terminal

cs50.c:15:16: error: gc.h: No such file or directory
cs50.c: In function ‘GetString’:
cs50.c:207: warning: implicit declaration of function ‘GC_FREE’
cs50.c:212: warning: implicit declaration of function ‘GC_REALLOC’
cs50.c:212: warning: initialization makes pointer from integer without a cast
cs50.c:230: warning: implicit declaration of function ‘GC_MALLOC’
cs50.c:230: warning: initialization makes pointer from integer without a cast

Would really appreciate if anyone can help.


回答1:


gc.h comes from the Boehm Garbage Collector. You can download it from here:

http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc-7.0.tar.gz

Unpack it, then do ./configure && make && sudo make install. This will install the header into /usr/local/include/gc, you will need to tell gcc to go look for it there:

gcc -I/usr/local/include/gc -c -ggdb -std=c99 cs50.c -o cs50.o




回答2:


If you trying to use gcc to compile the cs50.h library, I have found that to be unsuccessful on most modern 64 bit macs. Xcode 4.x generally wants a 64 bit compatible library format. GCC has not been updated to include 64 bit object files. Clang/LLVM is a rising alternative to gcc, and is used by Apple for Xcode as their preferred compiler engine. I have not personally tried it yet, but will be exploring Xcode to produce a compatible library for Xcode. I am taking the Harvardx cs50x course at edX, and it is great course, even for experienced programmers. The cs50.h library is interesting, because it provides relatively robust I/O routines for various variable types, e.g. String, Integer. float for the c programming language, including good protection for buffer overflow attacks.



来源:https://stackoverflow.com/questions/6963640/harvard-cs50-library-need-help-installing-on-mac-os-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!