python source code compilation issues when using Cython

102 views
Skip to first unread message

Venkatacharyulu B

unread,
Sep 16, 2022, 6:28:42 AM9/16/22
to cython-users
Hi,

To protect my python source code module, I am trying to compile source code using Cython. But compilation is failing with below errors.

Please help us in providing resolution.

@CythonSupport,
Also we would like to know that we can get any support/training on Cython related issues. If yes, please let us know contact details to connect with.
 
*********************************************************setup.py**************************************************************
# several files with ext .pyx, that i will call by their name
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("NSGAIII", ["NSGAIII/AlgorithmFuncs.py", "NSGAIII/CrossoverMutation.py", 'NSGAIII/CrowdingDistAss.py','NSGAIII/Evolution.py', "NSGAIII/niching.py", "NSGAIII/NonDominatedSorting.py","NSGAIII/normalization.py", "NSGAIII/NSGA3.py", "NSGAIII/plotting.py","NSGAIII/problemDef.py", "NSGAIII/referencePoints.py", "NSGAIII/Selection.py"])]

setup(
  name = 'MyProject',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules,
)
*********************************************************setup.py**************************************************************
> python setup.py build_ext --inplace

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Apps\Anaconda3\v3_8_5_x64\Local\libs /LIBPATH:C:\Apps\Anaconda3\v3_8_5_x64\Local\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64" /EXPORT:PyInit_NSGAIII build\temp.win-amd64-3.8\Release\NSGAIII\AlgorithmFuncs.obj build\temp.win-amd64-3.8\Release\NSGAIII\CrossoverMutation.obj build\temp.win-amd64-3.8\Release\NSGAIII\CrowdingDistAss.obj build\temp.win-amd64-3.8\Release\NSGAIII\Evolution.obj build\temp.win-amd64-3.8\Release\NSGAIII\niching.obj build\temp.win-amd64-3.8\Release\NSGAIII\NonDominatedSorting.obj build\temp.win-amd64-3.8\Release\NSGAIII\normalization.obj build\temp.win-amd64-3.8\Release\NSGAIII\NSGA3.obj build\temp.win-amd64-3.8\Release\NSGAIII\plotting.obj build\temp.win-amd64-3.8\Release\NSGAIII\problemDef.obj build\temp.win-amd64-3.8\Release\NSGAIII\referencePoints.obj build\temp.win-amd64-3.8\Release\NSGAIII\Selection.obj /OUT:C:\Users\503245630\Documents\CythonSamples\NSGTest\mytest\NSGAIII.cp38-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.8\Release\NSGAIII\NSGAIII.cp38-win_amd64.lib
CrossoverMutation.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
CrossoverMutation.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
CrowdingDistAss.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
CrowdingDistAss.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
Evolution.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
Evolution.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
niching.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
niching.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
NonDominatedSorting.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
NonDominatedSorting.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
normalization.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
normalization.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
NSGA3.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
NSGA3.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
plotting.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
plotting.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
problemDef.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
problemDef.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
referencePoints.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
referencePoints.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
Selection.obj : error LNK2005: __pyx_module_is_main_NSGAIII already defined in AlgorithmFuncs.obj
Selection.obj : error LNK2005: PyInit_NSGAIII already defined in AlgorithmFuncs.obj
   Creating library build\temp.win-amd64-3.8\Release\NSGAIII\NSGAIII.cp38-win_amd64.lib and object build\temp.win-amd64-3.8\Release\NSGAIII\NSGAIII.cp38-win_amd64.exp
C:\Users\503245630\Documents\CythonSamples\NSGTest\mytest\NSGAIII.cp38-win_amd64.pyd : fatal error LNK1169: one or more multiply defined symbols found
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\link.exe' failed with exit status 1169

Kind Regards,
Venkat

Jérôme Kieffer

unread,
Sep 16, 2022, 5:05:46 PM9/16/22
to cython...@googlegroups.com
On Thu, 15 Sep 2022 23:08:07 -0700 (PDT)
Venkatacharyulu B <venkat...@gmail.com> wrote:

> To protect my python source code module, I am trying to compile source code
> using Cython. But compilation is failing with below errors.

Dear Venkat,

Cython has not been built as an obfuscation tool. The C-code is easy to
revert to Python, so it is not the right way to hide the algorithm.

You are trying to assemble several sub-modules, and I am not sure this
has been foreseen. If you would have each file compiled separately, it
should work, but not all together.

Best regards,

Jérôme

da-woods

unread,
Sep 17, 2022, 3:55:38 AM9/17/22
to cython...@googlegroups.com
Jérôme's right I think

> You are trying to assemble several sub-modules, and I am not sure this
> has been foreseen. If you would have each file compiled separately, it
> should work, but not all together.
>
This isn't supported by Cython itself but it is possible and there are a
few tools which help automate it:
https://github.com/smok-serwis/snakehouse and
https://github.com/dave-msk/merak. I haven't used either so couldn't
give you a recommendation though.

Venkatacharyulu B

unread,
Sep 21, 2022, 5:07:26 AM9/21/22
to cython-users
Thanks a lot Jerome and Woods for your response and guidance. 

I will try to explore tools on python code security.

Kind Regards,
Venkat

Reply all
Reply to author
Forward
0 new messages