I'm trying to load a module library via dl in such way, that the module can access globals from the main application. How is that possible to do?
I get an error message from dlopen saying library/name.so: undefined symbol: .... The only flag used is: RTLD_NOW.
The module itself is build with libtool with -module -avoid-version.
The answer is: use -Wl,--export-dynamic when linking the main binary, so all symbols are automatically exported to the loaded libraries.
Same question, just asked differently: Receive "undefined symbol" error when loading library with dlopen
Related
I have been trying to integrate my Unity game with the iOS static library that I found on Github. The library is in Swift, however, I forked the library and I provided objective-c bindings necessary to make a call from C# code.
My static library is available in my xCode project under the products tab. To use it in Unity I copy-pasted generated library from the directory available under "Reveal in file explorer" to Unity. I put my library in the Plugin directories.
When I run my game on iOS simulator via generated by Unity solution I'm getting an error:
2020-11-02 13:56:43.450062+0100 NewUnityProject[4357:59213] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$s10Foundation3URLVMn
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
2020-11-02 13:56:43.473282+0100 NewUnityProject[4357:59213] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/1C4440FF-C7C6-486B-ADC8-F8A794A83CD9/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$s10Foundation3URLVMn
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
To validate Unity support step by step I've created an objective-c static library - Untiy was able to make a call to library and I didn't get an error. After that I added swift support to my objective-c library and then I got once again a problem with flat namespace:
2020-11-02 13:37:12.848568+0100 NewUnityProject[3034:44789] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$sBOWV
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
2020-11-02 13:37:12.874398+0100 NewUnityProject[3034:44789] Error loading /Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/Users/user/Library/Developer/CoreSimulator/Devices/4D7307D5-D320-4AEB-A0DE-581C61CB3E14/data/Containers/Bundle/Application/4E2199BA-7743-484E-AD01-636C4296BE85/NewUnityProject.app/Frameworks/UnityFramework.framework/UnityFramework, 265): Symbol not found: _$sBOWV
Referenced from: /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
Expected in: flat namespace
in /Users/use/Library/Developer/Xcode/DerivedData/Unity-iPhone-cwkdvrbwlxwbfzbpzacumxcttcmy/Build/Products/ReleaseForRunning-iphonesimulator/UnityFramework.framework/UnityFramework
I have been trying to set different xCode flags like "Always Embed Swift Standard Libraries" or "Enable Modules" but still no luck to run my game on iOS simulator.
Any hints are very appreciated.
I am trying to generate a shared native library using cmake. the contents of this library are nothing more than native functions that will later be used in Unity. that is why the functions have the extension __declspec (dllexport) so that in the Unity section they can be called with dllImport.
My problem comes when I try to compile that library in cmake. I am using Ninja as compiled and cross-compiled with Android toolchain. The problem is that it tells me:
../InnovaeInterface/include/Camara.h:7:2: error: unknown type name '_declspec'
_declspec(dllexport) CameraUtils::Calibration* createCamara(void);
^
../InnovaeInterface/include/Camara.h:7:22: error: expected ';' after top level declarator
_declspec(dllexport) CameraUtils::Calibration* createCamara(void);
^
The truth is that I have no idea where to throw. I hope you help me.
What does it mean to have undefined symbols?
There are no errors in the code files themselves and I am NOT using any external libraries.
I DID add a typedef NS_ENUM prior to this linker error occurring.
Where do I add this -v to see invocation?
Here is the error message:
Undefined symbols for architecture x86_64:
"_OBJC_IVAR_$_UIViewController._parentViewController", referenced from:
-[PEPI_LessonController setParentViewController:] in PEPI_LessonController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
"Undefined Symbols"
Building source code files to an executable file consist of at least two steps:
Compile the source code files to intermediate binary files (often called xyz.o).
Link the intermediate binary files to the final executable file.
The error message "undefined symbols" is a linker message. It may appear even though the compilation process was successful without notice. The linker organizes final memory address relations and it replaces symbols that the compiler had to assume they would be valid later, if all parts of the code would be available. Without this, no modularization would be possible at all.
-v to see invocation
If you build your application in Xcode, then Xcode calls all the compile and link commands for you (CompileC, Ln, Clang ...). But remember that a typical IDE runs only the commands you could run by yourself in the shell. Theoretically, you could develop big applications only in a text editor and a shell. So I suggest take some time and try to copy paste some commands listed in the Xcode build report to a shell :-) You'll learn a lot about the backgrounds. Therefore, in my opinion, -v to see invocation is used while invoking the command in the shell - or in the build settings, if you wish permanently more information.
"External libraries"
Finally, try to clarify "external libraries". To look at the most simple example: even if you write a simple C program and you want to know something trivial like the length of a string, you'll include <glibc.h>. Now this is an external library. It's external to your program code. Are you sure you haven't included external libraries?
Solving linker problems
Linker errors are often confusing and somehow difficult, because details of the linked modules tend to be out of sight. You may find many hints if you enter the error message in a search engine. For example, have a look at here:
Undefined symbols for architecture armv7: "_SCNetworkReachabilityCreateWithAddress"
Even if all components are found for linking, all paths are known etc, they may have the wrong version or else.
It means it can't find the property parentViewController and method setParentViewController when linking your object files files. The most common cause for these types of errors is not linking a library or framework in your projects target. UIViewController is part of UIKit so I'd be surprised if it's not already linked. Is this an OSX project and your trying to use UIViewcontroller instead of NSViewController?
In my case I had forgotten to add the .m file to all the same targets as the .h and that's what caused this issue. In case it helps anyone thought I'd mention here... double check your target memberships!
During building a c++ source code (configured with cmake gui) with mingw under MSYS gives following error while trying to "Linking C shared library":
Unrecognized option "--enable-new-dtags"
How can i solve this issue?
Likely --enable-new-dtags is supported only on ELF targets. For example there's a patch for Python3 distutils which sets this flag conditionally on the target platform: https://github.com/Alexpux/MINGW-packages/blob/master/mingw-w64-python3/0260-MINGW-compiler-enable-new-dtags.patch . You should make sure that this flag isn't specified explicitly somewhere in your project.
I'm getting this error
Undefined symbols:
".objc_class_name_MyClass", referenced from:
literal-pointer#__OBJC#__cls_refs#MyClass in infoViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
When referencing the static method below:
[MyClass ClickComment:self.navigationController];
MyClass is defined in a static library that I'm referencing in my app project. When I start typing "[MyClass "..., I get message hints. The app project knows MyClass exist and which methods are defined on it. Yet, I get the above error. Commenting out this call allows the project to build without error.
In the static library, I have a .h file that references all of the library's .h files. This way, the app project needs to reference only one .h file from the static library. The static library project also has an app. I use it to test the static library. I can do the above call fine. I usually see these types of errors when the static library has build a device/debug version and the app project has build simulator/debug. However, both builds are in sync.
I know there is a reference issue but I'm unsure how to resolve it. Any suggestions?
That means that the header files are found during compilation, but the linker is not aware of the static library. Make sure your static library is listed under "Targets -> YourMainTarget > Link Binary with Libraries" in the project view.
See http://developer.apple.com/tools/XCode/XCodeprojects.html