Skip to content

Conversation

@dgovil
Copy link
Collaborator

@dgovil dgovil commented Jun 14, 2025

Description of Change(s)

This PR moves the HgiShaderProgramDesc's operator== to the header, since its marked inline, but is only defined in the cpp file, therefore cannot actually be inlined.

(Thanks to Maddy Adams)

pxr/imaging/hgi/shaderProgram.h contains:

HGI_API
inline bool operator==(
    const HgiShaderProgramDesc& lhs,
    const HgiShaderProgramDesc& rhs);

But, the definition is only in the .cpp file, so calling it results in a linker error:

Undefined symbols for architecture arm64:
  "pxrInternal_v0_25_5__pxrReserved__::operator==(pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&, pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&)", referenced from:
      reproducer(pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&, pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&) in main-d9ce5a.o
ld: symbol(s) not found for architecture arm64

Clang also emits this warning:

/opt/local/OpenUSD_no-python/include/pxr/imaging/hgi/shaderProgram.h:44:13: warning: inline function 'pxrInternal_v0_25_5__pxrReserved__::operator==' is not defined [-Wundefined-inline]
   44 | inline bool operator==(
      |             ^
main.cpp:44:16: note: used here
   44 |     bool x = l == r;
      |                ^

I think the inline keyword should be removed from the function declaration, or the function definition should be moved into the header file. (Note that the fix should also be applied to operator!=.)

Reproduction

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-W#pragma-messages" // Silence TBB deprecation warning from pxr/base/work/dispatcher.h

#include <iostream>
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/sdf/layer.h"
#include "pxr/base/tf/token.h"
#include "pxr/usd/usdGeom/tokens.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usdPhysics/tokens.h"
#include "pxr/usd/usdPhysics/rigidBodyAPI.h"
#include "pxr/imaging/hgi/shaderProgram.h"

#pragma clang diagnostic pop


/// Basic smoke test that the OpenUSD install is usable
void smokeTest() {
    pxr::UsdStageRefPtr mainStage = pxr::UsdStage::CreateNew("main.usda");
    mainStage->DefinePrim(pxr::SdfPath("/hello"), pxr::UsdGeomTokens->Cube);
    mainStage->DefinePrim(pxr::SdfPath("/hello/world"), pxr::UsdGeomTokens->Sphere);
    std::string s;
    mainStage->ExportToString(&s);
    std::cout << s << std::endl;
}

/*
PXR_NAMESPACE_OPEN_SCOPE

bool operator==(
                const HgiShaderProgramDesc& lhs,
                const HgiShaderProgramDesc& rhs)
{
    return lhs.debugName == rhs.debugName &&
           lhs.shaderFunctions == rhs.shaderFunctions;
}

PXR_NAMESPACE_CLOSE_SCOPE
*/

void reproducer(const pxr::HgiShaderProgramDesc& l,
                const pxr::HgiShaderProgramDesc& r) {
    bool x = l == r;
}




int main() {
    smokeTest();
    return 0;
}

and compiled with

set -e

# Vanilla v25.05.01 with --no-python
OPENUSD_INSTALL=/opt/local/OpenUSD_no-python


# Remove stale files
rm -f ./a.out

# Compile
clang++ main.cpp -std=c++17 \
        -I $OPENUSD_INSTALL/include \
        -L $OPENUSD_INSTALL/lib \
        -Xlinker -rpath -Xlinker $OPENUSD_INSTALL/lib \
        -lusd_usd -lusd_sdf -lusd_tf -lusd_usdGeom -lusd_hgi

./a.out

Checklist

pxr/imaging/hgi/shaderProgram.h contains:
```
HGI_API
inline bool operator==(
    const HgiShaderProgramDesc& lhs,
    const HgiShaderProgramDesc& rhs);
```

But, the definition is only in the .cpp file, so calling it results in a linker error:
```
Undefined symbols for architecture arm64:
  "pxrInternal_v0_25_5__pxrReserved__::operator==(pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&, pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&)", referenced from:
      reproducer(pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&, pxrInternal_v0_25_5__pxrReserved__::HgiShaderProgramDesc const&) in main-d9ce5a.o
ld: symbol(s) not found for architecture arm64
```

Clang also emits this warning:
```
/opt/local/OpenUSD_no-python/include/pxr/imaging/hgi/shaderProgram.h:44:13: warning: inline function 'pxrInternal_v0_25_5__pxrReserved__::operator==' is not defined [-Wundefined-inline]
   44 | inline bool operator==(
      |             ^
main.cpp:44:16: note: used here
   44 |     bool x = l == r;
      |                ^
```

I think the `inline` keyword should be removed from the function declaration, or the function definition should be moved into the header file. (Note that the fix should also be applied to `operator!=`.)
@dgovil dgovil added the build Build-related issue/PR label Jun 14, 2025
@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-11120

(This is an automated message. See here for more information.)

@pixar-oss pixar-oss closed this in 7a5d313 Jun 26, 2025
meshula pushed a commit to meshula/USD that referenced this pull request Sep 11, 2025
Removed the 'inline' specifier from several operator==()
and operator!=() functions that are defined only in the
corresponding cpp files and can't be instantiated inline.

This is modified from the original PR which addressed only
hgi/shaderProgram.h

(Thanks to Maddy Adams)

Closes PixarAnimationStudios#3682

(Internal change: 2370680)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Build-related issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants