# Static linking (on Mac x64)

**URL:** <https://community.solace.com/t/static-linking-on-mac-x64/1532>\
**Category:** General Discussions\
**Tags:** ccsmp\
**Created:** [January 6, 2023, 10:23am UTC](https://community.solace.com/t/static-linking-on-mac-x64/1532 "2023-01-06T10:23:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![radekm](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/radekm/32/901_2.png) [@radekm](https://community.solace.com/u/radekm)\
**Post date:** [January 6, 2023, 10:23am UTC](https://community.solace.com/t/static-linking-on-mac-x64/1532/1 "2023-01-06T10:23:20Z")

</div>

Hello,  
normally I use dynamic linking with solclient library and it works as expected.  
Out of curiosity I tried static linking. I linked following  
libsolclient.a , libsolclientssl.a , libcrypto.a , libssl.a and Kerberos framework. When I run my app it fails with EXC\_BAD\_ACCESS when running solClient\_cleanup according to LLDB it calls \_solClient\_transactedSession\_failAllThreads which calls JudyLFirstEmpty .  
I use solclient-7.24.0.9 on Mac with x64 architecture.  
My question is whether there is some example or tutorial explaining how to do static linking on Mac? For example there’s also solClientSSLStaticLinkEnable.o which I don’t link because then I have duplicate symbols. So I’m confused why is solClientSSLStaticLinkEnable.o in the package or what should I do with it?  
Thanks

---

<div class="post-metadata">

**Author:** ![marc](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/marc/32/2191_2.png) [@marc](https://community.solace.com/u/marc)\
**Post date:** [January 6, 2023, 4:07pm UTC](https://community.solace.com/t/static-linking-on-mac-x64/1532/2 "2023-01-06T16:07:04Z")

</div>

Great question @radekm . I don’t recall anyone using static linking on Mac before. We’ll look into this and get back to you.

---

<div class="post-metadata">

**Author:** ![Ragnar](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/ragnar/32/180_2.png) [@Ragnar](https://community.solace.com/u/Ragnar)\
**Post date:** [January 6, 2023, 6:01pm UTC](https://community.solace.com/t/static-linking-on-mac-x64/1532/3 "2023-01-06T18:01:40Z")

</div>

Hello @radekm .

Can you provide a small project to demonstrate how you are linking and getting this error?  
Generally I expect problems with static linking to occur at linking not at run time. Once you’ve successfully created the executable, the run-time exception may be something else entirely.  
That said, I also expect that you need to include solClientSSLStaticLinkEnable.o in your link-edit command and it must occur before libssl.a and libcrypto.a in the command. If you do not include this, it is likely the library is still trying to dynamically load libssl.so/libcrypto.so. This still should not lead to the EXC\_BAD\_ACCESS but instead to a dynamic loading issue at run-time.  
If you are getting duplicate symbol errors at link-edit time, can you tell us what symbols are duplicated. And again provide a small project/makefile to demonstrate this so we can debug it.  
Finally, just for thoroughness, are you using TLS in your test (libssl/libcrypto) and GSS (Kerberos) both? Do you use Kerberos for authentication and TLS for encryption. I don’t think this will lead to a failure in JudyFirstLempty, but I do want to understand your test scenario so I can try to reproduce it.

---

<div class="post-metadata">

**Author:** ![radekm](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/radekm/32/901_2.png) [@radekm](https://community.solace.com/u/radekm)\
**Post date:** [January 13, 2023, 1:51pm UTC](https://community.solace.com/t/static-linking-on-mac-x64/1532/4 "2023-01-13T13:51:10Z")

</div>

That said, I also expect that you need to include solClientSSLStaticLinkEnable.o in your link-edit command and it must occur before libssl.a and libcrypto.a in the command. \> I tried  
clang solace\_lib/solClientSSLStaticLinkEnable.o solace\_lib/libssl.a solace\_lib/libcrypto.a solace\_lib/libsolclient.a -framework kerberos connect.c

> but still getting lots of duplicate symbol errors. The first few of them are  
> duplicate symbol ‘\_\_SSL\_set\_verify’ in:  
> &nbsp;&nbsp;&nbsp; solace\_lib/solClientSSLStaticLinkEnable.o  
> &nbsp;&nbsp;&nbsp; solace\_lib/libsolclient.a(solClientSSL.o)  
> duplicate symbol ‘\_\_SSL\_use\_cert\_and\_key’ in:  
> &nbsp;&nbsp;&nbsp; solace\_lib/solClientSSLStaticLinkEnable.o  
> &nbsp;&nbsp;&nbsp; solace\_lib/libsolclient.a(solClientSSL.o)  
> duplicate symbol ‘\_\_d2i\_PrivateKey’ in:  
> &nbsp;&nbsp;&nbsp; solace\_lib/solClientSSLStaticLinkEnable.o  
> &nbsp;&nbsp;&nbsp; solace\_lib/libsolclient.a(solClientSSL.o)  
> It’s very basic program. But seems not to link if I omit Kerberos framework.  
> #include \<stdio.h\>  
> #define SOLCLIENT\_CONST\_PROPERTIES 1  
> #include “solclient/solClient.h”  
> #include “solclient/solClientMsg.h”  
> solClient\_rxMsgCallback\_returnCode\_t sessionMessageReceiveCallback (  
> solClient\_opaqueSession\_pt session,  
> solClient\_opaqueMsg\_pt msg,  
> void \*data  
> ) {  
> return SOLCLIENT\_CALLBACK\_OK;  
> }  
> void sessionEventCallback (  
> solClient\_opaqueSession\_pt opaqueSession\_p,  
> solClient\_session\_eventCallbackInfo\_pt eventInfo\_p,  
> void \*user\_p  
> ) {  
> }  
> int main()  
> {  
> printf(“Starting\n”);  
> solClient\_initialize(SOLCLIENT\_LOG\_INFO, NULL);  
> const char \*contextProps[50] = {0, };  
> int propIndexC = 0;  
> contextProps[propIndexC++] = SOLCLIENT\_CONTEXT\_PROP\_CREATE\_THREAD;  
> contextProps[propIndexC++] = SOLCLIENT\_PROP\_ENABLE\_VAL;  
> contextProps[propIndexC++] = NULL;  
> solClient\_opaqueContext\_pt context;  
> solClient\_context\_createFuncInfo\_t contextFuncInfo = SOLCLIENT\_CONTEXT\_CREATEFUNC\_INITIALIZER;  
> solClient\_context\_create(  
> //SOLCLIENT\_CONTEXT\_PROPS\_DEFAULT\_WITH\_CREATE\_THREAD,  
> contextProps,  
> &context,  
> &contextFuncInfo,  
> sizeof(contextFuncInfo)  
> );  
> solClient\_opaqueSession\_pt session;  
> solClient\_session\_createFuncInfo\_t sessionFuncInfo = SOLCLIENT\_SESSION\_CREATEFUNC\_INITIALIZER;  
> sessionFuncInfo.rxMsgInfo.callback\_p = sessionMessageReceiveCallback;  
> sessionFuncInfo.rxMsgInfo.user\_p = NULL;  
> sessionFuncInfo.eventInfo.callback\_p = sessionEventCallback;  
> sessionFuncInfo.eventInfo.user\_p = NULL;  
> const char \*sessionProps[50] = {0, };  
> int propIndex = 0;  
> sessionProps[propIndex++] = SOLCLIENT\_SESSION\_PROP\_HOST;  
> sessionProps[propIndex++] = “foo”;  
> sessionProps[propIndex++] = SOLCLIENT\_SESSION\_PROP\_USERNAME;  
> sessionProps[propIndex++] = “bar”;  
> sessionProps[propIndex++] = SOLCLIENT\_SESSION\_PROP\_PASSWORD;  
> sessionProps[propIndex++] = “”;  
> sessionProps[propIndex++] = SOLCLIENT\_SESSION\_PROP\_VPN\_NAME;  
> sessionProps[propIndex++] = “default”;  
> sessionProps[propIndex++] = SOLCLIENT\_SESSION\_PROP\_CONNECT\_BLOCKING;  
> sessionProps[propIndex++] = SOLCLIENT\_PROP\_ENABLE\_VAL;  
> sessionProps[propIndex++] = SOLCLIENT\_SESSION\_PROP\_SUBSCRIBE\_BLOCKING;  
> sessionProps[propIndex++] = SOLCLIENT\_PROP\_ENABLE\_VAL;  
> sessionProps[propIndex++] = SOLCLIENT\_SESSION\_PROP\_RECONNECT\_RETRIES;  
> sessionProps[propIndex++] = “0”;  
> sessionProps[propIndex++] = NULL;  
> solClient\_session\_create(  
> (const char \*\*)sessionProps,  
> context,  
> &session,  
> &sessionFuncInfo,  
> sizeof(sessionFuncInfo)  
> );  
> solClient\_cleanup();  
> printf(“Finishing\n”);  
> return 0;  
> }
