Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add msvc support and other bugs #38

Open
Dath-Ohne-R opened this issue Nov 13, 2024 · 5 comments
Open

add msvc support and other bugs #38

Dath-Ohne-R opened this issue Nov 13, 2024 · 5 comments

Comments

@Dath-Ohne-R
Copy link

This project is most useful, but lacks generality. It seems its optimized for g++ only. I would like to have microsoft visual studio c++ compiler (msvc) support for it as well. Furthermore, I found some different things that might be a bug.
My build-system: CMake 3.31.0, c++ 20, MSVC 19.41.34123.0.
All references are from commit 4d025b5 of master.

MSVC-Support:
I recommend to change common.h line 9 as follows, as visibility is not supported by msvc
#ifdef _MSC_VER
#define DECL_STRUCT_ATTR
#else
#define DECL_STRUCT_ATTR attribute((visibility("hidden")))
#endif

CMakeLists.txt line 44 gave an error as it said that the word "optimized" is used - seems to be in ${Python3_LIBRARIES}. I tried to exchanged it with this:
target_link_libraries(matplotlibcpp17::matplotlibcpp17 INTERFACE ${Python3_LIBRARIES} pybind11::embed)
But then python3XX.lib is not found during linking. I could not find a solution.

Snippet of my CMakeLists.txt for comparison:
set(pybind11_DIR "path/to/pybind11")
add_subdirectory(ExtLibs/matplotlibcpp17)
target_link_libraries(projectname PRIVATE matplotlibcpp17::matplotlibcpp17)

I would highly appreciate if the author(s) of this repo would check their code for compatibility with msvc and check the issues I had.

@Dath-Ohne-R
Copy link
Author

I printed the variable: message("Python_LIBRARIES:${Python_LIBRARIES}")
here is the output
Python_LIBRARIES:optimized;C:/Users/[username]/AppData/Local/Programs/Python/Python311/libs/python311.lib;debug;C:/Users/[username]AppData/Local/Programs/Python/Python311/libs/python311_d.lib

so this is where the "optimized"comes from. I guess it should be "release" instead?

@Dath-Ohne-R
Copy link
Author

If I directly link my project to python3XX.lib, it works:
target_link_libraries(projectname PRIVATE "C:/Users/[username]/AppData/Local/Programs/Python/Python311/libs/python311.lib")

but now I have to specify the specific path - not an option when collaborating with others.

@soblin
Copy link
Owner

soblin commented Nov 18, 2024

Thank you, I will try adding a CI for MSVC so I can check compatibility.

@Dath-Ohne-R
Copy link
Author

Thank you a lot!

@Dath-Ohne-R
Copy link
Author

Dath-Ohne-R commented Dec 2, 2024

I printed the variable: message("Python_LIBRARIES:${Python_LIBRARIES}") here is the output Python_LIBRARIES:optimized;C:/Users/[username]/AppData/Local/Programs/Python/Python311/libs/python311.lib;debug;C:/Users/[username]AppData/Local/Programs/Python/Python311/libs/python311_d.lib

so this is where the "optimized"comes from. I guess it should be "release" instead?

According to my research, I need the following change to get it to build with cmake on windows, python 3.13 and MSVC:
CMakeLists.txt line 49,50,51:
Delete this:
set_property(
TARGET matplotlibcpp17::matplotlibcpp17
PROPERTY INTERFACE_LINK_LIBRARIES ${Python3_LIBRARIES} pybind11::embed)
Add this instead:
target_link_libraries(matplotlibcpp17::matplotlibcpp17 INTERFACE ${Python3_LIBRARIES} pybind11::embed)

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

No branches or pull requests

2 participants