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

pybind11_add_module unexpected error after PR #2368 #2373

Closed
MonkeyBreaker opened this issue Aug 8, 2020 · 6 comments · Fixed by #2374 or #2370
Closed

pybind11_add_module unexpected error after PR #2368 #2373

MonkeyBreaker opened this issue Aug 8, 2020 · 6 comments · Fixed by #2374 or #2370
Assignees

Comments

@MonkeyBreaker
Copy link

MonkeyBreaker commented Aug 8, 2020

Issue description

After integrating latest PR #2368 on our library, building started producing errors:

 You have called ADD_LIBRARY for library '' without any source files. ...

After looking into the documentation, I could not find the issue, but looking into the PR, I saw that when using pybind11_add_module, it explicitly uses the keyword MODULE, and from what I understood in the documentation

MODULE or SHARED may be given to specify the type of library. If no type is given, MODULE is used by default which ensures the creation of a Python-exclusive module.

I don't know if it isn't any more the case. and now the MODULE keyword must be used?

Because when I use the keyword MODULE everything compiles just fine.

I tested pybind11 before the last merge of #2368 and without using the keyword MODULE it compiles just fine.

Reproducible example code

Maybe I'm crazy but the simple example from the documentation does not work on my machine:

cmake_minimum_required(VERSION 3.7)
project(example)

add_subdirectory(pybind11)
pybind11_add_module(example my_file.cpp)

Thank you for the great library,
Julián

@YannickJadoul
Copy link
Collaborator

Thanks for reporting, @MonkeyBreaker! I can confirm and reproduce. It it could be related to this change?
But I'm going to forward this to @henryiii, who's much better at CMake than I am ;-) (Sorry but thanks, Henry!)

@YannickJadoul
Copy link
Collaborator

Reproduced with CMake 3.16.3 on master, btw:

yannick@Athenai:~/tmp/sandbox/build$ cat ../CMakeLists.txt 
cmake_minimum_required(VERSION 3.8)
project(example)

add_subdirectory(pybind11)
pybind11_add_module(example example.cpp)
yannick@Athenai:~/tmp/sandbox/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- pybind11 v2.6.0 dev
-- Found PythonInterp: /usr/bin/python3.8 (found version "3.8") 
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so
-- Configuring done
CMake Error at pybind11/tools/pybind11Tools.cmake:151 (add_library):
  No SOURCES given to target: example
Call Stack (most recent call first):
  CMakeLists.txt:5 (pybind11_add_module)


CMake Generate step failed.  Build files cannot be regenerated correctly.

@JarvanI
Copy link

JarvanI commented Aug 8, 2020

I got same problem too . I tried to used cmake to build example code with latest version of pybind11 under win10 and failed.
Here is the report.

CMake Error at pybind11/tools/pybind11Tools.cmake:151 (add_library):
No SOURCES given to target: example
Call Stack (most recent call first):
CMakeLists.txt:5 (pybind11_add_module)
And I downloaded v2.4.3 and used the same way built again, it passed.

@henryiii
Copy link
Collaborator

henryiii commented Aug 8, 2020

Sorry! I had a typo, and I thought I fixed it before merging, but apparently not. I'm surprised no test caught this. Todo: adjust a test to catch this. (Will close when I have a test that catches this)

@henryiii henryiii reopened this Aug 8, 2020
@YannickJadoul
Copy link
Collaborator

Thanks, once again, @henryiii! :-)

@MonkeyBreaker
Copy link
Author

Great, everything works now fine :) !

Thank you so much for the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants