environment: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
I am trying to override c++ symbols at linking time for the purpose of inserting measurement code into an existing library.
Perhaps typical linkers would search for symbols in specifing order of library and adopt the first hit.
Xcode's ld apparently does this in units of a object file.
If you create one object file to override one function and link it first, but call another function in the same object file contained in the original library, that one will be adopted. As a result, you cannot override function.
To override a function, the function to be overridden must be moved to a new cpp file and separated from the object file.
Here is a sample program to test this.
https://onedrive.live.com/redir?resid=DD46698E2D493F32!395&authkey=!AJqfiva7CXIDI_Y&e=OaFlSr
As you can see in main.cpp, func() and bar() are called from main().
func() and bar() are implemented in func.cpp and bar.cpp, respectively.
They are linked to libTest.lib.
To override func(), link libTest2.lib implementing func2() in func2.cpp, before libTest.lib.
If you run make and look at the code with objdump -d a.out, you can see the override.
Because the content of func2() is return i+1, __Z4funci contains leal 1(%rdi), %eax.
Then, build with make clean and make CONCAT=1, func() and bar() are concatenated into one cpp file and compiled.
The generated a.out is checked in the same way, you will see movl %edi, %eax at same position which means return i; which is the content of func().
This sample is small in scale, but in a larger project, it can be quite a hassle to isolate the functions you want to override.
Is there any easier way to override the function?
Since the original function name cannot be changed, it is our policy not to use -alias symbol_name alternate_symbol_name.
Thanks.
metal-cpp
RSS for tagC++ games and apps can tap into the power of Metal by bridging with metal-cpp.
Posts under metal-cpp tag
24 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Is there any way to use metal-cpp in a Swift project? I have a platform layer I've written in Swift that handles Window/View creation, as well as event handling, etc. I've been trying to bridge this layer with my C++ layer as you normally would using a pure C interface, but using Metal instances that cross this boundary just doesn't seem to work.
e.g. Currently I initialize a CAMetalLayer for my NSView, setting that as the layer for the view. I've tried passing this Metal layer into my C++ code via a void* pointer through a C interface, and then casting it to a CA::MetalView to be used. When this didn't work, I tried creating the CA::MetalLayer in C++ and passing that back to the Swift layer as a void* pointer, then binding it to a CAMetalLayer type. And of course, this didn't work either.
So are the options for metal-cpp to use either Objective-C or just pure C++ (using AppKit.hpp)? Or am I missing something for how to integrate with Swift?
Hi, I trying to use Metal cpp, but I have compile error:
ISO C++ requires the name after '::' to be found in the same scope as the name before '::'
metal-cpp/Foundation/NSSharedPtr.hpp(162):
template <class _Class>
_NS_INLINE NS::SharedPtr<_Class>::~SharedPtr()
{
if (m_pObject)
{
m_pObject->release();
}
}
Use of old-style cast
metal-cpp/Foundation/NSObject.hpp(149):
template <class _Dst>
_NS_INLINE _Dst NS::Object::bridgingCast(const void* pObj)
{
#ifdef __OBJC__
return (__bridge _Dst)pObj;
#else
return (_Dst)pObj;
#endif // __OBJC__
}
XCode Project was generated using CMake:
target_compile_features(${MODULE_NAME} PRIVATE cxx_std_20)
target_compile_options(${MODULE_NAME}
PRIVATE
"-Wgnu-anonymous-struct"
"-Wold-style-cast"
"-Wdtor-name"
"-Wpedantic"
"-Wno-gnu"
)
May be need to set some CMake flags for C++ compiler ?
Now the examples of metal-cpp are target on desktop and using AppKit which is not supported on iOS. Is there any tips for developing with metal-cpp on mobile device?