C Makefile - Cannot find library -lrssnews - c

I have reviewed the answer provided Here but I still cannot seem to make progress.
I am attempting to follow along with the online Stanford course CS107. I was able to complete assignments 2-3 but am stuck on assignment number 4.
I receive this error when I type "make" in the command line.
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/home/pi/Desktop/C/StanfordHW/Assn4/assn-4-rss-news-search-lib/ -o rss-news-search
/usr/bin/ld: cannot find -lrssnews
collect2: error: ld returned 1 exit status
make: *** [Makefile:32: rss-news-search] Error 1
Here is the snippet of my Makefile:
CFLAGS = -g -Wall -std=gnu99 -Wno-unused-function $(DFLAG)
LDFLAGS = -g $(SOCKETLIB) -lnsl -lrssnews -L/home/pi/Desktop
/C/StanfordHW/Assn4/assn-4-rss-news-search-lib/$(OSTYPE)
PFLAGS= -linker=/usr/pubsw/bin/ld -best-effort
So, I tried doing what the previous answer suggested by moving the file "librssnews.a" to the folder /lib from where I am executing the make command. But this did not work.
Here is an image of my directory
Is there something else that I can try? Please excuse any obvious mistakes, as I'm still learning. Thank you.

Related

C how do i import/link glfw with gcc on linux

this shit doesn't work. why?
gcc -c -Wall src/*.c -g -m64 && gcc -Iinclude *.o -o bin/debug/main -Lusr/local/lib -l libglfw && ./bin/debug/main
i get this linking error when trying to build the glfw window example
/usr/bin/ld: cannot find -l libglfw
collect2: error: ld returned 1 exit status
How do i import/link glfw and what is going wrong? I tried dynamically linking from usr/lib/x86_64-linux-gnu/libglfw.so but it didn't help. I'm pretty new to gcc and linux so i could just be stupid.
EDIT:
the comments pointed out a few mistakes i made so here's the new command, which is wrong too for some reason:
gcc -c -Wall src/*.c -g -m64 && gcc -Iinclude *.o -o bin/debug/main -L/usr/local/lib -lglfw && ./bin/debug/main
the new error:
/usr/bin/ld: main.o: in function `main':
/home/basti/dev/OpenGL/src/main.c:26: undefined reference to `glClear'
collect2: error: ld returned 1 exit status
I figured it out. Thanks to comments i managed to fix linking and didn't realize i had to import other opengl stuff.
In case somone is searching for an answer to the same problem here's my debug build command for sublime text 3:
gcc -c -Wall src/*.c -g -m64 && gcc -Iinclude *.o -o bin/debug/main -lglfw -lGLU -lGL && ./bin/debug/main

installed check for c but "check.h" not found

Im using windows 10 with wsl ubuntu 18.04 Im trying to run the code from here :
https://www.ccs.neu.edu/home/skotthe/classes/cs5600/fall/2015/labs/intro-check-lab-code.tgz
I installed gcc, makefile, and check in the ubuntu terminal. But when I di $ make it says:
gcc money.o check_money.o -lcheck -lm -lpthread -lrt -lgcov -coverage -o check_money_tests
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcheck.a(check_log.o): In function `subunit_lfun':
(.text+0x5f4): undefined reference to `subunit_test_start'
(.text+0x6bf): undefined reference to `subunit_test_fail'
(.text+0x6d4): undefined reference to `subunit_test_pass'
(.text+0x6ef): undefined reference to `subunit_test_error'
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'check_money_tests' failed
make: *** [check_money_tests] Error 1
so I open the check_money.c it says that check.h cannot be found. What did I miss here?
Simple version: you should also link with -lsubunit flag, i.e.:
TST_LIBS = -lcheck -lm -lpthread -lrt -lsubunit
Better yet, all the flags should be taken from check's package configuration, as the requirements depend on how the check library was built (and that's what pkg-config has been invented for). So instead of hardcoding your options, you could improve your Makefile like this:
CFLAGS = -c -Wall $(shell pkg-config --cflags check)
TST_LIBS = $(shell pkg-config --libs check)
Result:
$ make
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage src/*.c
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage tests/*.c
gcc money.o check_money.o -lcheck_pic -pthread -lrt -lm -lsubunit -lgcov -coverage -o check_money_tests
...

undefined reference to 'check_nan'

I'm trying to compile the file (glove.c from Stanford NLP https://github.com/stanfordnlp/GloVe/blob/master/src/glove.c) but I'm getting an undefined reference error.
aerin#capa:~/Desktop/GloVe/src$ gcc -pthread glove.c -o glove.out -lm
/tmp/ccZMsGyg.o: In function `glove_thread':
glove.c:(.text+0x9d7): undefined reference to `check_nan'
glove.c:(.text+0xa6a): undefined reference to `check_nan'
collect2: error: ld returned 1 exit status
I can't find the answer about "check_nan" on google. What flag should I use to compile this file? Any tip will greatly help!
If you look in the makefile for the full project, you'll see that some options are being passed that you aren't including:
CFLAGS = -lm -pthread -Ofast -march=native -funroll-loops -Wall -Wextra -Wpedantic
...
glove : $(SRCDIR)/glove.c
$(CC) $(SRCDIR)/glove.c -o $(BUILDDIR)/glove $(CFLAGS)
The flag in pariticular you're missing is -Ofast. Add that and it should compile fine.
Alternately, just run make from the top level directory to build everything.

using C and cuda create shared library got error at link stage

I was really struggled with this error when I try to build a shared library. My code utilize the Lapacke library and also CUDA. when I compile them, there are no errors(I compile them as)
gcc -m64 -Wall -fPIC -c xxx.c -o xxx.o $(INC)
where INC includes all directories
INC=-I. -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/linux/ I$/home/sniu/lapack-3.5.0/lapacke/include/ -I${CUDA_INSTALL_PATH}/include/ -I/home/sniu/CBLAS/include/
for cuda part, I wrote it as:
nvcc -m64 -arch=sm_20 -Xcompiler -fPIC $(INC) -c xxx.cu -o xxx.o
but I got the error message at the link stage:
gcc -m64 -D_REENTRANT -Wall -fPIC -g -shared -o libjniWrapper.so jniWrapper.o cholesky_inv.o wls_acc.o utils.o -L/home/sniu/lapack-3.5.0 -L/opt/cuda-toolkit/5.5.22/lib64 -lm -llapacke -llapack -lblas -lgfortran -lrt -lcudart -lcublas -ldl
/usr/bin/ld: /home/sniu/lapack-3.5.0/liblapacke.a(lapacke_dpotrf.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/home/sniu/lapack-3.5.0/liblapacke.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
I am very sure libraries are there, I really confused why I got this error.
Any suggestions are appreciated, Thank you so much!

CS107 Assignment file couldn't compile, missing expat.h and thread_107.h files

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.
This is the procedure to compile your project:
Create a file assn-6-rss-news-search/thread_107.h, and put this inside:
/* Empty header file */
Copy the library librssnews.a from assn-6-rss-news-search-lib/linux/ to assn-6-rss-news-search/
Modify the file rss-news-search.c by commenting the call to the function : InitThreadPackage on line 109:
//InitThreadPackage(false);
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)
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.

Resources