undefined reference to 'check_nan' - c

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.

Related

C Makefile - Cannot find library -lrssnews

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.

Littlecms - error during compiling "undefined reference to `cmsOpenProfileFromFile' "

Please help me to use LittleCMS framework - I'm receiving
" undefined reference to `cmsOpenProfileFromFile' "
I had made:
1) Downloaded from https://github.com/mm2/Little-CMS file lcms2.h
2) Downloaded https://sourceforge.net/projects/lcms/and tried to install it like it written in documentation (downloaded tar file, unTARed it, runned
./configure
make
sudo make install
3) Tried to implement a sample from tutorial:
#include "lcms2.h"
int main(void)
{
cmsHPROFILE hInProfile, hOutProfile;
cmsHTRANSFORM hTransform;
hInProfile = cmsOpenProfileFromFile("AdobeRGB1998.icc", "r");
hOutProfile = cmsOpenProfileFromFile("WebCoatedSWOP2006Grade5.icc", "r");
hTransform = cmsCreateTransform(hInProfile, TYPE_BGR_8, hOutProfile, TYPE_BGR_8, INTENT_PERCEPTUAL, 0);
cmsCloseProfile(hInProfile);
cmsCloseProfile(hOutProfile);
return 0;
}
After runing "make" I had received " undefined reference to `cmsOpenProfileFromFile' ".
I think I have to install some library (and I have to add something like this -L/opt/local/lib64 -llcms2 to a makefile or add it to clang ...), but I had read kilobytes of webpages and no one is telling how to do it from scratch - libraries does not appears in folder /opt/local/lib64 or /opt/local/lib (and I cannot find lcms2 in any directory) .
My IDE is: CS50 IDE, Linux version 4.9.17-c9 (root#30db80bfe262) (gcc version 4.9.2 (Debian 4.9.2-10) ).
I am very new in programming, so please, be condescending.
Please help me to solve and to inmplement Little CMS.
Update:
3 types of compilations:
1) Command prompt (internal IDE's makefile, without my Makefile):
~/workspace/cmyk/ $ make cmyk
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow -c -o cmyk.o cmyk.c
clang cmyk.o -lcrypt -lcs50 -lm -o cmyk
cmyk.o: In function `main':
/home/ubuntu/workspace/cmyk/cmyk.c:9: undefined reference to `cmsOpenProfileFromFile'
/home/ubuntu/workspace/cmyk/cmyk.c:10: undefined reference to `cmsOpenProfileFromFile'
/home/ubuntu/workspace/cmyk/cmyk.c:12: undefined reference to `__ubsan_handle_shift_out_of_bounds'
/home/ubuntu/workspace/cmyk/cmyk.c:12: undefined reference to `__ubsan_handle_shift_out_of_bounds'
/home/ubuntu/workspace/cmyk/cmyk.c:12: undefined reference to `__ubsan_handle_shift_out_of_bounds'
/home/ubuntu/workspace/cmyk/cmyk.c:12: undefined reference to `__ubsan_handle_shift_out_of_bounds'
/home/ubuntu/workspace/cmyk/cmyk.c:12: undefined reference to `__ubsan_handle_shift_out_of_bounds'
cmyk.o:/home/ubuntu/workspace/cmyk/cmyk.c:12: more undefined references to `__ubsan_handle_shift_out_of_bounds' follow
cmyk.o: In function `main':
/home/ubuntu/workspace/cmyk/cmyk.c:12: undefined reference to `cmsCreateTransform'
/home/ubuntu/workspace/cmyk/cmyk.c:14: undefined reference to `cmsCloseProfile'
/home/ubuntu/workspace/cmyk/cmyk.c:15: undefined reference to `cmsCloseProfile'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [cmyk] Error 1
2) Makefile1 (with clang):
CC = clang
CFLAGS = -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror
EXE = cmyk
HDRS = lcms2.h
LIBS =
SRCS = cmyk.c
OBJS = $(SRCS:.c=.o)
$(EXE): $(OBJS) $(HDRS) Makefile
$(CC) $(CFLAGS) -o $# $(OBJS) $(LIBS)
$(OBJS): $(HDRS) Makefile
clean:
rm -f core $(EXE) *.o
Output:
~/workspace/cmyk/ $ make cmyk
clang -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror -c -o cmyk.o cmyk.c
clang -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror -o cmyk cmyk.o
cmyk.o: In function `main':
/home/ubuntu/workspace/cmyk/cmyk.c:9: undefined reference to `cmsOpenProfileFromFile'
/home/ubuntu/workspace/cmyk/cmyk.c:10: undefined reference to `cmsOpenProfileFromFile'
/home/ubuntu/workspace/cmyk/cmyk.c:12: undefined reference to `cmsCreateTransform'
/home/ubuntu/workspace/cmyk/cmyk.c:14: undefined reference to `cmsCloseProfile'
/home/ubuntu/workspace/cmyk/cmyk.c:15: undefined reference to `cmsCloseProfile'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [cmyk] Error 1
3) Makefile2:
iEdit: cmyk.o
gcc $^ -o $# -std=c99
.c.o:
gcc -c $< -std=c99
cmyk.o: lcms2.h
Output:
~/workspace/cmyk/ $ make cmyk
gcc -c cmyk.c -std=c99
clang cmyk.o -lcrypt -lcs50 -lm -o cmyk
cmyk.o: In function `main':
cmyk.c:(.text+0x13): undefined reference to `cmsOpenProfileFromFile'
cmyk.c:(.text+0x26): undefined reference to `cmsOpenProfileFromFile'
cmyk.c:(.text+0x50): undefined reference to `cmsCreateTransform'
cmyk.c:(.text+0x60): undefined reference to `cmsCloseProfile'
cmyk.c:(.text+0x6c): undefined reference to `cmsCloseProfile'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [cmyk] Error 1
Solution is to use other IDE - CS50 IDE does not allowed to install additional libraries. I had installed VirtualBox, mounted xubuntu, installed lib, added -L/usr/local/lib -llcms2 to Makefile and my program was compiled without errors.

Unable to make shared library while embedding Python to C

I am trying to make a shared library which consists of one C header file and two C source files, one of which calls a Python file for implementation.
The compilation comand used is
gcc -fPIC -c -I-I/usr/local/include -I/usr/local/include -I/usr/local/include/python3.4m -I/usr/local/include/python3.4m -DNDEBUG -g -fwrapv -O0 -Wall -Wstrict-prototypes -DDOUBLE_PRECISION *.c
I am able to compile all these without any error, but when I try to make a shared object file using the following command
gcc *.o -L/usr/local/lib -lpthread -ldl -lutil -lm -Xlinker -export-dynamic /usr/local/lib/python3.4/config-3.4m/libpython3.4m.a -shared -o libroughness.so
I get the following error which I am unable to resolve
/usr/bin/ld: /usr/local/lib/python3.4/config-3.4m/libpython3.4m.a(abstract.o): relocation R_X86_64_32S against `_PyObject_NextNotImplemented' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/python3.4/config-3.4m/libpython3.4m.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
I am using -fPIC tag while compilation, however it still asks me to recompile with fPIC. Any help on how to resolve this case would be appreciated.

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.

Linker error: undefined reference to shared object

I am trying to use an external library called iniparser in my C program. I'm using gcc 4.4.
I put the iniparser library in a subdirectory called lib/ header files are in lib/iniparser/src and the library is compiled to lib/iniparser/libiniparser.so.0.
I wrote a short Makefile to compile it, here's the output of make:
gcc -Wall -Wextra -Werror -c -I include/ src/smag_main.c -L lib/iniparser -liniparser -I lib/iniparser/src
gcc -Wall -Wextra -Werror -c -I include/ -L lib/iniparser -liniparser -I lib/iniparser/src src/agros.c
gcc -Wall -Wextra -Werror -c -I include/ -L lib/iniparser -liniparser -I lib/iniparser/src src/main.c
gcc -Wall -Wextra -Werror -L lib/iniparser -liniparser -o agros smag_main.o main.o agros.o
smag_main.o: In function `sec_haskey':
smag_main.c:(.text+0xa9): undefined reference to `iniparser_find_entry'
smag_main.o: In function `parse_config':
smag_main.c:(.text+0x153): undefined reference to `iniparser_load'
smag_main.c:(.text+0x18b): undefined reference to `iniparser_getint'
smag_main.c:(.text+0x1c6): undefined reference to `iniparser_getstring'
smag_main.c:(.text+0x202): undefined reference to `iniparser_getstring'
smag_main.c:(.text+0x261): undefined reference to `iniparser_getstring'
smag_main.c:(.text+0x2c2): undefined reference to `iniparser_getint'
smag_main.c:(.text+0x2d5): undefined reference to `iniparser_freedict'
collect2: ld returned 1 exit status
make: *** [agros] Error 1
First call to gcc compiles smag_main.o successfully, the second one compiles agros.o and the third one main.o. The 4th call is the linker, that will link all those objects into an executable agros. It obviously fails.
It looks like it has problems locating iniparser.so at linking time. How's my call wrong?
I am confused.
(Alternate question, if anyone could explain how to the linking by calling ld directly it would be great).
Try putting a symlink from libiniparser.so.0 to libiniparser.so
cd lib/iniparser/
ln -s libiniparser.so.0 libiniparser.so

Resources