unable to add icon to exe using windres - windows

I'd like to add an Icon to my exe compiled with mingw-gcc.
I followed instructions in this SO post but the Icon does not show up on my exe in windows explorer.
[edit]
Meanwhile I found out that windres destroys my executable. Before applying windres the executable runs as expected. After applying windres calling the executable results in a windows error message telling (roughly) that this executable is not compatible with this windows version.
What am I doing wrong?
This is my directory layout:
$ ls -lR launcher/
launcher/:
total 508
drwxr-xr-x 1 me 1049089 0 Aug 20 2015 src/
drwxr-xr-x 1 me 1049089 0 Nov 7 10:56 target/
launcher/src:
total 0
drwxr-xr-x 1 me 1049089 0 Nov 7 10:51 main/
launcher/src/main:
total 4
drwxr-xr-x 1 me 1049089 0 Nov 7 10:52 cpp/
drwxr-xr-x 1 me 1049089 0 Apr 14 2016 resources/
drwxr-xr-x 1 me 1049089 0 Nov 4 15:11 scripts/
launcher/src/main/cpp:
total 8
-rw-r--r-- 1 me 1049089 6793 Nov 7 10:41 JavaLauncher.cpp
launcher/src/main/resources:
total 5
-rw-r--r-- 1 me 1049089 47 Nov 7 10:47 javaLauncher.rc
-rw-r--r-- 1 me 1049089 2238 Apr 14 2016 JavaLauncher.ico
launcher/src/main/scripts:
total 1
-rw-r--r-- 1 me 1049089 389 Nov 7 10:56 makefile
launcher/target:
total 4
-rwxr-xr-x 1 me 1049089 2502 Nov 7 10:56 JavaLauncher.exe*
this is my resource file:
0 ICON "launcher/src/main/resources/JavaLauncher.ico"
this is my makefile:
all: launcher/target/JavaLauncher.exe
launcher/target/JavaLauncher.exe: launcher/src/main/cpp/JavaLauncher.cpp launcher\target
/Absolute/Path/to/mingw64/bin/g++.exe $< -o $# -static -l winpthread
/Absolute/Path/to/mingw64/bin/windres.exe -v -i launcher/src/main/resources/javaLauncher.rc -o $#
launcher\target:
cmd /c md $#
this is the output of make:
/Project/root>/Absolute/Path/to/mingw64\bin\make.exe -f launcher\src\main\scripts\makefile
cmd /c md launcher\target
/Absolute/Path/to/mingw64/bin/g++.exe launcher/src/main/cpp/JavaLauncher.cpp -o launcher/target/JavaLauncher.exe -static -l winpthread
/Absolute/Path/to/mingw64/bin/windres.exe -v -i launcher/src/main/resources/javaLauncher.rc -o launcher/target/JavaLauncher.exe
Using `/Absolute/Path/to/mingw64/bin/gcc -E -xc -DRC_INVOKED launcher/src/main/resources/javaLauncher.rc'
Using popen to read preprocessor output
/Project/root>
this is the result in windows explorer:
[edit]
The final working solution is this:
mingwPath = $(realpath Path/to/mingw64/bin)
TARGET_DIR=target
TARGET_OBJECT_DIR=$(TARGET_DIR)/objects
TARGET_DIR_NAME=$(subst /,\, $(TARGET_DIR))
TARGET_OBJECT_DIR_NAME=$(subst /,\, $(TARGET_OBJECT_DIR))
SOURCE_DIR_NAME=src/main
APP_NAME=MyApp
TARGET_BASE_NAME=$(TARGET_DIR)/$(APP_NAME)
TARGET_ARCH=-m32
all: $(TARGET_OBJECT_DIR_NAME) $(TARGET_BASE_NAME).exe
$(TARGET_BASE_NAME).exe: $(TARGET_OBJECT_DIR)/$(APP_NAME).o\
$(TARGET_OBJECT_DIR)/$(APP_NAME)Res.o $(TARGET_OBJECT_DIR_NAME)
$(mingwPath)/g++ $(TARGET_ARCH) -o $# -static -l winpthread $(filter %.o,$^)
$(TARGET_OBJECT_DIR)/$(APP_NAME).o: $(SOURCE_DIR_NAME)/cpp/$(APP_NAME).cpp
$(mingwPath)/g++ $(TARGET_ARCH) -c $< -o $#
$(TARGET_OBJECT_DIR)/$(APP_NAME)Res.o: $(SOURCE_DIR_NAME)/resources/$(APP_NAME).rc
$(mingwPath)/windres -v -i $< -o $# --output-format=coff --target=pe-i386
$(TARGET_OBJECT_DIR_NAME):$(TARGET_DIR_NAME)
echo $#
cmd /c md $#
$(TARGET_DIR_NAME):
echo $#
cmd /c md $#
clean:
cmd /c del /s /q $(TARGET_DIR_NAME)

I'm not sure if the windres resource compiler can compile and add the resource data directly to the exe file, but that is what you're trying to do here. Maybe it is possible, I searched a little bit but couldn't find regarding information.
I got this working and having an exe icon. You need to specify the resource object generated by windres to the g++ linker after the program object. Also change the order and have windres run first so to have the resource object file generated before g++ linker links the program and resource objects.
all: launcher/target/JavaLauncher.exe
launcher/target/JavaLauncher.exe: launcher/src/main/cpp/JavaLauncher.cpp launcher\target
/Absolute/Path/to/mingw64/bin/windres.exe -v -i launcher/src/main/resources/JavaLauncher.rc -o launcher/src/main/resources/JavaLauncherRes.o
/Absolute/Path/to/mingw64/bin/g++.exe $< -o $# launcher/src/main/resources/JavaLauncherRes.o -static
launcher\target:
cmd /c md $#

Related

Error cross-compiling binutils-gdb for windows

I cloned binutils-gdb repository from here (master branch) on a linux machine (Ubuntu) and I want to compile it for Windows (using x86_64_w64_mingw32 toolchain).
First, I ran ./configure with the following options to specify the cross-compile toolchain.
./configure --prefix=/usr/x86_64-w64-mingw32 --target=arm-none-eabi --host=x86_64-w64-mingw32
Then I ran make and get the following error (I omitted most of the output because it is pretty large):
[...]
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -DWITH_DEFAULT_ALIGNMENT=STRICT_ALIGNMENT -DDEFAULT_INLINE=0 -Wall -Wdeclaration-after-statement -Wpointer-arith -Wpointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type -Wold-style-declaration -Wold-style-definition -Wno-format -Werror -DMODET -I. -I. -I../common -I./../common -I../../include -I./../../include -I../../bfd -I./../../bfd -I../../opcodes -I./../../opcodes -I../../intl -g -O2 -c -o callback.o -MT callback.o -MMD -MP -MF .deps/callback.Tpo ./../common/callback.c
./../common/callback.c: In function ‘os_time’:
./../common/callback.c:417:25: error: passing argument 1 of ‘time’ from incompatible pointer type [-Werror=incompatible-pointer-types]
417 | return wrap (p, time (t));
| ^
| |
| long int *
In file included from ./../common/callback.c:35:
/usr/share/mingw-w64/include/time.h:230:47: note: expected ‘time_t *’ {aka ‘long long int *’} but argument is of type ‘long int *’
230 | static __inline time_t __CRTDECL time(time_t *_Time) { return _time64(_Time); }
| ~~~~~~~~^~~~~
cc1: all warnings being treated as errors
make[3]: *** [Makefile:513: callback.o] Error 1
make[3]: Leaving directory '/media/D/Work/FC/binutils-gdb/sim/arm'
make[2]: *** [Makefile:928: all-recursive] Error 1
make[2]: Leaving directory '/media/D/Work/FC/binutils-gdb/sim'
make[1]: *** [Makefile:8376: all-sim] Error 2
make[1]: Leaving directory '/media/D/Work/FC/binutils-gdb'
make: *** [Makefile:915: all] Error 2
I think it has something to do with time_t being typedef'd as a long long int (64 bit integer) in the host platform (Windows), however, the function os_time from the file sim/common/callback.c:414 (path relative to project root), takes a long (32 bit integer) as a parameter:
static long
os_time (host_callback *p, long *t)
{
return wrap (p, time (t));
}
How can I fix this error? Or are there any issue trackers for binutils-gdb?
This is because you are building the current, non-release,development version - I got the exact same error while building from the latest git revision at the time I cloned the repository, 0a703a4cedffa6f3824e87f115e8d392e32de191.
If you really want to build from the development tree, you will have to wait for the issue to be fixed, or to fix it by yourself - this is not being addressed in this answer.
But if building the latest released version, 2.36.1, is sufficient, the procedure hereafter will work (tested on Ubuntu 20.04 TLS):
wget https://ftp.gnu.org/gnu/binutils/binutils-2.36.1.tar.gz
tar zxf binutils-2.36.1.tar.gz
mkdir binutils
cd binutils
../binutils-2.36.1/configure --prefix=$(pwd)/binutils-2.36.1-x86_64-w64-mingw32 --target=arm-none-eabi --program-prefix=arm-none-eabi- --host=x86_64-w64-mingw32
make
make install
ll -gG binutils-2.36.1-x86_64-w64-mingw32/bin/
total 159144
drwxrwxr-x 2 4096 Apr 7 14:41 ./
drwxrwxr-x 6 4096 Apr 7 14:41 ../
-rwxr-xr-x 1 9212998 Apr 7 14:41 arm-none-eabi-addr2line.exe*
-rwxr-xr-x 2 9748961 Apr 7 14:41 arm-none-eabi-ar.exe*
-rwxr-xr-x 2 14457348 Apr 7 14:41 arm-none-eabi-as.exe*
-rwxr-xr-x 1 9077841 Apr 7 14:41 arm-none-eabi-c++filt.exe*
-rwxr-xr-x 1 816086 Apr 7 14:41 arm-none-eabi-elfedit.exe*
-rwxr-xr-x 1 10783524 Apr 7 14:41 arm-none-eabi-gprof.exe*
-rwxr-xr-x 4 14526998 Apr 7 14:41 arm-none-eabi-ld.bfd.exe*
-rwxr-xr-x 4 14526998 Apr 7 14:41 arm-none-eabi-ld.exe*
-rwxr-xr-x 2 9259673 Apr 7 14:41 arm-none-eabi-nm.exe*
-rwxr-xr-x 2 10655762 Apr 7 14:41 arm-none-eabi-objcopy.exe*
-rwxr-xr-x 2 14908446 Apr 7 14:41 arm-none-eabi-objdump.exe*
-rwxr-xr-x 2 9748961 Apr 7 14:41 arm-none-eabi-ranlib.exe*
-rwxr-xr-x 2 6156460 Apr 7 14:41 arm-none-eabi-readelf.exe*
-rwxr-xr-x 1 9193640 Apr 7 14:41 arm-none-eabi-size.exe*
-rwxr-xr-x 1 9190290 Apr 7 14:41 arm-none-eabi-strings.exe*
-rwxr-xr-x 2 10655762 Apr 7 14:41 arm-none-eabi-strip.exe*
I did not test building from the git repository after having checked-out the binutils-2_36_1 tag:
git -C binutils-gdb checkout binutils-2_36_1
But it should work, if what was tagged is what was packaged in the archive file, which should be the case.

OpenSSL linking undefined reference to `EVP_MD_CTX_new' and others

I am compiling some codes based on OpenSSL. The compiler, parameters and error are shown in the following.
$ gcc -I/home/share/pkp/include -L/home/share/pkp/lib -lssl -lcrypto -Wall -O3 -Wpedantic -Wno-unused-result -Wno-pointer-sign ot.c -o ot
/tmp/cck3sgve.o: In function `main':
ot.c:(.text.startup+0x20): undefined reference to `EVP_get_digestbyname'
ot.c:(.text.startup+0x31): undefined reference to `EVP_MD_CTX_new'
ot.c:(.text.startup+0x41): undefined reference to `EVP_DigestInit_ex'
ot.c:(.text.startup+0x53): undefined reference to `EVP_DigestFinal_ex'
ot.c:(.text.startup+0x5b): undefined reference to `EVP_MD_CTX_free'
collect2: error: ld returned 1 exit status
Here are versions of components in the compile environments.
$ uname -a
Linux yzx-lab3 4.4.0-17763-Microsoft #379-Microsoft Wed Mar 06 19:16:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux
$ /home/share/pkp/bin/openssl version
./bin/openssl: relocation error: ./bin/openssl: symbol EVP_mdc2 version OPENSSL_1_1_0 not defined in file libcrypto.so.1.1 with link time reference
$ grep "OPENSSL_VERSION" /home/share/pkp/openssl-1.1.1a/include/openssl/opensslv.h
# define OPENSSL_VERSION_NUMBER 0x1010101fL
# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1a 20 Nov 2018"
$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I know there already many question about the similar error and have tried many solutions. But they do not work.
1) Fist I obtain the source code and unzip all the fils to "/home/share/pkp".
wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1a.tar.gz
Then compile and install openssl library.
./config --prefix=/home/share/pkp --openssldir=/home/share/pkp/openssl
make && make test && make install
There is no error message during the installation.
2) To asure that openssl is compiled and installed correctly, I do some verifications.
$ ls /home/share/pkp/lib/ -l
total 14912
drwxrwxrwx 1 share share 4096 Jun 18 12:30 engines-1.1
-rw-r--r-- 1 share share 5700252 Jun 18 12:30 libcrypto.a
lrwxrwxrwx 1 share share 16 Jun 18 12:30 libcrypto.so -> libcrypto.so.1.1
-rwxr-xr-x 1 share share 3414744 Jun 18 12:30 libcrypto.so.1.1
-rw-r--r-- 1 share share 1043216 Jun 18 12:30 libssl.a
lrwxrwxrwx 1 share share 13 Jun 18 12:30 libssl.so -> libssl.so.1.1
-rwxr-xr-x 1 share share 692696 Jun 18 12:30 libssl.so.1.1
$ nm /home/share/pkp/lib/libcrypto.a | grep "EVP_get_digestbyname" | wc -l
24
$ du /home/share/pkp/include/openssl -ah
4.0K /home/share/pkp/include/openssl/aes.h
36K /home/share/pkp/include/openssl/asn1.h
0 /home/share/pkp/include/openssl/asn1_mac.h
16K /home/share/pkp/include/openssl/asn1err.h
36K /home/share/pkp/include/openssl/asn1t.h
4.0K /home/share/pkp/include/openssl/async.h
4.0K /home/share/pkp/include/openssl/asyncerr.h
36K /home/share/pkp/include/openssl/bio.h
8.0K /home/share/pkp/include/openssl/bioerr.h
4.0K /home/share/pkp/include/openssl/blowfish.h
24K /home/share/pkp/include/openssl/bn.h
8.0K /home/share/pkp/include/openssl/bnerr.h
4.0K /home/share/pkp/include/openssl/buffer.h
4.0K /home/share/pkp/include/openssl/buffererr.h
4.0K /home/share/pkp/include/openssl/camellia.h
4.0K /home/share/pkp/include/openssl/cast.h
4.0K /home/share/pkp/include/openssl/cmac.h
20K /home/share/pkp/include/openssl/cms.h
12K /home/share/pkp/include/openssl/cmserr.h
4.0K /home/share/pkp/include/openssl/comp.h
4.0K /home/share/pkp/include/openssl/comperr.h
8.0K /home/share/pkp/include/openssl/conf.h
4.0K /home/share/pkp/include/openssl/conf_api.h
4.0K /home/share/pkp/include/openssl/conferr.h
20K /home/share/pkp/include/openssl/crypto.h
4.0K /home/share/pkp/include/openssl/cryptoerr.h
16K /home/share/pkp/include/openssl/ct.h
4.0K /home/share/pkp/include/openssl/cterr.h
8.0K /home/share/pkp/include/openssl/des.h
16K /home/share/pkp/include/openssl/dh.h
4.0K /home/share/pkp/include/openssl/dherr.h
12K /home/share/pkp/include/openssl/dsa.h
4.0K /home/share/pkp/include/openssl/dsaerr.h
4.0K /home/share/pkp/include/openssl/dtls1.h
12K /home/share/pkp/include/openssl/e_os2.h
4.0K /home/share/pkp/include/openssl/ebcdic.h
64K /home/share/pkp/include/openssl/ec.h
0 /home/share/pkp/include/openssl/ecdh.h
0 /home/share/pkp/include/openssl/ecdsa.h
16K /home/share/pkp/include/openssl/ecerr.h
36K /home/share/pkp/include/openssl/engine.h
8.0K /home/share/pkp/include/openssl/engineerr.h
12K /home/share/pkp/include/openssl/err.h
76K /home/share/pkp/include/openssl/evp.h
12K /home/share/pkp/include/openssl/evperr.h
4.0K /home/share/pkp/include/openssl/hmac.h
4.0K /home/share/pkp/include/openssl/idea.h
8.0K /home/share/pkp/include/openssl/kdf.h
4.0K /home/share/pkp/include/openssl/kdferr.h
8.0K /home/share/pkp/include/openssl/lhash.h
4.0K /home/share/pkp/include/openssl/md2.h
4.0K /home/share/pkp/include/openssl/md4.h
4.0K /home/share/pkp/include/openssl/md5.h
4.0K /home/share/pkp/include/openssl/mdc2.h
12K /home/share/pkp/include/openssl/modes.h
216K /home/share/pkp/include/openssl/obj_mac.h
8.0K /home/share/pkp/include/openssl/objects.h
4.0K /home/share/pkp/include/openssl/objectserr.h
16K /home/share/pkp/include/openssl/ocsp.h
4.0K /home/share/pkp/include/openssl/ocsperr.h
8.0K /home/share/pkp/include/openssl/opensslconf.h
8.0K /home/share/pkp/include/openssl/opensslv.h
8.0K /home/share/pkp/include/openssl/ossl_typ.h
16K /home/share/pkp/include/openssl/pem.h
0 /home/share/pkp/include/openssl/pem2.h
8.0K /home/share/pkp/include/openssl/pemerr.h
12K /home/share/pkp/include/openssl/pkcs12.h
4.0K /home/share/pkp/include/openssl/pkcs12err.h
12K /home/share/pkp/include/openssl/pkcs7.h
8.0K /home/share/pkp/include/openssl/pkcs7err.h
4.0K /home/share/pkp/include/openssl/rand.h
8.0K /home/share/pkp/include/openssl/rand_drbg.h
8.0K /home/share/pkp/include/openssl/randerr.h
4.0K /home/share/pkp/include/openssl/rc2.h
4.0K /home/share/pkp/include/openssl/rc4.h
4.0K /home/share/pkp/include/openssl/rc5.h
4.0K /home/share/pkp/include/openssl/ripemd.h
24K /home/share/pkp/include/openssl/rsa.h
12K /home/share/pkp/include/openssl/rsaerr.h
8.0K /home/share/pkp/include/openssl/safestack.h
4.0K /home/share/pkp/include/openssl/seed.h
4.0K /home/share/pkp/include/openssl/sha.h
4.0K /home/share/pkp/include/openssl/srp.h
4.0K /home/share/pkp/include/openssl/srtp.h
112K /home/share/pkp/include/openssl/ssl.h
0 /home/share/pkp/include/openssl/ssl2.h
16K /home/share/pkp/include/openssl/ssl3.h
48K /home/share/pkp/include/openssl/sslerr.h
4.0K /home/share/pkp/include/openssl/stack.h
12K /home/share/pkp/include/openssl/store.h
8.0K /home/share/pkp/include/openssl/storeerr.h
4.0K /home/share/pkp/include/openssl/symhacks.h
72K /home/share/pkp/include/openssl/tls1.h
24K /home/share/pkp/include/openssl/ts.h
8.0K /home/share/pkp/include/openssl/tserr.h
4.0K /home/share/pkp/include/openssl/txt_db.h
16K /home/share/pkp/include/openssl/ui.h
4.0K /home/share/pkp/include/openssl/uierr.h
4.0K /home/share/pkp/include/openssl/whrlpool.h
44K /home/share/pkp/include/openssl/x509.h
32K /home/share/pkp/include/openssl/x509_vfy.h
8.0K /home/share/pkp/include/openssl/x509err.h
36K /home/share/pkp/include/openssl/x509v3.h
12K /home/share/pkp/include/openssl/x509v3err.h
1.6M /home/share/pkp/include/openssl
3)Finally, I tried other compile commands, but then still do not work.
$ gcc -I/home/share/pkp/include -L/home/share/pkp/lib -lcrypto -lssl -Wall -O3 -Wpedantic -Wno-unuse
d-result -Wno-pointer-sign ot.c -o ot
$ gcc -I/home/share/pkp/include -L/home/share/pkp/lib -lssl -lcrypto -Wall -O3 -Wpedantic -Wno-unuse
d-result -Wno-pointer-sign ot.c -o ot
$ gcc -I/home/share/pkp/include -L/home/share/pkp/lib -lcrypto -lssl -Wall -Wpedantic -Wno-unuse
d-result -Wno-pointer-sign ot.c -o ot
$ gcc -I/home/share/pkp/include -L/home/share/pkp/lib -lcrypto -O3 -Wall -Wpedantic -Wno-unuse
d-result -Wno-pointer-sign ot.c -o ot
4) It seems that the openssl from downloaded source code is conflict with the openssl installed by "apt-get". So I try another method.
./config && make && make test && make install
It will install openssl into the system directory. Then I run
$ gcc -lssl -lcrypto ot.c -o ot
/tmp/ccrFwoa7.o: In function `main':
ot.c:(.text+0x2d): undefined reference to `EVP_get_digestbyname'
ot.c:(.text+0x66): undefined reference to `EVP_MD_CTX_new'
ot.c:(.text+0x82): undefined reference to `EVP_DigestInit_ex'
ot.c:(.text+0x99): undefined reference to `EVP_DigestFinal_ex'
ot.c:(.text+0xa5): undefined reference to `EVP_MD_CTX_free'
collect2: error: ld returned 1 exit status
It still failed. Envn I follow the solution in here trying to statically link libcrypto and libssl. It failed again.
$ gcc -lssl -lcrypto -ldl -lz -static -static-libgcc ot.c -o ot
/tmp/cc39C5Gq.o: In function `main':
ot.c:(.text+0x2d): undefined reference to `EVP_get_digestbyname'
ot.c:(.text+0x66): undefined reference to `EVP_MD_CTX_new'
ot.c:(.text+0x82): undefined reference to `EVP_DigestInit_ex'
ot.c:(.text+0x99): undefined reference to `EVP_DigestFinal_ex'
ot.c:(.text+0xa5): undefined reference to `EVP_MD_CTX_free'
collect2: error: ld returned 1 exit status
I am sure all the static libraries are in the correct location.
$ whereis lib{ssl,crypto,z,dl}.a
libssl: /usr/lib/x86_64-linux-gnu/libssl.a /usr/lib/x86_64-linux-gnu/libssl.so /usr/local/lib/libssl.a /usr/local/lib/libssl.so
libcrypto: /usr/lib/x86_64-linux-gnu/libcrypto.a /usr/lib/x86_64-linux-gnu/libcrypto.so /usr/local/lib/libcrypto.a /usr/local/lib/libcrypto.so /mnt/c/Windows/System32/libcrypto.dll
libz: /usr/lib/x86_64-linux-gnu/libz.a /usr/lib/x86_64-linux-gnu/libz.so
libdl: /usr/lib/x86_64-linux-gnu/libdl.a /usr/lib/x86_64-linux-gnu/libdl.so
5) Come here to post this question.
#include <stdio.h>
#include <openssl/evp.h>
int main(int argc, char *argv[]){
EVP_MD_CTX *mdctx;
const EVP_MD *md;
unsigned char md_value[EVP_MAX_MD_SIZE];
int md_len, i;
md = EVP_get_digestbyname(argv[1]);
if(!md) {
printf("Unknown message digest %s\n", argv[1]);
exit(1);
}
mdctx = EVP_MD_CTX_new();
EVP_DigestInit_ex(mdctx, md, NULL);
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
EVP_MD_CTX_free(mdctx);
printf("Digest is: ");
for (i = 0; i < md_len; i++)
printf("%02x", md_value[i]);
printf("\n");
exit(0);
}
The code should be compiled with no error. But now it shows "undefined reference to `EVP_get_digestbyname'".
You have to put the libraries in the end of the compiling command, like this:
gcc -I/home/share/pkp/include -L/home/share/pkp/lib -Wall -O3 -Wpedantic -Wno-unused-result -Wno-pointer-sign ot.c -o ot -lcrypto -lssl
You can know why here: Why does the library linker flag sometimes have to go at the end using GCC?
I reproduced the error in my machine and this change solved it.

“No rule to make target `clean'. Stop.” issue

Can someone explain please where is the mistake ?
Trying to install drivers for NIC which was download from official website and getting error:
[root#london r8169-6.023.02]# make clean modules
make -C src/ clean
make[1]: Entering directory `/home/av/r8169-6.023.02/src'
make -C /lib/modules/3.10.0-327.36.3.el7.x86_64/build SUBDIRS=/home/av/r8169-6.023.02/src clean
make[2]: Entering directory `/usr/src/kernels/3.10.0-327.36.3.el7.x86_64'
make[2]: *** No rule to make target `clean'. Stop.
make[2]: Leaving directory `/usr/src/kernels/3.10.0-327.36.3.el7.x86_64'
make[1]: *** [clean] Error 2
make[1]: Leaving directory `/home/av/r8169-6.023.02/src'
make: *** [clean] Error 2
[root#london r8169-6.023.02]#
So the manual provided by Realtek says:
If you are running the target kernel, then you should be able to do :
# make clean modules (as root or with sudo)
# make install
# depmod -a
# modprobe r8169
Makefile is:
KFLAG := 2$(shell uname -r | sed -ne 's/^2\.[4]\..*/4/p')x
all: clean modules install
modules:
ifeq ($(KFLAG),24x)
$(MAKE) -C src/ -f Makefile_linux24x modules
else
$(MAKE) -C src/ modules
endif
clean:
ifeq ($(KFLAG),24x)
$(MAKE) -C src/ -f Makefile_linux24x clean
else
$(MAKE) -C src/ clean
endif
install:
ifeq ($(KFLAG),24x)
$(MAKE) -C src/ -f Makefile_linux24x install
else
$(MAKE) -C src/ install
endif
Additional info
[root#london r8169-6.023.02]# lsmod | grep r8169
[root#london r8169-6.023.02]#
and directory with Makefile
[root#london r8169-6.023.02]# ls -lah
total 24K
drwxrwxrwx 3 root root 4.0K Sep 26 16:50 .
drwx------. 4 av av 4.0K Nov 28 16:21 ..
-rwxrwxrwx 1 root root 2.0K Oct 20 10:23 Makefile
-rwxrwxrwx 1 root root 4.4K Oct 20 10:23 readme
drwxrwxrwx 2 root root 4.0K Sep 26 16:50 src
[root#london r8169-6.023.02]#
Thanks in advance
Dont worry..
There are only some packages need to be intalled.
type sudo synaptic in terminal and enter.
in search box type qt4-qmake and mark for installation.
then same as above search libqt4-dev and libxml2-dev and do the same mark for installation simultaneously.
then apply without check the download option.
Then go to cd netanim directory and type make clean and enter,
if it does not work type qmake NetAnim.pro and enter, it takes couple of seconds.
then type make and enter.
Here its done, it will take less then a minute.
Now in netanim directory tyoe ./NetAnim and enter.
Here you will see animation interface.
Good luck

Makefile dependencies variable

I have a simple Makefile. When i'm NOT using a variable in dependencies list it works fine. Otherwise it gives fallowing error:
make: *** No rule to make target 'ext/configXML.o', needed by 'libledrgb-jni.so'. Stop.
Furthermore when i do
make print-LED-CFG-SRC
LED-CFG-SRC = ../led-cfg/src
So the value is set properly, altough if I explicitly add rule for this file:
ext/configXML.o: $(LED-CFG-SRC)/%.cc
#echo 'Building file: $<'
#${CXX} $(CXXFLAGS) -c -o "$#" "$<"
It looks like the problem is with the LED-CFG-SRC to source file:
make ext/configXML.o
make: *** No rule to make target '/configXML.cc', needed by 'ext/configXML.o'. Stop.
But the file exists:
make list
ls -la ../led-cfg/src
total 340
drwxrwxr-x 2 gigi gigi 4096 lip 27 13:10 .
drwxrwxr-x 12 gigi gigi 4096 lip 28 10:08 ..
-rw-rw-r-- 1 gigi gigi 11918 lip 28 09:54 configXML.cc
-rw-rw-r-- 1 gigi gigi 2891 lip 27 13:17 configXML.h
Here's the source Makefile:
EXTOBJS = ext/configXML.o ext/packet.o ext/tinyxml2.o ext/crypt.o ext/rozkaz.o
LED-CFG-SRC := ../led-cfg/src/
INCLUDES := -I$(LED-CFG-SRC)
CXXFLAGS := $(INCLUDES)
LIBRARY := libledrgb-jni.so
CXXFLAGS := $(INCLUDES) -fPIC -std=c++14
all: dirs $(LIBRARY)
$(LIBRARY): $(OBJFILES) $(EXTOBJS)
$(CXX) -shared -o $# $^
ext/%.o: $(LED-CFG-SRC)/%.cc
#echo 'Building file: $<'
#${CXX} $(CXXFLAGS) -c -o "$#" "$<"
clean:
rm -rf $(EXTOBJS)
list:
ls -la $(LED-CFG-SRC)
print-% : ; #echo $* = $($*)
.PHONY: clean dirs
I'm using GNU Make 4.1
Shot in the dark. At least in the Makefile listing you have posted, there is a redundant undesired whitespace in the definition of the LED-CFG-SRC variable:
LED-CFG-SRC := ../led-cfg/src/<there-is-reduntant-whitespace-here>
That means, when the variable is expanded in the rule definition later, the make would see ../led-cfg/src/ %.cc (two words, $< = ../led-cfg/src/, and %.cc being only as a additional dependency) instead of the expected ../led-cfg/src/%.cc.
You should activate display of non-printable characters in your editor, since make in places is extremely picky about the whitespaces: some it chooses to strip automatically, but some it keeps. Like here: make had stipped the whitespace in the front of the ../led-cfg/src/, but it kept the one at the end.

How can I automatically create (and remove) a temp directory in a Makefile?

Is it possible to have make create a temp directory before it executes the first target? Maybe using some hack, some additional target etc.?
All commands in the Makefile would be able to refer to the automatically created directory as $TMPDIR, and the directory would be automatically removed when the make command ends.
These previous answers either didn't work or seemed overly complicated. Here is a far more straight forward example I was able to figure out:
PACKAGE := "audit"
all:
$(eval TMP := $(shell mktemp -d))
#mkdir $(TMP)/$(PACKAGE)
rm -rf $(TMP)
With GNU make, at least,
TMPDIR := $(shell mktemp -d)
will get you your temporary directory. I can't come up with a good way to clean it up at the end, other than the obvious rmdir "$(TMPDIR)" as part of the all target.
See Getting the name of the makefile from the makefile for the $(self) trick
ifeq ($(tmpdir),)
location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
self := $(location)
%:
#tmpdir=`mktemp --tmpdir -d`; \
trap 'rm -rf "$$tmpdir"' EXIT; \
$(MAKE) -f $(self) --no-print-directory tmpdir=$$tmpdir $#
else
# [your real Makefile]
%:
#echo Running target $# with $(tmpdir)
endif
I seem to recall being able to call make recursively, something along the lines of:
all:
-mkdir $(TEMPDIR)
$(MAKE) $(MFLAGS) old_all
-rm -rf $(TEMPDIR)
old_all: ... rest of stuff.
I've done similar tricks for calling make in subdirectories:
all:
#for i in $(SUBDIRS); do \
echo "make all in $$i..."; \
(cd $$i; $(MAKE) $(MFLAGS) all); \
done
Just checked it and this works fine:
$ cat Makefile
all:
-mkdir tempdir
-echo hello >tempdir/hello
-echo goodbye >tempdir/goodbye
$(MAKE) $(MFLAGS) old_all
-rm -rf tempdir
old_all:
ls -al tempdir
$ make all
mkdir tempdir
echo hello >tempdir/hello
echo goodbye >tempdir/goodbye
make old_all
make[1]: Entering directory '/home/pax'
ls -al tempdir
total 2
drwxr-xr-x+ 2 allachan None 0 Feb 26 15:00 .
drwxrwxrwx+ 4 allachan None 0 Feb 26 15:00 ..
-rw-r--r-- 1 allachan None 8 Feb 26 15:00 goodbye
-rw-r--r-- 1 allachan None 6 Feb 26 15:00 hello
make[1]: Leaving directory '/home/pax'
rm -rf tempdir
$ ls -al tempdir
ls: cannot access tempdir: No such file or directory

Resources