dynamic library gcc compilation error - c

I have the following code:
gcc -Wall -fno-stack-protector -O2 -g -fPIC -c ec.c
pwd
gcc -shared -Wl,-soname,libec.so.1 -o libec.so.1.0 ec.o /urs/src/soem/ethercat*.o ../soem/nicdrv.o -lc -lpthread
mv libec.so.1.0 /usr/lib/.
cd /usr/lib
ldconfig -v -n
ln -sf libec.so.1.0 libec.so
ln -sf libec.so.1.0 libec.so.1
It gives the following error when compiling:
/home/ebox/Documents/SVN/Libs/ec
gcc: error: /urs/src/soem/ethercat*.o: No such file or directory
mv: cannot stat ‘libec.so.1.0’: No such file or directory
I understand there is something wrong with the gcc command, but cannot figure out how to fix this. There are several .o files in the path that start with ethercat*.
How can I get this fixed?

The error means that there are no files that match the pattern /urs/src/soem/ethercat*.o.
Note that the first component is urs. Probably it should be usr.

Related

CS50 library in C

I am new to Ubuntu and new to C programming. Now I am watching cs50 videos to understand better about C and CS all together.
I tried to install this by using these guidelines:
Debian, Ubuntu
First become root, as with:
sudo su -
Then install the CS50 Library as follows:
apt-get install gcc
wget http://mirror.cs50.net/library50/c/library50-c-5.zip
unzip library50-c-5.zip
rm -f library50-c-5.zip
cd library50-c-5
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
chmod 0644 cs50.h libcs50.a
mkdir -p /usr/local/include
chmod 0755 /usr/local/include
mv -f cs50.h /usr/local/include
mkdir -p /usr/local/lib
chmod 0755 /usr/local/lib
mv -f libcs50.a /usr/local/lib
cd ..
rm -rf library50-c-5
I used it, and I think everything went as planned, but as soon as I try to run gcc demo.c I get a fatal error message:
adder.c:2:18: fatal error: cs50.h: No such file or directory
#include <cs50.h>
So as it seems that somewhere something went wrong and I don't really know how to fix it. Could anyone guide me a little bit how to fix it or how reinstall everything that C automatically would include that library?
check in the /usr/local/include directory for the cs50.h file
If it was not there, then one or more of the shell commands failed (or was skipped).
have you tried running gcc to compile/link the demo.c file via:
gcc -c -Wall -Wextra -pedantic -Wconversion -std=gnu99 demo.c -o demo.o -I/usr/local/include
gcc demo.o -o demo -L/usr/local/lib -lcs50
If your not sure what the above two lines do, just ask.
<CS50.h> exist on the CS50 IDE only. The functions it contains are string as a type def and the get functions.
If you use char * instead of string type
and
scanf() instead of get_(type)
You do not need it.
If you do need it I would just use the IDE in the course. It's free and halfway through the course they take the training wheels off.
Use -lcs50 in the end. Also specify the file where you want the machine code output using the -o parameter.
Run this to compile the program: gcc demo.c -o demo -lcs50
Run this to execute the program: ./demo

(node v8plus)example.c:5:26: fatal error: sys/ccompile.h: No such file or director

when I want to try out nodejs module 'v8plus' that lead to only use C to write nodejs addons, I try its example file, but it tell errors that is lacking files.
could anyone tell me that how to get these lacking library files and install? thanks.
all error codes output in ubuntu bash shell:
$ make
/usr/bin/gcc -DBUILDING_NODE_EXTENSION -DMODULE=example -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DPIC -isystem /usr/local/bin/../include/node -I. -I/media/2/pro/v8plus/node_modules/v8plus -g -Wall -Wextra -Werror -fPIC -O2 -std=c99 -c -o example.o example.c
example.c:5:26: fatal error: sys/ccompile.h: No such file or directory
compilation terminated.
make: *** [example.o] Error 1
makefile all content:
V8PLUS = ..
include /media/2/pro/v8plus/node_modules/v8plus/Makefile.v8plus.defs
MODULE = example
MODULE_DIR = .
SRCS = \
example.c
ERRNO_JSON = errno.json
PREFIX_NODE = /opt/local
CC = /usr/bin/gcc
CXX = /usr/bin/g++
PREFIX_NODE := $(shell dirname bash -c 'hash node; hash -t node')/..
V8PLUS := $(shell $(PREFIX_NODE)/bin/node -e 'require("v8plus");')
include /media/2/pro/v8plus/node_modules/v8plus/Makefile.v8plus.targ
v8plus is only compatible with illumos distros as noted in the v8plus faq ("What systems can I use this on?"). So you won't be able to get it to compile on Windows, Linux, BSD, or OS X for example without some major changes.

GDB doesn't find sources

I start gdb using this (working dir is /home/leon/Develop/tests/atomic/):
gdb ./bin/lin64/httpress
Then I add directories with source files, and it understands me:
Source directories searched: /home/leon/Develop/tests/atomic/third/http_parser:/home/leon/Develop/tests/atomic/src/tools:$cdir:$cwd
When I run my binary, gdb doesn't recognize the line in my source code, where segfault happened.
How to set source files for gdb?
The program is compiled by gcc:
gcc -D_AMD64_ -D_LIN_ -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -m64 -march=core2 -O2 -Wall -I. -I src/include -I src/lib/zlib/ -I src/lib/otg -I third/openssl/include/ -I src/lib/otg/Tools/HostTime/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Cross -I src/lib/otg/Tools/OpenToolsGate/Common/Interfaces/ -o bin/lin64/httpress -std=c99 -lpthread -lev -lgnutls -O2 -s -DWITH_SSL -Wno-strict-aliasing \
-I /usr/include/libev src/tools/httpress.c -I third/http_parser/ third/http_parser/http_parser.c
Ok, I've made some changes:
gcc -g -ggdb -D_AMD64_ -D_LIN_ -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -m64 -march=core2 -Wall -I. -I src/include -I src/lib/zlib/ -I src/lib/otg -I third/openssl/include/ -I src/lib/otg/Tools/HostTime/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Interfaces/ -I src/lib/otg/Tools/OpenToolsGate/Guest/Cross -I src/lib/otg/Tools/OpenToolsGate/Common/Interfaces/ -o bin/lin64/httpress -std=c99 -lpthread -lev -lgnutls -s -DWITH_SSL -Wno-strict-aliasing \
-I /usr/include/libev src/tools/httpress.c -I third/http_parser/ third/http_parser/http_parser.c
In this case it still can't find symbols in the binary.
But if I remove -s option from gcc call. It writes:
Reading symbols from /home/leon/Develop/tests/atomic/bin/lin64/httpress...done.
But the debugger still says this:
(gdb) info source
No current source file.
...after I point him directories with sources.
You miss the -g in your gcc call to include debugging information.
On the other hand, I suggest to decrease optimization level from -O2 to -O0 and use it only once (included gcc call has 2 -O2).
Apart of this, you can add directories to gdb's source path with dir command: Source_Path. But this would only work if you've proper debug information available in httpress
But the debugger still says this:
(gdb) info source
No current source file.
...after I point him directories with sources.
This is expected. There is no current source because you haven't started executing your binary yet.
You want to start or run your binary and get it to some place in execution (e.g. main, or the crash point).
Remove optimize flag :
-O2
And add that flags:
-g -ggdb

GCC compile with mysql library

when I try to compile a self written project in C with includes the mysql libraries I get this error:
gcc -c src/oDAO.c
src/oDAO.c:4:23: fatal error: my_global.h: No such file or directory
I included the my_global.h as following:
#include <my_global.h>
The error comes up, because my system copied the header files to /usr/include/mysql/ and gcc is searching for system header files only in /usr/include (without subdirectories). How can I call gcc with adding /usr/include/mysql as additional shared library root?
Here is my acutal Makefile:
all: main.o oDAO.o FileUtils.o DVDDAO.o
gcc -Llib -o oDAO main.o oDAO.o FileUtils.o DVDDAO.o -llinkedlist -lncurses `mysql_config --cflags --libs`
main.o:
gcc -c src/main.c
oDAO.o:
gcc -c src/oDAO.c
FileUtils.o:
gcc -c src/FileUtils.c
DVDDAO.o:
gcc -c src/DVDDAO.c
clean:
rm -f *.o
rm -f oDAO
rm -f *.bak
rm -f *.~
I've got the answer on my own:
Everytime i try to compile a .c file that includes a mysql library into an object file I have to compile it like that:
gcc -c DVDDAO.c `mysql_config --cflags`
Then everything works fine
Try the option -I for adding a include directory and -L for adding a libary directory.

Why can't gcc find my static library?

I am trying to link the cspec library into my C project. This is my Makefile located in the tests folder:
all: test
test: sample.o
gcc -Wall -o test sample.o -L ../lib/cspec -llibcspec.a
sample.o: sample.c
gcc -Wall -c sample.c -I../lib/cspec
clean:
rm -rf *o test
My directory is:
/
/src
/lib
/lib/cspec
/tests
When I run make I receive the following error:
gcc -Wall -o test sample.o -L ../lib/cspec -llibcspec.a
/usr/bin/ld: cannot find -llibcspec.a
I have made sure that the the libcspec.a file is located in the lib/cspec folder but to be sure I have also tried placing it within the tests folder and removing the -L command, to no avail.
Change:
gcc -Wall -o test sample.o -L ../lib/cspec -llibcspec.a
to:
gcc -Wall -o test sample.o -L ../lib/cspec -lcspec
(By convention, gcc and other *nix compilers automatically add the lib prefix and the appropriate suffix.)

Resources