Docker image issue finding header files - c++

I am new to Docker. I am creating a Dockerfile to build my C/C++ application using a custom Makefile. The Makefile builds my code correctly outside Docker and all is good. However, there is an issue when using Docker. My Dockerfile looks as follows :
FROM gcc:latest
RUN apt-get update
RUN apt-get install libboost1.62-*
RUN apt-get install -y libmodbus-dev
COPY . /usr/src/client
WORKDIR /usr/src/client
RUN make -f MyMakefile.mak
CMD [ "bin/runfile" ]
Obviously my code needs libboost and libmodbus and therefore install them first. This was actually all working fine last week, but not now somehow. There is an issue finding the header files for the boost library afterwards though during compilation :
Sending build context to Docker daemon 255MB
Step 1/8 : FROM gcc:latest
---> 9bfd59c68035
Step 2/8 : RUN apt-get update
---> Using cache
---> 0ee029cb9883
Step 3/8 : RUN apt-get install libboost1.62-*
---> Using cache
---> 4d76aa8ea9a1
Step 4/8 : RUN apt-get install -y libmodbus-dev
---> Using cache
---> 35f300d99fa4
Step 5/8 : COPY . /usr/src/client
---> 5b880a0488d4
Step 6/8 : WORKDIR /usr/src/client
---> Running in 13c8a522b792
Removing intermediate container 13c8a522b792
---> 2c5d62aa1b32
Step 7/8 : RUN make -f MyMakefile.mak
---> Running in 7e8b5138bb55
g++ -Iinc -Iinc/common -Iinc/modbus -MMD -MP -std=c++11 -c src/main.cpp -o obj/main.o
In file included from inc/clientdevice_ctrl.h:23,
from inc/client_ctrl.h:21,
from src/main.cpp:23:
inc/profile.h:15:10: fatal error: boost/property_tree/json_parser.hpp: No such file or directory
15 | #include <boost/property_tree/json_parser.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [MyMakefile.mak:29: obj/main.o] Error 1
The command '/bin/sh -c make -f MyMakefile.mak' returned a non-zero code: 2
Where would Docker attempt to find these required header files? I would think that in the standard header locations?

Related

Cannot compile, error: cryptlib.h: No such file or directory

I've downloaded Crypto++ 7.0.0 from the official site, build a static library out of it, included cryptlib header with:
#include "cryptlib.h"
and when I try to compile my program with:
gcc main.cpp ./cryptopp700/libcryptopp.a
it throws at me errors like this:
main.cpp:2:10: fatal error: cryptlib.h: No such file or directory
#include "cryptlib.h"
^~~~~~~~~~~~
compilation terminated.
I also tried with:
-L. -llibcryptopp //while moving libcryptopp.a to the same directory main.cpp is
-L./cryptopp700 -llibcryptopp
so I started wondering if I was doing something wrong, but as I was checking out code examples with static libraries, everything seemed to be fine.
Help please.
Based on:
main.cpp:2:10: fatal error: cryptlib.h: No such file or directory
And:
gcc main.cpp ./cryptopp700/libcryptopp.a
Your directory structure looks like:
+- Project Folder
|
+- main.cpp
|
+- cryptopp700
|
+- cryltib.h
+- ...
+- libcryptopp.a
You should only need to add cryptopp700/ to your include header search path with -I:
g++ main.cpp -I ./cryptopp700 ./cryptopp700/libcryptopp.a
Note that you should also use g++ (the C++ compiler), not gcc (the C compiler).
You can also install the library since it has been built. By default it installs into /usr/local with:
skylake:cryptopp$ sudo make install
[sudo] password for jwalton:
install -m 644 *.h /usr/local/include/cryptopp
install -m 644 libcryptopp.a /usr/local/lib
install cryptest.exe /usr/local/bin
install -m 644 TestData/*.dat /usr/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /usr/local/share/cryptopp/TestVectors
You can install into an alternate location using PREFIX:
skylake:cryptopp$ sudo make install PREFIX=/opt/local
install -m 644 *.h /opt/local/include/cryptopp
install -m 644 libcryptopp.a /opt/local/lib
install cryptest.exe /opt/local/bin
install -m 644 TestData/*.dat /opt/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /opt/local/share/cryptopp/TestVectors
Then, you would change you compile and link command to something like:
g++ main.cpp -I /usr/local/include/cryptopp -o main.exe /usr/local/lib/libcryptopp.a
After an install like shown below, I normally tell folks to run the self tests. Unfortunately, the won't work if all you did was a make -j 4 or similar.
$ make -j 4
...
$ sudo make install
[sudo] password for jwalton:
install -m 644 *.h /usr/local/include/cryptopp
install -m 644 libcryptopp.a /usr/local/lib
install cryptest.exe /usr/local/bin
install -m 644 TestData/*.dat /usr/local/share/cryptopp/TestData
install -m 644 TestVectors/*.txt /usr/local/share/cryptopp/TestVectors
Here's the error you would get:
skylake:cryptopp$ cd /opt/local/bin/
skylake:bin$ ./cryptest.exe v
Using seed: 1544189072
Testing Settings...
passed: Your machine is little endian.
passed: Aligned data access.
passed: sizeof(byte) == 1
passed: sizeof(word16) == 2
passed: sizeof(word32) == 4
passed: sizeof(word64) == 8
passed: sizeof(word128) == 16
passed: sizeof(hword) == 4, sizeof(word) == 8, sizeof(dword) == 16
passed: cacheLineSize == 64
hasSSE2 == 1, hasSSSE3 == 1, hasSSE4.1 == 1, hasSSE4.2 == 1, hasAVX == 1, hasAVX2 == 1, hasAESNI == 1, hasCLMUL == 1, hasRDRAND == 1, hasRDSEED == 1, hasSHA == 0, isP4 == 0
...
SHA validation suite running...
Exception caught: Can not open file TestVectors/sha.txt for reading
My thinking is things should "just work" for you. You should not need to worry about CRYPTOPP_DATA_DIR for a common case. And you certainly should not have to RTFM to make the common case work. That tells me there's a defect in our engineering process.
We are going to fix that now: Issue 760, Make self-tests run after install by a typical user.
For me installing the development crypt library solved the issue:
apt-get install libcrypt-devel

How to Install Wt into a Custom Folder Without "fatal error: Wt/WApplication: No such file or directory"

I'm new to Wt and c++ and I just installed the Wt webframework on Ubuntu 16.04 LTS into a custom folder in my home directory. I cannot install or build any software into the /usr diretories of this computer. Even if I could, the PPA hasn't been active for 2 1/2 years, and the official Ubuntu installation instructions are also outdated. Aptitude no longer ships with Ubuntu and will eventually be discontinued.
I compliled and installed everything successfully, yet when I try to compile the Hello World example I get the following error:
g++ -o hello hello.cpp -lwt -lwthttp
fatal error: Wt/WApplication: No such file or directory
Here are my installation steps:
Boost:
wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.bz2
tar --bzip2 -xf boost_1_65_1.tar.bz2
cd boost_1_65_1
./bootstrap.sh --prefix=../myfolder
sudo ./b2 install --prefix=../myfolder
CMake:
wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz
tar -xvzf cmake-3.9.2.tar.gz
cd cmake-3.9.2
./configure --prefix=../myfolder
make
sudo make install
vim .profile
export PATH=$PATH:/home/ubuntu/myfolder/bin
Wt:
git clone https://github.com/emweb/wt.git
cd wt
cmake -DCMAKE_INSTALL_PREFIX:PATH=../myfolder .
-- Generating done
-- Build files have been written to: /home/ubuntu/myfolder
make
sudo make install
make -C examples
Since I'm lumping everything together in /myfolder I did not use the /build folder per the Wt installation instructions. The libwt and libboost libraries are in /myfolder/lib. I assumed all of the linking was taken care of during installation.
Any thoughts? Thanks in advance.
You have to tell your compiler to look for includes and libraries in the right folders, so instead of:
g++ -o hello hello.cpp -lwt -lwthttp
Try:
g++ -o hello hello.cpp -I/home/ubuntu/myfolder/include -L/home/ubuntu/myfolder/lib -lwt -lwthttp
Note that when you run your application, you'll also have to make sure that it can find the dynamic libs (.so files) it needs. You could do this:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/ubuntu/myfolder/lib"

Error while running configure on nxlogs build

I'm attempting to build nxlog with some updated libraries:
Latest APR (1.5.2)
Non-Heartbleed vulnerable OpenSSL sources
PCRE 8.37
Zlib 1.2.8
After building all the dependencies I'm a little stuck on getting nxlogs to build, specifically I'm stuck on the step where I run ./configure
At first it couldn't find apr-1-config, so I added /local/apr/bin to the path.
Then it couldn't fine libapr-1 so I added /local/apr/lib to the path, this is where the problems started. When APR built there wasn't a "libapr-1" file in /local/apr/lib, only libapr-1.a, libapr-1.la, libapr-1.dll.a.
Did I build APR incorrectly?
I'm trying to build this on windows
List of steps to get where I am:
Install MINGW using MinGW Installation Manager
Add packages:
mingw-developer-toolkit
mingw-base
mingw-expat bin
mingw32-libexpat dev
msys-libopenssl dev
msys-automake
msys-autoconf
Setup msys fstab (c:/mingw /mingw)
Install Python (2.5)
Add Python and mingw to system path (C:\Python25;C:\MinGW\bin;C:\MinGW\msys\1.0\bin)
Get and build APR source (I could not get APR iconv to compile)
Download:
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz
http://mirror.nexcess.net/apache//apr/apr-1.5.2-win32-src.zip
http://mirror.nexcess.net/apache//apr/apr-util-1.5.4-win32-src.zip
http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.zip/download
http://zlib.net/zlib128.zip
Build:
Extract all files to c:\mingw\msys\1.0\src
Compile libiconv
cd libiconv-1.11
./configure CFLAGS="-O2 -s -mms-bitfields -march=i686" CXXFLAGS="-O2 -s -mms-bitfields -march=i686"
make && make install
Compile APR
cd apr
./buildconf
./configure CFLAGS="-O0 -s -mms-bitfields -march=i686" CXXFLAGS="-O0 -s -mms-bitfields -march=i686"
make && make install
cd ..
Compile APR-UTIL
cd apr-util-1.5.4
./buildconf --with-apr=/usr/src/apr-1.5.2
./configure CFLAGS="-O2 -s -mms-bitfields -march=i686" CXXFLAGS="-O2 -s -mms-bitfields -march=i686" --with-apr=/usr/src/apr-1.5.2
make && make install
cd ..
Compile PCRE
cd pcre-.37
./configure
make && make install
(make threw an error corrected with make clean, autoconf -i --force, started back at step 1)
cd ..
Compile ZLIB
cd zlib-1.2.8
make -f win32/Makefile.gcc
Compile nxlog
cd nxlog-ce-2.8.1248
./configure
This is where the problems began. First it couldn't find apr-1-config.
Fixed by adding /local/apr/bin to path.
Now it can't find libapr-1, adding /local/apr/lib to the path doesn't help. There is no libapr-1 file in the MinGW directory tree; thought I do see libapr-1.a libapr-1.la libapr.dll.a. Ideas? I assume this is supposed to be a script file to respond to queries about the library's interfaces?

Set a custom install directory when making a deb package with fpm

I'm using fpm to create a deb package, but when I install that deb package, it is installed into the wrong location, my fpm command is:
fpm -f -s "dir" -t "deb" -a "all" -n "my_project" -v 1 -C "/tmp/tmpjWTuVp" /tmp/tmpjWTuVp/my_project
The folder i want to package up exists at /tmp/tmpjWTuVp/my_project, but every time i install it with:
dpkg -i my_package.deb
it installs it into /tmp/tmpjWTuVp/my_project, ideally i'd like it to install into /var/lib/my_project. I have tried --installdir and --root with my dpkg command, but it complains with cannot access archive: No such file or directory
Other information:
I'm installing onto an ubuntu box
I'm very new to deb packaging, so may have missed something obvious
I'm not bound to fpm and happy to hear other viable suggestions
inside my_project is a python virtualenv and my django project
I have randomly found the answer to this immediately after writing this question...
basically the last, unnamed argument within the fpm command can contain an equals separator which defines the directory to come from, and to install to, so the command I ended up using was:
fpm -f -s "dir" -t "deb" -a "all" -n "my_project" -v 1 -C "/tmp/tmpjWTuVp" my_project=/var/lib/my_project
Notice the my_project=/var/lib/my_project, the left side is the directory name of my project (relative, because I used -C to change directory to /tmp/tmpjWTuVp before looking for packages) and on the right side is where I want to install to on the remote machine...

Building a Debian package tries to install to real /opt

This is again one these nice Debian packaging problems.
I have an app that installs to /opt (the install location is actually irrelevant, the same problem occurs with /usr):
OPT=1 ./configure && make && make install
I took a working Debian packaging from my other app, that used CMake, but the configuring, build and installation were similar. I modified the rules file a bit to build my new app:
build: build-stamp
build-stamp:
dh_testdir
# Add here commands to compile the package.
OPT=1 ./configure && $(MAKE) -j$(shell cat /proc/cpuinfo | grep processor | wc -l)
touch build-stamp
I left the installation part untouched:
install: build
dh_testdir
dh_testroot
dh_prep
dh_installdirs
# Add here commands to install the package into debian/<packagename>
DESTDIR=`pwd`/debian/`dh_listpackages` $(MAKE) install
Now, the problem is that when I try to build the package, it tries to install
to the real /opt and crashes:
mkdir: cannot create directory ‘/opt/snm’: Permission denied
make[1]: *** [install_target] Error 1
make: *** [install] Error 2
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2
debuild: fatal error at line 1361:
dpkg-buildpackage -rfakeroot -D -us -uc -i -b failed
I just can't figure out why my packaging doesn't work with my new app. Or alternatively, why it DID work with the other app :)
It seems that my install step was just ignoring the DESTDIR given by the Debian rules file.