Skip to content

Conversation

@hellokenlee
Copy link

The following c++20 code would not link when using /GL in MSVC:

class __declspec(dllexport) Animal {
public:
	virtual ~Animal() = default;
	virtual void go(int n_times) {}
};

class __declspec(dllexport) PyAnimal : public Animal, public pybind11::trampoline_self_life_support {
public:
	void go(int n_times) override {
		PYBIND11_OVERRIDE_PURE(
			void,
			Animal,
			go,
			n_times
		);
	}
};

PYBIND11_MODULE(example, m, pybind11::mod_gil_not_used()) {
	pybind11::class_<Animal, PyAnimal, pybind11::smart_holder>(m, "Animal")
		.def(pybind11::init<>())
		.def("go", &Animal::go)
	;
}

The error is:

Error LNK2001 : unresolved external symbol "struct pybind11::detail::override_unused `public: virtual void __cdecl PyAnimal::go(int)'::`12'::caster" (?caster@?M@??go@PyAnimal@@UEAAXH@Z@4Uoverride_unused@detail@pybind11@@A)

We can use constexpr if to avoid this link error.

@hellokenlee hellokenlee force-pushed the master branch 2 times, most recently from 99ed4d1 to 74922f2 Compare December 17, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant