0

How I can make friends pybind11 with another libs? I using CMake and MinGW

cmake_minimum_required(VERSION 3.24)
project(cmake_example)

add_subdirectory(pybind11)

pybind11_add_module(cmake_example src/main.cpp)

target_compile_definitions(cmake_example PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})

This is default settings for getting start. I have another lib, which I build before. My attempt looks like this:

cmake_minimum_required(VERSION 3.24)
project(cmake_example)

add_subdirectory(pybind11)
add_subdirectory(anotherlib_dir)

pybind11_add_module(cmake_example src/main.cpp)

target_link_libraries(anotherlib)

target_compile_definitions(cmake_example PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})

Where anotherlib_dir looks like this:

- lib
- src
- CMakeLists.txt

This lib works correctly (I tested it in clear project)

But this solution do not working. On building I have problems with undefined reference

Someone tried to make friends libraries? I don't know what else to try I am sure that there are no problems with my library, since CMake defines it: The existing target is a static library created [cmake] in source directory ".../cmake_example".

In clear project I link libs look like

add_subdirectory(anotherlib_dir)
target_link_libraries(ProjectName anotherlib)

In pybind11 ProjectName not specified. As I understand, pybind11 has custom superctructure, which can define project.

onyx1a
  • 1
  • 1
  • Neither of your cmake lists define targets. Can't imagine they pass cmake configure steps successfully. `target_link_libraries(anotherlib)` also should raise an error. – 273K Feb 04 '23 at 15:54
  • Yes, it should. But on the contrary, it gives an [error](https://imgur.com/a/GzBW4Mz) if I specify a target. – onyx1a Feb 04 '23 at 16:01
  • @273K: "Neither of your cmake lists define targets." - Actually, function `pybind11_add_module` creates a target. – Tsyvarev Feb 04 '23 at 16:21
  • @onyx1a: Concerning the error message on the screenshot which you posted as a comment, see [that question](https://stackoverflow.com/questions/47737558/uses-of-target-link-libraries-must-be-either-all-keyword-or-all-plain). Next time describe your attempts in the question post itself, and provide **textual** representation of the error: https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors – Tsyvarev Feb 04 '23 at 16:24

0 Answers0