1

I have a swift project and I am trying to call C++ libraries from it. I have several .h files that I have included in project (added them in Project > Build Settings > Header Search Paths). Then created a build header:

client-Bridging-header

#import "DongleWrapper.hpp"

Created a wrapper DongleWrapper.hpp


#import "Dongle.hpp"
@implementation DongleWrapper

- (DongleWrapper*) init {
  dong = (void*)new Dongle;  // create c++ class instance
  return self;           // return objc++ instance
}

- (void) generateKeyPair {
  Dongle* d = (Dongle*)dong;
  d->generateKeyPair();  // call c++ method
}

@end

Created a C++ header Dongle.hpp

#ifndef Dongle_hpp
#define Dongle_hpp

#include <stdio.h>

#endif /* Dongle_hpp */

class Dongle {
    public:
        void generateKeyPair();
};

And then finally created the C++ file Dongle.cpp

#include "Include/pkcs.h"

void Dongle::generateKeyPair() {
   ...
}

Note that, I have included a header file here. But I am getting an error:

Full Log

Undefined symbols for architecture arm64:
  "_C_GenerateKeyPair", referenced from:
      Dongle::generateKeyPair() in Dongle.o
  "_C_Login", referenced from:
      Dongle::generateKeyPair() in Dongle.o
  "_C_Logout", referenced from:
      Dongle::generateKeyPair() in Dongle.o
  "_fl", referenced from:
      FindObjects(unsigned long, CK_ATTRIBUTE*, unsigned long) in Dongle.o
     (maybe you meant: _CNIOBoringSSL_EVP_CIPHER_flags, _CNIOBoringSSL_X509_VERIFY_PARAM_set_flags , _c_nio_llhttp__internal__c_or_flags_15 , _CNIOBoringSSL_EC_GROUP_get_asn1_flag , _c_nio_llhttp__internal__c_test_flags_2 , _CNIOBoringSSL_BIO_flush , _CNIOBoringSSL_X509_VERIFY_PARAM_get_flags , _CNIOBoringSSL_X509_VERIFY_PARAM_clear_flags , _c_nio_llhttp__internal__c_test_lenient_flags , _CNIOBoringSSL_X509_STORE_CTX_set_flags , _c_nio_llhttp__internal__c_or_flags_3 , _c_nio_llhttp__internal__c_or_flags_6 , _CNIOBoringSSL_X509_STORE_set_flags , _$s7NIOCore15EventLoopFutureC8_flatMapyACyqd__GAExYbclF , _CNIOBoringSSL_BIO_clear_flags , _c_nio_llhttp__internal__c_test_lenient_flags_2 , _c_nio_llhttp__internal__c_or_flags_5 , _CNIOBoringSSL_EVP_CIPHER_CTX_flags , _CNIOBoringSSL_CBB_flush , _c_nio_llhttp__internal__c_test_flags_3 , _CNIOBoringSSL_BIO_get_retry_flags , _$s7NIOCore9EventLoopPAAE17_flatScheduleTask2in4file4line_AA9ScheduledVyqd__GAA10TimeAmountV_s12StaticStringVSuAA0bC6FutureCyqd__GyYbKctlF , _CNIOBoringSSL_SSL_CTX_flush_sessions , _c_nio_llhttp__internal__c_test_lenient_flags_7 , _$s7NIOCore9EventLoopPAAE11_flatSubmityAA0bC6FutureCyqd__GAGyYbclF , _CNIOBoringSSL_BIO_clear_retry_flags , _$s7NIOCore15EventLoopFutureC16_flatMapBlocking4onto_ACyqd__GSo17OS_dispatch_queueC_qd__xYbKctlF , _CNIOBoringSSL_EC_KEY_set_enc_flags , _CNIOBoringSSL_RSA_test_flags , _c_nio_llhttp__internal__c_or_flags_18 , _CNIOBoringSSL_CBB_flush_asn1_set_of , _CNIOBoringSSL_EC_GROUP_set_asn1_flag , _$s7NIOCore9EventLoopPAAE17_flatScheduleTask8deadline4file4line_AA9ScheduledVyqd__GAA11NIODeadlineV_s12StaticStringVSuAA0bC6FutureCyqd__GyYbKctlF , _c_nio_llhttp__internal__c_and_flags , _CNIOBoringSSL_EVP_MD_meth_get_flags , bssl::CNIOBoringSSL::dtls1_flush_flight(CNIOBoringSSL_ssl_st*) , _c_nio_llhttp__internal__c_test_flags , _CNIOBoringSSL_SSL_quic_max_handshake_flight_len , _CNIOBoringSSL_X509_get_extension_flags , _CNIOBoringSSL_EC_KEY_get_enc_flags , _$s7NIOCore15EventLoopFutureC21_flatMapErrorThrowingyACyxGxs0G0_pYbKcF , _CNIOBoringSSL_EVP_MD_CTX_set_flags , bssl::CNIOBoringSSL::tls_flush_pending_hs_data(CNIOBoringSSL_ssl_st*) , _c_nio_llhttp__internal__c_or_flags_16 , _CNIOBoringSSL_EVP_CIPHER_CTX_set_flags , _CNIOBoringSSL_EVP_MD_flags , _c_nio_llhttp__internal__c_test_flags_1 , _c_nio_llhttp__internal__c_test_lenient_flags_1 , _CNIOBoringSSL_EC_KEY_set_asn1_flag , _CNIOBoringSSL_X509_TRUST_get_flags , _$s7NIOCore15EventLoopFutureC13_flatMapErroryACyxGAEs0G0_pYbcF , _c_nio_llhttp__internal__c_test_lenient_flags_5 , _CNIOBoringSSL_BIO_set_flags , _c_nio_llhttp__internal__c_or_flags_4 , _c_nio_llhttp__internal__c_or_flags_1 , _CNIOBoringSSL_BIO_test_flags , bssl::CNIOBoringSSL::ssl_write_buffer_flush(CNIOBoringSSL_ssl_st*) , bssl::CNIOBoringSSL::tls_flush_flight(CNIOBoringSSL_ssl_st*) , _c_nio_llhttp__internal__c_or_flags , _CNIOBoringSSL_RSA_flags , _$s7NIOCore15EventLoopFutureC16_flatMapThrowingyACyqd__Gqd__xYbKclF , _$s7NIOCore15EventLoopFutureC14_flatMapResultyACyqd__Gs0G0Oyqd__qd_0_GxYbcs5ErrorRd_0_r0_lF )
ld: symbol(s) not found for architecture arm64

I am using and M1 Pro with Mac OS Ventura 13.3.1, Xcode 14.3 (14E222b) and Apple clang version 14.0.3 (Target: arm64-apple-darwin22.4.0).

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
desertSniper87
  • 795
  • 2
  • 13
  • 25
  • Please show a [mre], the errors don't seem related to your code. Does `DongleWrapper.hpp` really include itself? – Alan Birtles May 28 '23 at 07:35
  • Sorry, Updated my code `DongleWrapper.hpp` doesn't include itself. Will include more examples. – desertSniper87 May 28 '23 at 08:11
  • ok, so looking at the actual build log rather than your summary it makes more sense, the code (which you've omitted) inside `Dongle::generateKeyPair` is referencing some other code which you've not provided a definition for – Alan Birtles May 28 '23 at 08:25
  • I was able to solve it. I wasn't including the **dylib** files that was required. – desertSniper87 May 28 '23 at 16:52

0 Answers0