Closed
Description
Dear all,
I've been running into strange inconsistencies where type information is not synchronized across shared library boundaries. This happens when using Clang & libc++ on Linux/x86_64 machines.
Before escalating to Clang/LLVM, I wanted to gauge if anyone here has previously run into this. To reproduce:
issue.py
import mod1, mod2
mod2.test(mod1.Test())
# Expected output
# ================
# $ python issue.py
# $
# Actual output:
# ================
# $ python issue.py
# Traceback (most recent call last):
# File "issue.py", line 3, in <module>
# mod2.test(mod1.Test())
# TypeError: test(): incompatible function arguments. The following argument types are supported:
# 1. (arg0: Test) -> None
#
# Invoked with: <mod1.Test object at 0x7f12861f5df8>
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.12)
project(example)
# Issue is triggered in a release build
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
# Issue is triggered when using libc++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
add_subdirectory(pybind11)
add_library(shared SHARED shared.cpp)
pybind11_add_module(mod1 mod1.cpp)
pybind11_add_module(mod2 mod2.cpp)
target_link_libraries(mod1 shared)
target_link_libraries(mod2 shared)
shared.h
#pragma once
#define EXPORT __attribute__ ((visibility("default")))
class EXPORT Test {
public:
Test();
};
shared.cpp
#include "shared.h"
Test::Test() { }
mod1.cpp
#include <pybind11/pybind11.h>
#include "shared.h"
namespace py = pybind11;
PYBIND11_MODULE(mod1, m) {
py::class_<Test>(m, "Test")
.def(py::init<>());
}
mod2.cpp
#include <pybind11/pybind11.h>
#include "shared.h"
namespace py = pybind11;
void test(Test b) { }
PYBIND11_MODULE(mod2, m) {
py::module::import("mod1");
m.def("test", &test);
}
Best,
Wenzel
Metadata
Metadata
Assignees
Labels
No labels