Skip to main content
Ctrl+K
Carbonite SDK - Home

Carbonite SDK

  • gitlab
  • twitter
  • youtube
  • instagram
  • www
  • linkedin
  • twitch
Carbonite SDK - Home

Carbonite SDK

  • gitlab
  • twitter
  • youtube
  • instagram
  • www
  • linkedin
  • twitch

Table of Contents

  • Carbonite SDK API
  • ForceLink.h
  • ForceLink.h

ForceLink.h#

Fully qualified name: omni/extras/ForceLink.h

File members: omni/extras/ForceLink.h

// SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.
#pragma once

#include "../core/Platform.h"

#if OMNI_PLATFORM_WINDOWS
// see below for why we unfortunately either need this or to forward declare SetLastError()
// directly here instead of using something like strerror_s() on Windows.
#    include "../../carb/CarbWindows.h"
#endif

namespace omni
{
namespace extras
{

class ForceSymbolLink
{
public:
    ForceSymbolLink(void* ptr)
    {
#if OMNI_PLATFORM_WINDOWS
        // On Windows, we unfortunately can't call into something like strerror_s() to
        // accomplish this task because the CRT is statically linked to the module that
        // will be using this.  That would make the function we're passing the symbol
        // to local and therefore the symbol will still be discardable.  Instead, we'll
        // pass the address to SetLastError() which will always be available from 'kernel32'.
        SetLastError(static_cast<DWORD>(reinterpret_cast<uintptr_t>(ptr)));
#else
        char* str;
        CARB_UNUSED(str);
        str = strerror(static_cast<int>(reinterpret_cast<uintptr_t>(ptr)));
#endif
    }
};

} // namespace extras
} // namespace omni

#define OMNI_FORCE_SYMBOL_LINK(symbol_, tag_)                                                                          \
    static omni::extras::ForceSymbolLink CARB_JOIN(                                                                    \
        g_forceLink##tag_##_, CARB_JOIN(CARB_JOIN(__COUNTER__, _), __LINE__))(&(symbol_))

previous

ForceLink.h

next

OMNI_FORCE_SYMBOL_LINK

NVIDIA NVIDIA

Copyright © 2018-2025, NVIDIA Corporation.

Last updated on Apr 22, 2025.