0

I was auditing cs107 at stanford online

The problem I ran into is with assignment 6, when I type "make" in terminal, the error message pops up. Basically, I miss two header files, which I guess can be got from the pre-compiled .lib file. But somehow it just doesn't work.

Here's part of the original make file:

CFLAGS = -D_REENTRANT -g -Wall -D__ostype_is_$(OSTYPE)__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function $(DFLAG)
LDFLAGS = -L/usr/class/cs107/assignments/assn-6-rss-news-search-lib/$(OSTYPE) -L/usr/class/cs107/lib -lexpat -lrssnews $(PLATFORM_LIBS) $(THREAD_LIBS)
PFLAGS= -linker=/usr/pubsw/bin/ld -best-effort -threads=yes -max-threads=1000

Edit:

When I said "This is supposed to compile even without threading implementation", I meant that it should compile without FURTHER threading implementation by students.

So here's the error message with thread:

gcc -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
rss-news-search.c: In function ‘main’:
rss-news-search.c:109:3: warning: implicit declaration of function ‘InitThreadPackage’ [-Wimplicit-function-declaration]
gcc rss-news-search.o -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -L/home/h/cs107/assn-6-rss-news-search-lib/linux -L/usr/class/cs107/lib -L. -lexpat -lrssnews -lnsl -lpthread -lthread_107_linux -o rss-news-search
/usr/bin/ld: cannot find -lthread_107_linux
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1

here's the error message without $(THREAD_LIBS):

gcc -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
rss-news-search.c: In function ‘main’:
rss-news-search.c:109:3: warning: implicit declaration of function ‘InitThreadPackage’ [-Wimplicit-function-declaration]
gcc rss-news-search.o -D_REENTRANT -g -Wall -D__ostype_is_linux__ -std=gnu99 -I/usr/class/cs107/include/ -Wno-unused-function -L/home/h/cs107/assn-6-rss-news-search-lib/linux -L/usr/class/cs107/lib -L. -lexpat -lrssnews -lnsl -lpthread  -o rss-news-search
rss-news-search.o: In function `main':
/home/h/cs107/assn-6-rss-news-search/rss-news-search.c:109: undefined reference to `InitThreadPackage'
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1

In the later case, if I comment out "InitThreadPackage", it compiles just fine.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
  • 1
    Post the makefile, or some links to the assignment resources. We don't have enough information to help you. – TOC Aug 12 '12 at 20:10
  • hi, thanks for your comment. The assignment file can be found here http://see.stanford.edu/see/materials/icsppcs107/assignments.aspx which include a make file. It's Assignment 6. – user1105360 Aug 12 '12 at 20:19
  • Thanks and the link is this : http://see.stanford.edu/materials/icsppcs107/assn-6-rss-news-search.zip? – TOC Aug 12 '12 at 20:22
  • Yes. That one contains a make file. And the one right below it has the .lib files. – user1105360 Aug 12 '12 at 20:24

2 Answers2

1

The class-specific header files, like thread_107.h are found in /usr/class/cs107/include/ on whatever machine the instructor is expecting the students to use. If you're not using that machine, you'll have to copy those include files or make your own.

The expat.h file is from an open source library. You'll need to install the appropriate package on the system you're compiling on. On Ubuntu, that's sudo apt-get install libexpat1-dev, but the package name should be similar on other distributions.

Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
  • Thank you! Karl. I think I can get the expat.h. But how do I make my own thread_107.h? I'm sorry I am still new to cs. – user1105360 Aug 12 '12 at 20:16
  • You just make a file with that name, and when the compiler complains about unknown functions, you put a matching function declaration in there. – Karl Bielefeldt Aug 12 '12 at 20:23
1

This is the procedure to compile your project:

  1. Create a file assn-6-rss-news-search/thread_107.h, and put this inside:

    /* Empty header file */

  2. Copy the library librssnews.a from assn-6-rss-news-search-lib/linux/ to assn-6-rss-news-search/

  3. Modify the file rss-news-search.c by commenting the call to the function : InitThreadPackage on line 109:

    //InitThreadPackage(false);

  4. Modify the Makefile to include the path to the current directory (to be able to link to the library you've copied earlier librssnews.a):

The line 27 should look like this:

LDFLAGS = -L/usr/class/cs107/assignments/assn-6-rss-news-search-lib/$(OSTYPE) -L/usr/class/cs107/lib -L. -lexpat -lrssnews $(PLATFORM_LIBS) $(THREAD_LIBS)

Then:

make clean
make

EDIT :

When you got this error cannot find lthread_107_linux, Edit your Makefile to remove this $(THREAD_LIBS) on line 27:

LDFLAGS = -L/usr/class/cs107/assignments/assn-6-rss-news-search-lib/$(OSTYPE) -L/usr/class/cs107/lib -L. -lexpat -lrssnews $(PLATFORM_LIBS)
TOC
  • 4,326
  • 18
  • 21
  • Now it prompts "cannot find lexpat" and "cannot find lthread_107_linux". – user1105360 Aug 12 '12 at 22:33
  • As Karl said if you are on Ubuntu install libexpat (sudo apt-get install libexpat1-dev) – TOC Aug 12 '12 at 22:38
  • Cheers~~The first one is gone~~~ One more to go~~YEAH! – user1105360 Aug 12 '12 at 22:46
  • Thanks, it's gone too. But once I brings back InitThreadPackage on line 109 in rss-news-search.c. Another one comes up that says it's undefined. The assignment 6 is all about multithreading. Without $(THREAD_LIBS), the whole assignment wouldn't be accomplished. – user1105360 Aug 12 '12 at 23:06
  • Sorry, i don't understand! We talk here about assn-6-rss-news-search, and there is no threading inside except the line 109 and i tell you to comment it. Are you trying another project or what? – TOC Aug 12 '12 at 23:22
  • Sorry I didn't make this clear before. The goal of that assignment is to build a Multithreaded RSS News Aggregator. rss-news-search.c is the starter code for students. This is supposed to compile even without threading implementation. – user1105360 Aug 12 '12 at 23:47
  • YES, IT COMPILE ON MY MACHINE! PLEASE POST YOUR ERRORS HERE (BY EDITING YOUR POST) – TOC Aug 13 '12 at 00:15