Error: Unresolved external 'std::_String_base::_Xlen() const' referenced from-and others when compiling project in C++Builder11 - c++builder-11-alexandria

As per title, I have 9 linker errors as follows:
[ilink32 Error] Error: Unresolved external 'std::_String_base::_Xran() const' referenced from
[ilink32 Error] Error: Unresolved external '__InitExceptBlockLDTC' referenced from
[ilink32 Error] Error: Unresolved external 'std::_String_base::_Xlen() const' referenced from
[ilink32 Error] Error: Unresolved external '_ReThrowException(unsigned int, unsigned char *)' referenced from
[ilink32 Error] Error: Unresolved external '_CatchCleanup()' referenced from
[ilink32 Error] Error: Unresolved external '__fastcall __DynamicCastVCLptr(void *, void *)' referenced from
[ilink32 Error] Error: Unresolved external '_ThrowExceptionLDTC(void *, void *, void *, void *, unsigned int, unsigned int, unsigned int, unsigned char *, void *)' referenced from
[ilink32 Error] Error: Unresolved external '__Return_unwind' referenced from
These references refer to custom components written in C++Builder 10.1, 10.2 Berlin, and compile and used in projects without too much fuss.
The unfortunate thing about this is that I have not come across any real solutions for this in reference to C++Builder, found here: Linker error LNK2001 unresolved external std::_String_base::_Xlen.
When I loaded the project into C++Builder 10.4, installed just today, apart from a couple of migration errors corrected quickly, the components installed into the component pallet but linker errors occurred when compiling the project that uses the components.
I have searched for any reference to the linker error, maybe I am using the wrong search engine, I will not use Google so, any pointing in the right direction would be very much appreciated.
I tried searching for solutions by asking questions in the search engines, no useful answers were found, with little to no detailed in C++Builder (not unusual), so I came here to ask the experts.

Answered here to help others.
A thought crossed my mind, so I checked the compiler version, Use 'Classic' Borland compiler was unchecked, when I checked the option and re-compiled, it ran without issue.

Related

C++ Builder 10.3 Linker issues with std library

Using C++ Builder 10.3 Update 2
I'm upgrading some existing software from classic Borland compiler to Clang 64.
The entire project consists of a number of static libraries, and some applications.
When building the final applications, I'm running into linker issues that look like this:
[ilink64 Error] Error: Unresolved external 'std::_Facet_base::_Facet_base()' referenced from XXX.A|xxx.o
[ilink64 Error] Error: Unresolved external 'vtable for std::locale::facet' referenced from XXX.A|xxx.o
[ilink64 Error] Error: Unresolved external 'vtable for std::ctype_base' referenced from XXX|xxx.o
The libraries are using std::stringstream, and std::readline, along with some other std library functions.
The general pattern that is causing the error is:
// mystaticlib.h
void foo();
// mystaticlib.cpp
#include <sstream>
void foo() {
stringstream ss;
// do some more stuff
}
// myapp.cpp
#include "mystaticlib.h"
void bar()
{
foo();
}
Is this a bug with the compiler/linker?
I've found these related questions (and more):
Undefined reference to vtable
Linking error: undefined reference to `vtable for XXX`
Linker error: undefined reference to vtable
But the answers generally boil down to "implement the missing functions".
Since this is the std library delivered with the product, I'm hesitant to start changing it.
I'm fairly familiar with C++ Builder, and C++ and I've tried investigating all the basic stuff.
This code did compile, link and run using C++ Builder 10.3 with the classic 32 bit compiler.
This is so low level that I'm having a hard time figuring out what is wrong.
Because of reasons, I would prefer not to update to 10.4 at this time.
I also saw that there is a 10.3.3 release, but I was hoping not to upgrade unless I specifically had to to fix this problem.

Undefined symbol _UnitySendMessage

Define a method in the .mm file
#if defined(__cplusplus)
extern "C"{
#endif
extern void UnitySendMessage(const char* obj, const char* method, const char* msg) __attribute__ ((weak));;
extern NSString* _CreateNSString (const char* string);
#if defined(__cplusplus)
}
#endif
#interface UnityAdapter ()
...
Called in #implementation UnityAdapter()
UnitySendMessage("PottingMobile", "bannerDidLoadAd", "");
I need help solving the following error:
ld: warning: Could not find auto-linked framework 'FBSDKCoreKit'
Undefined symbols for architecture armv7:
"_UnitySendMessage", referenced from:
-[UnityAdapter bannerDidLoadAd] in UnityAdapter.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
when i don't use UnitySendMessage method, everthing is ok.
I want to write a framework for bridging unit and iOS projects. When I use it in a unit packaged project, no problem. When I put the bridging file into my own framework, I will report an error. There is nothing in the framework project. Do I need to integrate unit's lib? If so, how to integrate? Can you give me a website? Thank you.
Unity is currently doing this with their library feature.
You can look at their solution.
If you need a solution now: Have a look at https://github.com/jiulongw/swift-unity. It's all automated and a good starting point, but missing the library feature.
This project shows how to make an actual library: https://github.com/forestlin1212/unity-ios-framework (But for an older Unity version and not automated)

Reading .dcm files itk

I am using itk library for reading my .dcm files using its example in: https://itk.org/Doxygen46/html/IO_2DicomImageReadWrite_8cxx-example.html.
When I use CMake to build this example its appear that everything is OK and I can for example write my .dcm in .png format. But when I use Visual Studio (2015-2013-2010) I face with these errors:
LNK1120 4 unresolved externals
LNK2019 unresolved external symbol gethostname referenced in function "public: static bool __cdecl gdcm::System::GetHostName(char * const)" (?GetHostName#System#gdcm##SA_NQEAD#Z)
LNK2019 unresolved external symbol WSACleanup referenced in function "public: static bool __cdecl gdcm::System::GetHostName(char * const)" (?GetHostName#System#gdcm##SA_NQEAD#Z)
LNK2019 unresolved external symbol WSAStartup referenced in function "public: static bool __cdecl gdcm::System::GetHostName(char * const)" (?GetHostName#System#gdcm##SA_NQEAD#Z) Read_Write
LNK2019 unresolved external symbol __imp_UuidCreate referenced in function "protected: static bool __cdecl gdcm::UIDGenerator::GenerateUUID(unsigned char *)" (?GenerateUUID#UIDGenerator#gdcm##KA_NPEAE#Z)
It seems that there is something wrong with gdcm.
About the socket functions: seems you should link your project to WS2_32.lib
About the __imp_UuidCreate: seems to be a known issue.

Linker Command Failed with exit code 1 (Use -v to see invocation) iOS Error

In my application I'm using a static library named ABC.a in that library in a c file named Layout.c there is a function called init(). And I linked the library to the projects and added the .h file. The program is compiled without error but while linking the function its throwing the error. Why?
Info: I've added that static library in build phases also.
And the library is built for armv7, armv7s and arm64. bitcode enabled: No and Build active architectures : NO
Example error:
Undefined symbols for architecture arm64:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
"amid_Val(float const*, int, int*, int, unsigned int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
Please help two days gone for this.
This is based on the fact that you mention that the .a file is generated from a c file. The linker error:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
indicates that the AMID_INIT definition came from a C++/Objective-C++ file - this is because C files would not have information about the parameters of the routine.
From this I was able to surmise that the library header file did not have c++ guards.
Three approaches in this case - wrap all imports of the library header file in the C++ code with something like:
extern "C" {
#import "lib.h"
}
or create a lib.hpp file, containing:
#pragma once
extern "C" {
#import "lib.h"
}
and #import 'lib.hpp' instead, or fix the lib.h file by adding the standard name mangling preventative:
… near start of lib.h:
#ifdef __cplusplus
extern "C" {
#endif
… near end of lib.h:
#ifdef __cplusplus
}
#endif
This allows you to keep using the lib.h with both C and C++ compilers by declaring that all the routines offered by lib.h are exposed using C linkage, rather than C++ linkage.

iOS-QR-Code-Generator linking issue

Need to generate QR code from iOS for different strings. Tried out the following library:
**jverkoey-ObjQREncoder-e1841fe**
being able to generate QR Code .. but this code cannot be read by any readers.
**iOS-QR-Code-Generator**
Following the documentation provided But facing linking problem when i am trying to add the 'kuapay-iOS-QR-Code-Generator' to generate QRCode. I followed the way that is written in the github project
"To build your own project from this template you must attace the libz.dylib library to your target in Xcode. You must also drag the QRDraw and libpng folder files into your project. Update the Header Search path to look in the libpng folder in your target build settings menu."
But it give me 6 error message. These are -
Undefined symbols for architecture i386:
"CQR_Encode::EncodeData(int, int, bool, int, char*, int)", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"CQR_Encode::~CQR_Encode()", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"_OBJC_CLASS_$_FileManager", referenced from:
objc-class-ref in RootViewController.o
"QRDrawPNG::draw(char*, int, int, unsigned char (*) [177], void*)", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"CQR_Encode::CQR_Encode()", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"vtable for QRDrawPNG", referenced from:
QRDrawPNG::QRDrawPNG() in RootViewController.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyone help me with this? OR suggest a better QRcode generator for iOS device?
Thanks a lot!
This issue is caused because you are using c++ code silently in your app , use .mm instead of .m in your RootViewController .
Check you have the file Barcode.mm, qr_draw_png.mm, QR_Encode.mm linked to your project target. Also you may be add "-fno-objc-arc" flag.

Resources