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.
Related
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.
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)
Under delphi tokyo, when I link a static libraries (*.a) inside an Ios project like this :
procedure StubProc1; cdecl; external 'FBSDKCoreKit.a' name 'OBJC_CLASS_$_FBSDKAccessToken';
I receive a lot of warnings like this one:
ld: warning: unknown dwarf DW_FORM_strp (offset=0xFFFF6E38) is too
big in
C:\Dev\lib\ios\facebook\FBSDKShareKit.framework\FBSDKShareKit.a(FBSDKAppInviteContent.o)
Any idea what goes wrong? What exactly does unknown dwarf DW_FORM_strp mean?
Reference code:
https://opensource.apple.com/source/cxxfilt/cxxfilt-9/cxxfilt/binutils/dwarf.c.auto.html
/* Process the contents of a .debug_info section. If do_loc is non-zero
then we are scanning for location lists and we do not want to display
anything to the user. */
static int
process_debug_info (struct dwarf_section *section, void *file,
int do_loc)
Then it calls read_and_display_attr -> read_and_display_attr_value -> fetch_indirect_string:
offset -= section->address;
if (offset > section->size)
{
warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
return _("<offset is too big>");
}
So, it seems that this warning is only for debug purpose only.
Maybe your third party library lacks debug info, or something incompatible for debug (remember, even if you are building for release, there can still be some debug info in your app).
As it is for debug only, once you have successfully compiled your project, this warning shouldn't matter.
I'm trying to use an iOS native framework inside Unity, but I don't know how.
Inside my C# script, I call a native function like this :
[DllImport ("__Internal")]
private static extern void writeHello();
void Start () {
writeHello();
}
I have drag the iOS framework inside my project like this :
Link to my image
But when I deploy my app on iPad, xCode showing this error :
Undefined symbols for architecture armv7: "_writeHello", referenced
from:
RegisterMonoModules() in RegisterMonoModules.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with
exit code 1 (use -v to see invocation)
I don't understand why, and I don't know if what I'm trying to do is possible.
Help! :)
Thanks,
Sennin
The iOS framework must be put in the xCode generated project, not in unity.
And the framework's functions must be wrapped in an extern "C" block (as shown here).
Then you will be able to use it in C# with dllimport.
The doc says that all files with extensions .a,.m,.mm,.c,.cpp located in the Assets/Plugins/iOS folder will be merged into the generated Xcode project automatically. The docs also says that subfolders are currently not supported, so, in your example, the "framework-helloUnity.framework" folder will be ignored.
It is important to note that .m files default to C-style bindings, while .mm files default to C++-style bindings. In other word, unless you use the extern "C" keyword, as Heilo suggested, your functions won't be found if you put them in .mm or .cpp files.
In other words, if you put the following:
void writeHello() {}
in a file named Assets/Plugins/iOS/myTestFile.m, your code should compile.
Found the solution thanks to this post : Calling Objective-C method from C++ method?
By doing like that :
void myWriteHello( void *test) {
[(id)test writeHello];
}
- (void) writeHello
{
NSLog(#"Hello World!");
}
and calling my C function from Unity
You have write the following function in your Xcode project any class
extern "C"
{
-(void) writeHello
{
}
}
I've compiled a static library and linked both SQLCipher and OpenSSL. The full project, makefile, and compiled library can be found here:
https://github.com/anujb/SQLCipherNet
When I link the resulting library in a normal Objective-C Xcode project, the call to sqlite3_key works fine.
I've linked the same library into a MonoTouch project using:
-gcc_flags "-L${ProjectDir} -lsqlciphernet -force_load ${ProjectDir}/libsqlciphernet.a"
Then I've modified SQLite-NET to call the the key function, after every SQLite3.Open(...) function:
[DllImport("__Internal", EntryPoint = "sqlite3_key")]
public static extern Result Key(IntPtr db, string key, int keyLength);
But I get a EntryPointNotFoundException when the Key method is called. Here's the stack trace:
System.EntryPointNotFoundException has been thrown at:
at (wrapper managed-to-native) SQLite.SQLite3:Decrypt (intptr,string,int)
at SQLite.SQLiteConnection..ctor (System.String databasePath) [0x00031] in
../SQLite.cs:108
Obviously the stacktrace isn't particularly helpful, but I'm at a loss as to where to begin to debug this issue. Halp?
I get the same error when building your solution for "Debug|iPhoneSimulator". However your project options, for this configuration, do not include the gcc_flags you mentioned - so the exception is totally normal.
Trying to build the "Debug|iPhone" configuration (where the options are specified) fails because of path issues... but I'm pretty sure it would work if I fixed them ;-)
UPDATE
Moving the library to it's right location gives me:
Undefined symbols for architecture armv6: "___udivmodsi4",
referenced from:
_sqlite3BitvecSet in libsqlciphernet.a(sqlite3.o)
_sqlite3BitvecClear in libsqlciphernet.a(sqlite3.o)
_sqlite3BitvecTest in libsqlciphernet.a(sqlite3.o) ld: symbol(s) not found for architecture armv6
I believe it's missing because of libopenssl ?