discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SWIG doesn't recognize argument in make()


From: Stéphane Ancelot
Subject: Re: SWIG doesn't recognize argument in make()
Date: Tue, 17 Nov 2020 09:34:51 +0100

Hi guys,

Using swig using cmake is like using a blackbox and unfortunately is not consistent between cmake versions.
This is better to hardcode your own swig sequence in CMake

I have not any time to spend in the code at the moment, but I may give you some tips to avoid to use cmake swig integration .
This code snippet permits to use swig, but you have control on what will be done and understand what is done:


cmake_minimum_required(VERSION 3.10)
project(MyProject)

find_package(SWIG REQUIRED)


if(NOT WIN32)
        set(Python_ADDITIONAL_VERSIONS 2.7)
        find_package(PythonLibs 2.7 REQUIRED)
else(NOT WIN32)
        set(PYTHON_LIBRARIES "/C/python38/libs/python38.lib") #Msys 
        set(PYTHON_INCLUDE_DIRS "/C/python38/include")
endif(NOT WIN32)

include_directories(${PYTHON_INCLUDE_DIRS})

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_definitions("-DSWIG")

file(GLOB sources  control.h control.C)

add_custom_command(OUTPUT  control_preprocessed.h
                   COMMAND ${CMAKE_COMMAND} -E echo "Phase 1 : Generation control_preprocessed.h."
                   COMMAND ${CMAKE_C_COMPILER} -E   -P -DSWIG  -I(optionals include dir) control.h -o ${CMAKE_CURRENT_BINARY_DIR}/control_preprocessed.h
                   COMMAND ${CMAKE_COMMAND} -E echo "Done."
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.i
                   DEPENDS ${sources})


set_source_files_properties(control.i PROPERTIES CPLUSPLUS ON)

add_custom_command(OUTPUT  control_wrap.cpp
                   COMMAND ${CMAKE_COMMAND} -E echo "Phase2: generating control_wrap.cpp"
                   COMMAND ${SWIG_EXECUTABLE} -c++ -python -I${CMAKE_CURRENT_BINARY_DIR}  -o ${CMAKE_CURRENT_BINARY_DIR}/control_wrap.cpp control.i
                   COMMAND ${CMAKE_COMMAND} -E echo "Done."
                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                   DEPENDS control_preprocessed.h)


                   
# generating shared library .so/.dll
add_library(control SHARED control.h
                                                   ${CMAKE_CURRENT_BINARY_DIR}/control_wrap.cpp
                                                   control.C)
set_target_properties(control PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
set_target_properties(control PROPERTIES PREFIX "")  # removes lib prefix from target name

if (WIN32)
    set_target_properties(control PROPERTIES SUFFIX ".pyd") 
endif(WIN32)

set_target_properties(control PROPERTIES OUTPUT_NAME "_control") # rename shared lib as _control.so

target_link_libraries(control python
                            ${CMAKE_DL_LIBS})


set(COPY_TO_PATH control_shadow.py)
add_custom_command(TARGET control POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy control.py ${COPY_TO_PATH}
                   COMMENT "Copying 'control.py' python file to '${COPY_TO_PATH}'")

install(TARGETS control DESTINATION ${INSTALL_DIRECTORY})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/control_shadow.py DESTINATION ${INSTALL_DIRECTORY})




Le mar. 17 nov. 2020 à 07:52, Lukas Haase <lukashaase@gmx.at> a écrit :
Hi Nick,

Indeed, I just removed the "2" and suddenly it works.
Insane. Totally crazy...

Lukas


Gesendet: Montag, 16. November 2020 um 20:09 Uhr
Von: "Nick Foster" <bistromath@gmail.com>
An: "Lukas Haase" <lukashaase@gmx.at>
Cc: "discuss-gnuradiognu.org" <discuss-gnuradio@gnu.org>, cinaed.simson@gmail.com
Betreff: Re: SWIG doesn't recognize argument in make()

You're not crazy. I've seen similar behavior. Does it work if you remove the underscore? The number?
 
Who can fathom the esoteric secrets of SWIG? 

On Mon, Nov 16, 2020 at 3:06 PM Lukas Haase <lukashaase@gmx.at[mailto:lukashaase@gmx.at]> wrote:Additional detail: I tried it again:

$ gr_modtool rm tx_msg2tag
$
$ gr_modtool add test
$ rm -rf build; mkdir build; cd build; cmake ..; make

--> WORKS!!

$ gr_modtool add tx_msg2tag
$ rm -rf build; mkdir build; cd build; cmake ..; make

--> FAILS with the error below.


(of course, I edited the files to replace the <+...+> to make it compile).

It really seems it's the name of the block (tx_msg2tag) that makes things fail.
How can that be?

Lukas

Lukas wrote:
> Hi Cinaed,
>
> *I* am the author of gr-petro ;-)
> This is indeed a SWIG question. Or a question about OOT modules.
>
> I created the module with gr_modtool. I inserted bunch of blocks with "add"
> command. Just this one below does not work. I have no idea why (and it drives
> me crazy).
>
> Hence my questions:
> - What could be the issue?
> - What exactly generates *swigPYTHON_wrap.cxx files ?
> - How are the argument lists for the functions determined?
>
> Thanks,
> Lukas
>
>
>> Hi Lukas - gr-petro is a OOT module - an "out of tree "module - it's not
>> part of gnuradio.
>>
>> You need to contact the author of the module.
>>
>> It's highly unlikely it's a problem with make - it's more likely a
>> mismatch between gr-petro and your installed version of gnuradio.
>>
>> For instance, the OOT was written for a version of gnuradio prior to
>> 3.8.
>>
>> In any case, I couldn't find the gr-petro source code with a Google
>> search so I can't even guess what the problem might be. It also helps to
>> state which OS you're using.
>>
>> -- Cinaed
>>
>>> Hi everyone,
>>>
>>> It's driving me NUTS! SWIG just won't recognize an argument to my make()
>>> function and hence build fails. I have other nearly identical blocks in
>>> the same module that work without issues.
>>>
>>> What exactly generates the *swigPYTHON_wrap.cxx files and how are the
>>> argument lists for the functions determined?
>>>
>>> Here is how my make fails:
>>>
>>> [ 77%] Building CXX object
>>> swig/CMakeFiles/petro_swig.dir/CMakeFiles/petro_swig.dir/petro_swigPYTHO
>>> N_wrap.cxx.o
>>> /home/petro/src/gr38/gr-petro/build/swig/CMakeFiles/petro_swig.dir/petro
>>> _swigPYTHON_wrap.cxx: In function ‘PyObject*
>>> _wrap_tx_msg2tag_make(PyObject*, PyObject*)’:
>>> /home/petro/src/gr38/gr-petro/build/swig/CMakeFiles/petro_swig.dir/petro
>>> _swigPYTHON_wrap.cxx:18687:48: error: no matching function for call to
>>> ‘gr::petro::tx_msg2tag::make()’ 18687 | result =
>>> gr::petro::tx_msg2tag::make(); |
>>> ^ In file included from
>>> /home/petro/src/gr38/gr-petro/build/swig/CMakeFiles/petro_swig.dir/petro
>>> _swigPYTHON_wrap.cxx:2881:
>>> /home/petro/src/gr38/gr-petro/lib/../include/petro/tx_msg2tag.h:48:19:
>>> note: candidate: ‘static gr::petro::tx_msg2tag::sptr
>>> gr::petro::tx_msg2tag::make(unsigned int)’ 48 | static sptr
>>> make(unsigned int time_increment_factor); | ^~~~
>>> /home/petro/src/gr38/gr-petro/lib/../include/petro/tx_msg2tag.h:48:19:
>>> note: candidate expects 1 argument, 0 provided
>>> /home/petro/src/gr38/gr-petro/build/swig/CMakeFiles/petro_swig.dir/petro
>>> _swigPYTHON_wrap.cxx: In function ‘PyObject*
>>> _wrap_tx_msg2tag_sptr_make(PyObject*, PyObject*)’:
>>> /home/petro/src/gr38/gr-petro/build/swig/CMakeFiles/petro_swig.dir/petro
>>> _swigPYTHON_wrap.cxx:18914:30: error: no matching function for call to
>>> ‘gr::petro::tx_msg2tag::make()’ 18914 | result = (*arg1)->make();
>>> | ^ In file included from
>>> /home/petro/src/gr38/gr-petro/build/swig/CMakeFiles/petro_swig.dir/petro
>>> _swigPYTHON_wrap.cxx:2881:
>>> /home/petro/src/gr38/gr-petro/lib/../include/petro/tx_msg2tag.h:48:19:
>>> note: candidate: ‘static gr::petro::tx_msg2tag::sptr
>>> gr::petro::tx_msg2tag::make(unsigned int)’ 48 | static sptr
>>> make(unsigned int time_increment_factor); | ^~~~
>>> /home/petro/src/gr38/gr-petro/lib/../include/petro/tx_msg2tag.h:48:19:
>>> note: candidate expects 1 argument, 0 provided make[2]: ***
>>> [swig/CMakeFiles/petro_swig.dir/build.make:63:
>>> swig/CMakeFiles/petro_swig.dir/CMakeFiles/petro_swig.dir/petro_swigPYTHO
>>> N_wrap.cxx.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:466:
>>> swig/CMakeFiles/petro_swig.dir/all] Error 2 make: *** [Makefile:141:
>>> all] Error 2
>>>
>>> As can be very, very clearly seen, tx_msg2tag::make(unsigned int) has
>>> ONE parameter (time_increment_factor). Yet SWIG wants to call
>>> gr::petro::tx_msg2tag::make().
>>>
>>> I have tried regenerating the file, deleting build directory and
>>> starting from scratch but this error follows me like a nightmare.
>>>
>>> Thanks for suggestions!
>>>
>>> Lukas


 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]