I have the redis server installed, and can use it from the command line. Now, I am wanting to write a client program using hiredis. To begin with, I tried to compile example.c which is present in the hiredis directory:
vishal#expmach:~/redis-2.6.14/deps/hiredis$ ls
adapters async.h COPYING dict.h *example.c* example-libevent.c
hiredis.c Makefile net.h sds.c test.c async.c CHANGELOG.md dict.c example-
ae.c example-libev.c fmacros.h hiredis.h net.c README.md sds.h
Here are the commands:
vishal#expmach:~/redis-2.6.14/deps/hiredis$ gcc -c -I hiredis example.c
vishal#expmach:~/redis-2.6.14/deps/hiredis$ gcc -o example -I hiredis -L hiredis -lhiredis -lm
/usr/bin/ld: cannot find -lhiredis
collect2: ld returned 1 exit status
I am not sure how to go about fixing this. Please help.
gcc -o example example.c -lhiredis $(pkg-config --cflags --libs glib-2.0)
why don't you juste juste the provided Makefile?
make
./hiredis-example
Related
I want to compile my own Apache module when building my image, so i wrote the following Dockerfile.
FROM httpd:2.4.25
COPY conf/httpd.conf /usr/local/apache2/conf/httpd.conf
COPY modules/mod_example.c /usr/local/apache2/modules/mod_example.c
RUN apxs -i -a -c modules/mod_example.c
EXPOSE 80
But i get an error :
/usr/share/apr-1.0/build/libtool --silent --mode=compile x86_64-linux-gnu-gcc -std=gnu99 -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/local/apache2/include -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -c -o mod_example.lo mod_example.c && touch mod_example.slo
/usr/share/apr-1.0/build/libtool: line 1114: x86_64-linux-gnu-gcc: command not found
apxs:Error: Command failed with rc=65536
I tried apt-get install gcc or libtool it say it's unable to locate the package.
My goal is to compile the ".c" file in a ".so" file.
Installing gcc, or the build-deps of say libapr1, is all that's needed. You probably just have a problem with your unspecified attempt at adding the compiler from your dockerfile.
For referene, here's how the httpd layer adds the compiler:
https://github.com/docker-library/httpd/blob/master/2.4/Dockerfile
I needed to do an apt-get update then :
apt-get install build-essential libtool
Since the docker image is a prod image, it doesn't contain dev tools.
I'm trying to compile nginx with custom openssl »libressl« using this script: https://gist.github.com/Belphemur/3c022598919e6a1788fc
Everything works fine using libressl 2.1.1.
Problem is that libressl 2.1.1 has some security issues, which have been resolved by newer releases.
However I can't get the build to work with libressl 2.1.2 or libressl 2.1.3 (latest version).
The issue I get:
..
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /tmp/build/pcre-8.36 -I /tmp/build/libressl-2.1.2/.openssl/include -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
In file included from /usr/include/string.h:635:0,
from /tmp/build/libressl-2.1.2/.openssl/include/string.h:6,
from src/os/unix/ngx_linux_config.h:27,
from src/core/ngx_config.h:26,
from src/core/nginx.c:8:
/tmp/build/libressl-2.1.2/.openssl/include/string.h:29:8: error: expected identifier or ‘(’ before ‘__extension__’
char * strndup(const char *str, size_t maxlen);
^
make[1]: *** [objs/src/core/nginx.o] Error 1
make[1]: Leaving directory `/tmp/build/nginx-1.7.9'
make: *** [build] Error 2
All done.
..
What's the problem & how to resolve it?
Thanks for helping.
I'm the creator of the script you use to build Nginx with LibreSSL.
It is now corrected, the previous way to build and use libressl doesn't work with previous version of the script. (Simply copying all the include and stripping the lib)
The script now install libressl in a set directory and give it to nginx, this way, all the include not needed to use the library (like this string.h) is not part of the building process of nginx.
strndup is provided in string.h. You don't need to provide it here:
/tmp/build/libressl-2.1.2/.openssl/include/string.h:29:8: error: expected identifier or ‘(’ before ‘__extension__’
char * strndup(const char *str, size_t maxlen);
I would delete the copy of string.h from the sources, and use the platform's supplied string.h for strndup.
As a matter of fact, I don't know where that string.h is coming from because its not present on my system (and I regularly build and use the latest OpenSSL):
$ find /usr/local/ssl/ -name string.h
$ find /usr/local/ssl/ -name *.h
/usr/local/ssl/include/openssl/rc4.h
/usr/local/ssl/include/openssl/crypto.h
/usr/local/ssl/include/openssl/ts.h
/usr/local/ssl/include/openssl/ecdsa.h
/usr/local/ssl/include/openssl/opensslconf.h
...
I'm trying to compile nginx with custom openssl »libressl« using this script: https://gist.github.com/Belphemur/3c022598919e6a1788fc
OK, this can be a pain as I've had to do similar with nginx (FIPS validated OpenSSL).
The easiest way to handle it is build OpenSSL from sources and install it into /usr/local/ssl. Then, grep nginx's files for -lcrypto and -lssl. When you find them, replace them with the static archive of OpenSSL:
change -lcrypto to /usr/local/ssl/lib/libcrypto.a
change -lssl to /usr/local/ssl/lib/libssl.a
And drop the -L related to OpenSSL.
This will ensure you use your version of OpenSSL at compile time and run time without the need for LD_PRELOAD and DYLD_LIBRARY_PATH tricks. It will just always work.
When I compile things with gitbash and gcc, is there someway to shorten what I need to type?
In order to compile my helloworld program, I have to type the following in:
gcc -o helloworld.exe helloworld.m -I C:/GNUstep/GNUstep/System/Library/Headers -L C:/GNUstep/GNUstep/System/Library/Libraries -std=c99 -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
Most people use Makefiles (or something related, e.g. CMake) in order to ease development. Makefiles are similar to bash scripts (the syntax is similar as well). After you created a Makefile you can run make and it does exactly what you specified.
If you want to know how to run Automake on Windows, read this: How to run a makefile in Windows?
I'm having a hard time finding good documentation on the most common g++ options. I have the following g++ command and I'm trying to understand it well:
g++ q1.cpp -o q1 -I/usr/local/include/opencv -L/usr/local/lib -lm -lopencv_core -lopencv_highgui -lopencv_calib3d -lopencv_imgproc
What does the -I option do?
-I adds to the path for searching for include files.
-l links to a particular library. (e.g. -lm links libm which is math)
It's not for a library I think it's only for include files. (It's a i not a l, l it's for libraries)
My problem is that ocamlc and ocamlopt apear to be refusing to find third party libraries installed through apt-get. I first started having this problem when I tried to incorporate third-party modules into my own OCaml programs, and quickly wrote it off as a personal failing in understanding OCaml compilation. Soon-- however-- I found myself running into the same problem when trying to compile other peoples projects under their own instructions.
Here is the most straight-forward example. The others all use ocamlbuild, which obfuscates things a little bit.
The program: http://groups.google.com/group/fa.caml/msg/5aee553df34548e2
The compilation:
$ocamlc -g -dtypes -pp camlp4oof -I +camlp4 dynlink.cma camlp4lib.cma -cc g++ llvm.cma llvm_bitwriter.cma minml.ml -o minml
File "minml.ml", line 43, characters 0-9:
Error:Unbound module Llvm
Even when I provide ocamlc with the obsolute paths to the llvm files, like so...
$ ocamlc -g -dtypes -pp camlp4oof -I +camlp4 dynlink.cma camlp4lib.cma -cc g++ /usr/lib/ocaml/llvm-2.7/llvm.cma /usr/lib/ocaml/llvm-2.7/llvm_bitwriter.cma minml.ml -o minml
... to no avail.
What am I doing wrong?
Your command is doing two things: it's compiling minml.ml (into minml.cmo), then linking the resulting object into minml.
Compiling a module requires the interfaces of the dependencies. The interfaces contain typing information that is necessary to both the type checker and the code generator; this information is not repeated in the implementation (.cma here). So for the compilation stage, llvm.cmi must be available. The compiler looks for it in the include path, so you need an additional -I +llvm-2.7 (which is short for -I /usr/lib/ocaml/llvm-2.7).
The linking stage requires llvm.cma, which contains the bytecode implementation of the module. Here, you can either use -I or give a full path to let ocamlc know where to find the file.
ocamlc -g -dtypes -I +camlp4 -I +llvm-2.7 -pp camlp4oof -c minml.ml
ocamlc -g -cc g++ -I +camlp4 -I +llvm-2.7 dynlink.cma camlp4lib.cma llvm.cma llvm_bitwriter.cma minml.cmo -o minml
or if you want to do both stages in a single command:
ocamlc -g -dtypes -cc g++ -I +camlp4 -I +llvm-2.7 dynlink.cma camlp4lib.cma llvm.cma llvm_bitwriter.cma -pp camlp4oof minml.ml -o minml