Build docker image in C programm - c

I am sending over a socket a Dockerfile and a .c file. I am trying to
build the image in a C programm using the following command:
system("docker build -t my_image .")
But when it starts to build the image, I get the following output:
Step 1/6 : FROM gcc:4.9
---> 1b3de68a7ff8
Step 2/6 : COPY . /home/server/src
---> 3ad55a5751dd
Step 3/6 : WORKDIR /home/server/src
---> Running in 8d768eda43ee
Removing intermediate container 8d768eda43ee
---> bf9a9ff0273b
Step 4/6 : EXPOSE 9000
---> Running in 75c48b8aa200
Removing intermediate container 75c48b8aa200
---> b38c514453e0
Step 5/6 : RUN gcc ./rand_gen_server.c -o server_side
---> Running in b4486ecd8451
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
The command '/bin/sh -c gcc ./rand_gen_server.c -o server_side' returned a non-zero code: 1
When building directly in the cmd, everything works. I am running the C
programm using sudo.
Any ideas?

The combination of #ForceBru and #Rudi help me. Since the Dockerfile was obtained from a socket, I had to replace the COPY and WORKDIR paths to the ones corresponding to the new host.
Also, I changed the step 5/6 to gcc -c /rand_gen_server.c -o server_side.
Let's see if the rest of the endeavor will work.
UPDATE
Turns out, during compilation, I cannot compile another .c file. In order to do this, I have to create a new process. Using the function fork() and the executing the system call for building the docker image did the job. Plus, I did not use the -c option during the compilation.

Related

trouble running make on CBLAS

I'm trying to build a BLAS shared library for use with ghostjat/np cannot get make to run successfully on the CBLAS source code. I performed these exact steps on an Ubuntu 20 workstation:
# create new directory
mkdir ~/blas
cd ~/blas
# fetch and extract the CBLAS source code linked from the BLAS page
wget http://www.netlib.org/blas/blast-forum/cblas.tgz
tar -xvzf cblas.tgz
#cd into the CBLAS dir
cd CBLAS
#get appropriate make file according to README:
rm Makefile.in
ln -s Makefile.LINUX Makefile.in
#then we try make
make
This results in an error because gfortran was not installed:
gfortran -O3 -c sdotsub.f
make[1]: gfortran: Command not found
make[1]: *** [Makefile:247: sdotsub.o] Error 127
make[1]: Leaving directory '/home/foo/biz/machine-learning/blas/CBLAS/src'
make: *** [Makefile:147: allprecision] Error 2
So I install gfortran
sudo apt install gfortran
# answer YES to prompts
I am then able to make most of the project, but it croaks with an error:
make[1]: Entering directory '/home/foo/biz/machine-learning/blas/CBLAS/testing'
gcc -I../include -O3 -DADD_ -c c_sblas1.c
gfortran -O3 -c c_sblat1.f
c_sblat1.f:214:48:
214 | CALL STEST1(SNRM2TEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Warning: Rank mismatch in argument ‘strue1’ at (1) (scalar and rank-1) [-Wargument-mismatch]
c_sblat1.f:218:48:
218 | CALL STEST1(SASUMTEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Warning: Rank mismatch in argument ‘strue1’ at (1) (scalar and rank-1) [-Wargument-mismatch]
gfortran -o xscblat1 c_sblat1.o c_sblas1.o ../lib/cblas_LINUX.a libblas.a
gfortran: error: libblas.a: No such file or directory
make[1]: *** [Makefile:72: xscblat1] Error 1
make[1]: Leaving directory '/home/foo/biz/machine-learning/blas/CBLAS/testing'
make: *** [Makefile:180: alltst] Error 2
What is the problem here? This is mostly greek to me, but it looks like it compiles successfully all the CBLAS source code except it seems to barf when it gets to the testing, complaining that it cannot find a file, libblas.a. Can someone help me make sure this make operation completes?
Also, I was expecting this compilation step to produce a shared library, perhaps cblas.so or something. I am hoping this process will yield a viable BLAS library that I can use with ghostjat/np to perform fast matrix operations from a PHP script. However, there are no files in this directory ending in .so. Should I be looking for some other file?
EDIT: the comments have suggested that perhaps I should 'install BLAS' or 'install the libopenblas-dev package' on this machine. Let me first say that my goal is to obtain a library that I might distribute with some PHP source code. I am under the impression that building/making CBLAS will provide this library.
EDIT 2: After attempting a lot of trial and error, I think (but am not sure) that CBLAS is not a full-blown implementation of the BLAS functionality, but just a C wrapper around the BLAS functions, which are written in FORTRAN. It would appear that the makefile in CBLAS must be changed to point to a BLAS static library. I've been able to build the BLAS 3.11.0 library like so:
cd ~/blas
curl https://netlib.org/blas/blas-3.11.0.tgz > blas-3.11.0.tgz
tar -xvzf blas-3.11.0.tgz
cd BLAS-3.11.0
make
this runs for about a minute or so and yields a static lib, blas_LINUX.a. I take note of this file's location:
/Users/foo/Desktop/biz/machine-learning/blas2/BLAS-3.11.0/blas_LINUX.a.
I then return to my previously downloaded/extracted CBLAS folder:
cd ~/blas/CBLAS
and note this information in the README file:
BLLIB is your Legacy BLAS library
I edit this line in Makefile.in:
BLLIB = libblas.a
so that it refers instead to the static blas_LINUX. I just compiled above:
BLLIB = /Users/foo/Desktop/biz/machine-learning/blas2/BLAS-3.11.0/blas_LINUX.a
I save the make file and then make CBLAS:
make clean all
This runs for awhile, but fails in the testing phase with a certain gfortrain complaint:
( cd testing && make all )
gcc -I../include -O3 -DADD_ -c c_sblas1.c
gfortran -O3 -c c_sblat1.f
c_sblat1.f:214:48:
214 | CALL STEST1(SNRM2TEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Error: Rank mismatch in argument 'strue1' at (1) (scalar and rank-1)
c_sblat1.f:218:48:
218 | CALL STEST1(SASUMTEST(N,SX,INCX),STEMP,STEMP,SFAC)
| 1
Error: Rank mismatch in argument 'strue1' at (1) (scalar and rank-1)
make[1]: *** [c_sblat1.o] Error 1
make: *** [alltst] Error 2
Not a direct answer, but since you're on Ubuntu you can just install the libopenblas-dev package which contains the cblas headers and will pull in a high performance BLAS library as a dependency.
I stumbled across these directions which have worked for me, at least on Ubuntu 20.04. A couple of things changed so I list the exact steps I took here on my Ubuntu 20.04 workstation. The basic solution is to first compile BLAS (this appears to be FORTRAIN code) into a static library, blas_LINUX.a, and then modify the CBLAS files to point to that static library. There are tgz archives for both on the BLAS homepage.
# make a working dir
mkdir ~/cblas
cd ~/cblas
# fetch the BLAS library (not CBLAS, just BLA)S
wget http://www.netlib.org/blas/blas-3.11.0.tgz
tar -xvzf blas-3.11.0.tgz
cd BLAS-3.11.0
make
This will produce a file, blas_LINUX.a. Take note of its location here, you'll need to refer to it in the CBLAS make file. Next, fetch CBLAS and compile.
# get out of this directory back to our working dir
cd ..
# fetch CBLAS tgz, linked from netlib page
wget http://www.netlib.org/blas/blast-forum/cblas.tgz
# extract it
tar -cvzf cblas.tgz
# cd into CBLAS dir for edits
cd CBLAS
# remove default makefile
rm Makefile.in
# copy LINUX make file to Makefile.in
ln -s Makefile.LINUX Makefile.in
# edit Makefile.in
nano Makefile.in
Make the following changes:
# path to just-compiled static lib
# NOTE your path will be different
BLLIB = /home/sneakyimp/cblas/BLAS-3.11.0/blas_LINUX.a
CBLIB = ../lib/cblas_$(PLAT).so
CFLAGS = -O3 -DADD_ -fPIC
FFLAGS = -O3 -fPIC
ARCH = gcc
ARCHFLAGS = -shared -o
Save & close Makefile.in and then make CBLAS
# this takes a bit of time
make
# ls -al lib
You should now have your so file in lib/cblas_LINUX.so
I was able edit the blas.h file in a composer-installed ghostjat/np to point to this cblas_LINUX.so file, and eventually get it working, but you'll have complaints about various functions in the that blas.h file which are not defined in CBLAS. If you remove each of the functions it complains about you may get it to work or not. I was able to get it working on Ubuntu 20 running php 8.2, but have had trouble on other machines. My attempt to run cblas_dgemm on a matrix i defined resulted in this error:
php: symbol lookup error: /home/sneakyimp/cblas/CBLAS/lib/cblas_LINUX.so: undefined symbol: dgemm_

collect2: error: ld returned 1 exit status for

I am trying to use two github repositories as shown below:
https://github.com/markoneill/ssa-daemon
https://github.com/markoneill/ssa
When trying to execute "build-client-auth.sh" in the ssa-daemon directory I ran into this error. Also, in order to make it easy to troubleshoot I went into "build-client-auth.sh" and took the command on line 72 that was giving me an error, which is "make clientauth" as shown below.
[eli#localhost ssa-daemon]$ make clientauth
make -C ./qrdisplay
make[1]: Entering directory '/home/eli/csci400/ssa-daemon/qrdisplay'
make[1]: 'bin/qrPopUp' is up to date.
make[1]: Leaving directory '/home/eli/csci400/ssa-daemon/qrdisplay'
gcc hashmap.o netlink.o hashmap_str.o tls_wrapper.o config.o issue_cert.o
daemon.o main.o self_sign.o openssl_compat.o csr_daemon.o rfcomm_client.o nsd.o
log.o rfcomm_server.o queue.o notification.o tb_connector.o auth_daemon.o -o
tls_wrapper -Llibevent/lib -Lopenssl/lib -Wl,-rpath -Wl,libevent/lib -Wl,-rpath
-Wl,openssl/lib -lpthread pkg-config --libs libconfig libevent_openssl libnl-
genl-3.0 libnotify avahi-client openssl
/usr/bin/ld: rfcomm_client.o: in function main': /home/eli/csci400/ssa-
daemon/rfcomm_client.c:35: multiple definition of main';
main.o:/home/eli/csci400/ssa-daemon/main.c:61: first defined here
/usr/bin/ld: rfcomm_server.o: in function main': /home/eli/csci400/ssa-
daemon/rfcomm_server.c:15: multiple definition of main';
main.o:/home/eli/csci400/ssa-daemon/main.c:61: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:65: clientauth] Error 1
Thanks to Kuchara, who said to remove both rfcomm_client.c and rfcomm_server.c, I was able to get passed the error above. However, I am getting a new error as follows:
Done
Building custom sslsplit
Cloning into 'sslsplit'...
remote: Enumerating objects: 155, done.
remote: Counting objects: 100% (155/155), done.
remote: Compressing objects: 100% (110/110), done.
remote: Total 4050 (delta 80), reused 106 (delta 43), pack-reused 3895
Receiving objects: 100% (4050/4050), 1.59 MiB | 4.92 MiB/s, done.
Resolving deltas: 100% (2885/2885), done.
0001-SSA-patch.patch:147: trailing whitespace.
error: patch failed: pxyconn.c:936
error: pxyconn.c: patch does not apply
===========================================================================
So, what I did was look at the build script for the section that was making the error and saw this:
echo "Building custom sslsplit"
git clone https://github.com/droe/sslsplit
cd sslsplit
cp ../extras/sslsplit/0001-SSA-patch.patch .
cp ../extras/sslsplit/ca.crt .
cp ../extras/sslsplit/ca.key .
cp ../extras/sslsplit/start.sh .
cp ../extras/sslsplit/firewallOn.sh .
git apply 0001-SSA-patch.patch
make
cd ..
echo "Done"
So, what I believe is the "git apply 0001-SSA-patch.patch" is giving the error, but how I would I fix it?
Try checking out this revision: 6955368275b4372ebd0b7a125de626808a7e5aef
According to the git log, problematic files seem to be some test codes, which were added recently:
https://github.com/markoneill/ssa-daemon/commit/d5a94cb4409dd27e4478b4bba2413dfae1c70169
BTW that failure you have is the reason why I usually discourage to use wildcards. :-)
the patch was not working so I applied the patch by hand and it works!

undefined references to `strerror_s' while building lua-openssl on alpine image

I am trying to build an openresty alpine image with lua-openssl like so
FROM openresty/openresty:alpine-fat
# Set the version
ENV RESTY_CONFIG_OPTIONS_MORE "--with-ngx_http_ssl_module"
EXPOSE 80
EXPOSE 443
RUN ls /usr/local/openresty/nginx/logs
COPY lualib /usr/local/openresty/nginx/lualib
RUN chown -R nobody:root /usr/local/openresty/nginx/lualib
RUN apk add --update \
openssl openssl-dev \
lua5.3 luajit-dev lua-socket \
git
RUN git clone https://github.com/zhaozg/lua-openssl.git /usr/local/lua-openssl; \
cd /usr/local/lua-openssl; \
git checkout e923252b28cff43add6382853cc85ed888c4474b; \
make
But I get the one below and a lot of such errors:
/usr/local/lua-openssl/deps/lua-compat/c-api/compat-5.3.c:74:
undefined reference to strerror_s' ./libopenssl.a(cms.o): In function
compat53_strerror':
/usr/local/lua-openssl/deps/lua-compat/c-api/compat-5.3.c:74:
undefined reference to strerror_s'
./libopenssl.a(compat.o):/usr/local/lua-openssl/deps/lua-compat/c-api/compat-5.3.c:74:
more undefined references tostrerror_s' follow collect2: error: ld
returned 1 exit status make: *** [Makefile:94: openssl.so] Error 1
Am I missing a package?
(1) We grabbed the trusty image instead of alpine-fat.
(2) Overrode the make file with one that uses lcrypto lib to build.
And that is the only setting I know to make this work.
I did not try compiling with MSVC++.
My issue and it's fix is tracked in https://github.com/zhaozg/lua-openssl/issues/138

Mingw32 make command: Unrecognized option -z

I'm trying to make this project using Mingw32:
GitHub PNG2POS
For that, I'm doing the following command using git bash:
git clone --recursive https://github.com/petrkutalek/png2pos.git
It creates a folder called png2pos containing the project sources, and an important file called Makefile.
From there, I cd into the newly create folder, and try to execute the command
make
The expected result was the sources being built into an executable file, but I'm getting some errors that don't allow me to to that:
(...)/x86_64-pc-cygwin-bin/ld: unrecognized option '-z'
use the --help option for usage information
collect2: error: ld returned 1 exit status
Makefile:36: recipe for target 'png2pos' failed
mingw32-make: *** [png2pos] Error 1
What am I supposed to do for this to work and create my desired executable file?

ERROR: Failed to spawn fakeroot worker to run /PATH_TO_THIS/example_0.1.bb:do_install: [Errno 2] No such file or directory

I am trying to compile a c code and install it using yocto. it is successfully compiled using do_compile.
I tried to install using do_install, it is giving bellow error.
ERROR: Failed to spawn fakeroot worker to run /PATH_TO_THIS/example_0.1.bb:do_install: [Errno 2] No such file or directory
Please find my bb file below
SUMMARY = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR} /MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://sample.c"
S = "${WORKDIR}"
do_compile() {
x86_64-linux-gnu-gcc sample.c -o test_example
}
do_install() {
install -d ${D}${bindir}
install -m 0755 test_example ${D}${bindir}
}
Based on your comment above that you are using -b - that is almost certainly the cause of this issue. When you use -b bitbake will print this warning:
WARNING: Buildfile specified, dependencies will not be handled. If this is not what you want, do not use -b / --buildfile.
One of the dependencies that you may be missing is the fakeroot program (pseudo). Using -b is likely preventing that from being built.
Instead of using -b, you should put the recipe into a place bitbake can find it (to test, could be meta/recipes-extended/example, but when you do it properly you should create your own layer and put it there). Then you can just build it like any other recipe:
bitbake example

Resources