# Static library seems not properly generated

**URL:** <https://openfhe.discourse.group/t/static-library-seems-not-properly-generated/362>\
**Category:** Library Questions\
**Created:** [February 15, 2023, 9:12am UTC](https://openfhe.discourse.group/t/static-library-seems-not-properly-generated/362 "2023-02-15T09:12:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adki](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@adki](https://openfhe.discourse.group/u/adki)\
**Post date:** [February 15, 2023, 9:12am UTC](https://openfhe.discourse.group/t/static-library-seems-not-properly-generated/362/1 "2023-02-15T09:12:54Z")

</div>

I tried to get static library by using following CMake options;

```
    cmake -S .\
          -DCMAKE_BUILD_TYPE=Release\
          -DCMAKE_INSTALL_PREFIX=${DIR_PREFIX}\
          -DMATHBACKEND=2\
          -DWITH_OPENMP="OFF"\
          -DBUILD_DYNAMIC=OFF\
          -DBUILD_STATIC=ON\
          -DCMAKE_CXX_FLAGS="-g "\
          ..

```

It generates following static libraries along with dynamic libraries.  
libOPENFHEbinfhe.so  
libOPENFHEbinfhe.so.1  
libOPENFHEbinfhe.so.1.0.2  
libOPENFHEbinfhe\_static.a  
libOPENFHEcore.so  
libOPENFHEcore.so.1  
libOPENFHEcore.so.1.0.2  
libOPENFHEcore\_static.a  
libOPENFHEpke.so  
libOPENFHEpke.so.1  
libOPENFHEpke.so.1.0.2  
libOPENFHEpke\_static.a

However "undefined reference " errors occur while liking stage as followings.  
g++ -c -g -O0 -Werror -std=c++11 -I/include -Iopenfhe/include/openfhe -Iopenfhe/include/openfhe/core -Iopenfhe/include/openfhe/pke src/main.cpp -o obj/main.o  
g++ -o test -O0  
obj/main.o  
-Wl,-Bstatic -Lopenfhe/lib -lOPENFHEbinfhe\_static -lOPENFHEcore\_static -lOPENFHEpke\_static -Wl,-Bdynamic -lntl  
/usr/bin/ld: openfhe/lib/libOPENFHEpke\_static.a(bfvrns-parametergeneration.cpp.o): in function `lbcrypto::StdLatticeParm::FindRingDim(lbcrypto::DistributionType, lbcrypto::SecurityLevel, unsigned int)': openfhe/openfhe-development/src/core/include/lattice/stdlatticeparms.h:139: undefined reference to `lbcrypto::StdLatticeParm::initialized’  
/usr/bin/ld: openfhe/openfhe-development/src/core/include/lattice/stdlatticeparms.h:139: undefined reference to `lbcrypto::StdLatticeParm::byLogQ' /usr/bin/ld: openfhe/lib/libOPENFHEpke_static.a(bfvrns-parametergeneration.cpp.o): in function `lbcrypto::StdLatticeParm::initializeLookups()‘:  
openfhe/openfhe-development/src/core/include/lattice/stdlatticeparms.h:119: undefined reference to `lbcrypto::StdLatticeParm::StandardLatticeParmSets' /usr/bin/ld: openfhe/openfhe-development/src/core/include/lattice/stdlatticeparms.h:119: undefined reference to `lbcrypto::StdLatticeParm::StandardLatticeParmSets’  
…  
~

---

<div class="post-metadata">

**Author:** ![dcousins](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/dcousins/32/71_2.png) [@dcousins](https://openfhe.discourse.group/u/dcousins)\
**Post date:** [February 15, 2023, 4:39pm UTC](https://openfhe.discourse.group/t/static-library-seems-not-properly-generated/362/2 "2023-02-15T16:39:22Z")

</div>

it may be that you are linking libraries out of order. try linking core first then pke then binfhe  
note you do not need binfhe if you are not using the binfhe schemes.

---

<div class="post-metadata">

**Author:** ![adki](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@adki](https://openfhe.discourse.group/u/adki)\
**Post date:** [February 16, 2023, 1:35am UTC](https://openfhe.discourse.group/t/static-library-seems-not-properly-generated/362/3 "2023-02-16T01:35:48Z")

</div>

It has been solved and it was linking order problem.

Use following order;  
-L$(DIR\_OPENFHE\_LIB)   
-lOPENFHEpke\_static  
-lOPENFHEcore\_static

or use linking group option as follows.  
-Wl,–start-group -L$(DIR\_OPENFHE\_LIB) -lOPENFHEpke\_static -lOPENFHEcore\_static -Wl,–end-group
