Archicad C++ API
About Archicad add-on development using the C++ API.

Compile error on Mac

dushyant
Enthusiast

Hi, 

I'm getting a compile error on Mac:

 

 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/locale:2827:22: no member named 'GS_realloc' in namespace 'std'; did you mean simply 'GS_realloc'?

    _Tp* __t = (_Tp*)std::realloc(__owns ? __b.get() : 0, __new_cap);

 

The same code compiles fine with MSVC on windows.

Anyone faced this error?

 

Thanks.

21 REPLIES 21

Hi,

 

#define std::realloc(p, s) GS_realloc(p, s)​ <--- is not defining a valid macro name, because of the '::'. 

 

 

Sorry, missed out the notes on the github repo page.

Thanks again for the suggestions and help!

 

 

Ah yeah, you're right, that won't work then.

I just thought maybe also the include order might make a difference.

So maybe including iostream before any Archicad API include could work (also make sure it's before the includes you have in associated header files of .cpp files).
But I'm not sure if there would be an effect if parts of the code use different memory allocators then.

Maybe including iostream before AC headers could have a different behaviour.

 

Anyway, I don't really need iostream here. So it's no problem for now 🙂

Victor Baboi
Booster

Hi,

 

I may have found a workaround for the issue. I am new to Macs and a beginner at C++ so take it with a grain of salt.

 

As usual, all works fine on Windows.

 

What I did was #undefine the malloc functions right before #include-ing an std libraries. This seems to solve the issue of duplicated / overwritten defines, like in the example bellow:

 

// Archicad 27 API Includes
#include "ACAPinc.h"
#include "APICommon.hpp"
#include "APIEnvir.h"
#include "DGModule.hpp"
#include "DGBrowser.hpp"
// these define the GS_realloc and so on

// Undefine macros that cause issues (potential fix)
#undef calloc
#undef malloc
#undef free
#undef realloc

// Include standard or third-party headers that need the original memory functions
#include <string>
#include <cstring>
#include <vector>
#include <ctime>
#include <unordered_map>

 

I don't know if it's correct, but at least it compiled with no error.

For now I'm using the 14.2 sdk, that comes with Xcode.

 

Regarding the minimum 10.15 version, I managed to set it up via CMake, using the base template from GitHub, but I don't think it had any effect on the issue above.

In BuilAddOn.py:

 

def GetProjectGenerationParams (workspaceRootFolder, buildPath, addOnName, platformName, devKitFolder, version, languageCode, additionalParams):
    ...
    if platformName == 'WIN':
        ...
    elif platformName == 'MAC':
        projGenParams.extend (['-G', 'Xcode'])
        # Ensure the deployment target is macOS 10.15
        projGenParams.append('-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15')

 

If you find an actual fix, please let me know!

Thanks!

Victor Baboi
TESSERACT ARCHITECTURE
AC 16-27 | WIN 11
Viktor Kovacs
Graphisoft
Graphisoft

This issue occurs because there was a change in the latest Xcode SDK that is not compatible with the Development Kit. Although earlier it was possible to always use the latest Xcode, unfortunately it's not the case anymore.

 

Hopefully there will be a solution for this in the future, but in the meantime please make sure that you are using  Xcode 14.2 for compilation. The tricky part here is that it's not very straightforward to install an earlier version of Xcode, but it's possible by following the steps below.

 

  • Go to https://developer.apple.com/download/all/?q=xcode.
  • Download and install these two packages:
    • Command Line Tools for Xcode 14.2,
    • Xcode 14.2.
  • Make sure that the system uses this newly downloaded Xcode by running the command below (replace the app location with your current installation location).
sudo xcode-select -s /Applications/Xcode_14.2.app

 After this change everything should compile without any issues.

vdentello
Advocate

 

I figured out a very dumb solution that worked for me.


I noticed that the MacOSX14.sdk is just a shortcut that points to MacOSX.sdk
I simply duplicated and renamed the shortcut to MacOSX14.0.sdk (with the explicit) .0 so the compiler sees the path and the build works.

vdentello_0-1712238440413.png

 

Archicad User Since 2013
GDL Developer
Experimenting with API
from Brazil

Hi Victor! Any news on an update? Xcode 14.2 is not compatible with macOS Sonoma thus this workaround won't work with new Macs.

Ralph Wessel
Mentor

There is a name clash between the STL and the Archicad SDK, but it can be avoided. The compiler is currently seeing the GS version first, which is shadowing std::realloc - hence the compiler suggestion that this is what you mean.

 

I recommend ordering your header file includes so all STL headers are read first, followed by any Archicad SDK header includes.

Ralph Wessel BArch
Software Engineer Speckle Systems

I had a new update on my (old) mac and reordering seems to have done the trick this time. If I find any more details I will let you know.

By the way, I have Xcode 15.2 on Ventura 13.6.7.

Victor Baboi
TESSERACT ARCHITECTURE
AC 16-27 | WIN 11
Emkave
Booster

I faced the same issue on MacOS (Intel chip) Ventura 13.5