-1

How to properly build these 2 static libraries and use them for my code? No matter what I try I get some compilation errors in my test program. I followed the official steps, but it didn't work and internet didn't give me an answer...

Here is what I do to build tomsfastmath:

git clone https://github.com/libtom/tomsfastmath.git
cd tomsfastmath
sudo make install

And here is what I do to install libtomcrypt:

git clone https://github.com/libtom/libtomcrypt.git
cd libtomcrypt
sudo make CFLAGS="-DUSE_TFM -DTFM_DESC" EXTRALIBS="-ltfm" install

I tried only sudo make install, but it didn't seem to solve my issue. I only got undefinded reference to `tfm_desc' in that case, instead of the current error...

And here is how I compile my code:

g++ "%f" -o "%e" -pipe -fwrapv -fno-plt -fno-semantic-interposition -std=c++20 -mcmodel=large -march=x86-64 -mtune=generic -Wshadow -Wno-unused-result -Wall -O3 -L /usr/lib -Wl,--as-needed -lm -lz -lpthread -lutil -ldl -lrt -lcrypt -lgcrypt -Wl,-Bstatic -ltfm -ltomcrypt -Wl,-Bdynamic

It's my full g++ command, I provide it whole because I don't understand this command fully so you might catch a silly mistake...

This is essentially my whole code (without some empty functions):

#include <cstdio>
#include <cstdlib>
#include <cstring>
#define TFM_DESC
#include <tomcrypt.h>

int main(){
    ltc_mp=tfm_desc;
}

And this is the error I am getting:

g++ "crypt.cpp" -o "crypt" -pipe -fwrapv -fno-plt -fno-semantic-interposition -std=c++20 -mcmodel=large -march=x86-64 -mtune=generic -Wshadow -Wno-unused-result -Wall -O3 -L /usr/lib -Wl,--as-needed -lm -lz -lpthread -lutil -ldl -lrt -lcrypt -lgcrypt -Wl,-Bstatic -ltfm -ltomcrypt -Wl,-Bdynamic (in directory: /home/korsic/Documents/c++__projekti/traktor)
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `tfm_ecc_projective_dbl_point':
tfm_desc.c:(.text+0x1b8): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x1c6): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x1d6): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x1e5): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x1f4): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x200): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x220): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x22e): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x23e): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x24c): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x257): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x265): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x273): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x27e): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x295): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x2a0): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x2b7): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x2c2): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x2da): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x2e6): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x2fb): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x30a): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x316): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x324): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x349): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x357): undefined reference to `fp_div_2'
/usr/bin/ld: tfm_desc.c:(.text+0x366): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x375): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x380): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x38e): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x39d): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x3a7): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0x3bf): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x3c9): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0x3e1): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x3ec): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0x404): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x413): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x422): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x42d): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0x445): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x45b): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x472): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x48a): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x4a3): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x4ba): undefined reference to `fp_sub'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o):tfm_desc.c:(.text+0x4d2): more undefined references to `fp_sub' follow
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `tfm_ecc_projective_dbl_point':
tfm_desc.c:(.text+0x4dc): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0x4f3): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x4fe): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x511): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x51f): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x543): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x55a): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x572): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x58a): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x5a2): undefined reference to `fp_add'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `tfm_ecc_projective_add_point':
tfm_desc.c:(.text+0x7d0): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x7dc): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x7ff): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x81a): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x834): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x8b1): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x8c4): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x8d4): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x8e4): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x8f3): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x901): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x911): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x921): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x92e): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0x941): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x950): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x95e): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x96e): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x97c): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x98b): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0x999): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0x9ac): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x9b6): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0x9cd): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0x9d8): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0x9eb): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0x9fb): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0xa06): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0xa19): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xa2c): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xa36): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0xa4d): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0xa58): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0xa6b): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xa7b): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0xa86): undefined reference to `fp_cmp'
/usr/bin/ld: tfm_desc.c:(.text+0xa99): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xab2): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0xac2): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xad7): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0xaec): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xafa): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0xb08): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xb13): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0xb21): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xb2f): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0xb3d): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xb4b): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0xb59): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xb66): undefined reference to `fp_sqr'
/usr/bin/ld: tfm_desc.c:(.text+0xb74): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xb82): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xb8c): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0xba5): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xbaf): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0xbc8): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xbd2): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0xbee): undefined reference to `fp_mul'
/usr/bin/ld: tfm_desc.c:(.text+0xbfe): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: tfm_desc.c:(.text+0xc0c): undefined reference to `fp_sub'
/usr/bin/ld: tfm_desc.c:(.text+0xc16): undefined reference to `fp_cmp_d'
/usr/bin/ld: tfm_desc.c:(.text+0xc47): undefined reference to `fp_div_2'
/usr/bin/ld: tfm_desc.c:(.text+0xd4c): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0xd64): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0xd7c): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0xd94): undefined reference to `fp_add'
/usr/bin/ld: tfm_desc.c:(.text+0xdaa): undefined reference to `fp_add'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o):tfm_desc.c:(.text+0xdc2): more undefined references to `fp_add' follow
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `set_rand':
tfm_desc.c:(.text+0xf2a): undefined reference to `fp_rand'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `submod':
tfm_desc.c:(.text+0xf6d): undefined reference to `fp_submod'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `addmod':
tfm_desc.c:(.text+0x101d): undefined reference to `fp_addmod'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `sqr':
tfm_desc.c:(.text+0x13ef): undefined reference to `fp_sqr'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `montgomery_reduce':
tfm_desc.c:(.text+0x1447): undefined reference to `fp_montgomery_reduce'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `mul':
tfm_desc.c:(.text+0x14b4): undefined reference to `fp_mul'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `add':
tfm_desc.c:(.text+0x1524): undefined reference to `fp_add'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `compare':
tfm_desc.c:(.text+0x158f): undefined reference to `fp_cmp'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `sub':
tfm_desc.c:(.text+0x15f4): undefined reference to `fp_sub'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `compare_d':
tfm_desc.c:(.text+0x165a): undefined reference to `fp_cmp_d'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `div_2':
tfm_desc.c:(.text+0x169f): undefined reference to `fp_div_2'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `isprime':
tfm_desc.c:(.text+0x16f9): undefined reference to `fp_isprime_ex'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `exptmod':
tfm_desc.c:(.text+0x175d): undefined reference to `fp_exptmod'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `montgomery_normalization':
tfm_desc.c:(.text+0x182f): undefined reference to `fp_montgomery_calc_normalization'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `montgomery_setup':
tfm_desc.c:(.text+0x18e9): undefined reference to `fp_montgomery_setup'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `invmod':
tfm_desc.c:(.text+0x1974): undefined reference to `fp_invmod'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `sqrmod':
tfm_desc.c:(.text+0x1a04): undefined reference to `fp_sqrmod'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `mulmod':
tfm_desc.c:(.text+0x1a9d): undefined reference to `fp_mulmod'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `lcm':
tfm_desc.c:(.text+0x1b44): undefined reference to `fp_lcm'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `gcd':
tfm_desc.c:(.text+0x1bb4): undefined reference to `fp_gcd'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `modi':
tfm_desc.c:(.text+0x1c36): undefined reference to `fp_mod_d'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `divide':
tfm_desc.c:(.text+0x1ccf): undefined reference to `fp_div'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `muli':
tfm_desc.c:(.text+0x1d3f): undefined reference to `fp_mul_d'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `subi':
tfm_desc.c:(.text+0x1d8f): undefined reference to `fp_sub_d'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `addi':
tfm_desc.c:(.text+0x1ddf): undefined reference to `fp_add_d'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `unsigned_read':
tfm_desc.c:(.text+0x1e2f): undefined reference to `fp_read_unsigned_bin'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `unsigned_write':
tfm_desc.c:(.text+0x1e7f): undefined reference to `fp_to_unsigned_bin'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `unsigned_size':
tfm_desc.c:(.text+0x1eca): undefined reference to `fp_unsigned_bin_size'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `write_radix':
tfm_desc.c:(.text+0x1eff): undefined reference to `fp_toradix'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `read_radix':
tfm_desc.c:(.text+0x1f6f): undefined reference to `fp_read_radix'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `twoexpt':
tfm_desc.c:(.text+0x1fda): undefined reference to `fp_2expt'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `set_int':
tfm_desc.c:(.text+0x206a): undefined reference to `fp_set'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `count_lsb_bits':
tfm_desc.c:(.text+0x2006): undefined reference to `fp_cnt_lsb'
/usr/bin/ld: /usr/local/lib/libtomcrypt.a(tfm_desc.o): in function `count_bits':
tfm_desc.c:(.text+0x2036): undefined reference to `fp_count_bits'
collect2: error: ld returned 1 exit status
Compilation failed.

I don't know what useful I can say more, I have been trying whatever came to my mind which is not much, I could only follow the official git... I just want my code to compile normally, I am trying to compile an example RSA encrypt code that is provided in the official manual https://github.com/libtom/libtomcrypt/releases/download/v1.18.2/crypt-1.18.2.pdf on page 96. How do I do it properly?

Nimantha
  • 5,793
  • 5
  • 23
  • 56

0 Answers0