# Need help using swig

**URL:** https://discourse.cmake.org/t/need-help-using-swig/13791
**Category:** Usage
**Created:** [March 22, 2025, 11:46am UTC](https://discourse.cmake.org/t/need-help-using-swig/13791 "2025-03-22T11:46:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![emanuel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/ecc23a/32.png) [@emanuel](https://discourse.cmake.org/u/emanuel)
#### Post date: [March 22, 2025, 11:46am UTC](https://discourse.cmake.org/t/need-help-using-swig/13791/1 "2025-03-22T11:46:05Z")

</div>

Hello, I’m brand new to CMake.  
I’ve been building interpreters into LibreCAD for a while now.  
It works well with QtCreator.  
LibreCAD also has a Pixi build with CMake.

> <https://github.com/emanuel4you/LibreCAD/blob/developer/CMakeLists.txt#L1711>

I’m trying in vain to port my configs.

> <https://github.com/emanuel4you/LibreCAD/blob/developer/librecad/src/python.pri>

The result is an executable file named “librecad” with the Python module “\_librecad” built in (with QtCreator or with make).

When I try this with CMake using swig\_add\_library(librecad…), I get the message that the target “librecad” already exists. If I specify \_librecad in swig\_add\_library(\_librecad) and link “\_librecad” with “librecad”, I get the message:

CMakeFiles/librecad.dir/librecad/src/lib/scripting/rs\_python.cpp.o: in function `RS_Python::RS_Python()': rs_python.cpp:(.text+0x48b4): undefined reference to `PyInit\_\_librecad’

because swig now creates \_\_librecad.a, not \_librecad.a.

With QtCreator or make, I don’t even have to explicitly link it or set swig to -builtin. It works like this (python.pri).  
Please help me.

> … \_\_librecad.a /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libQt6PrintSupport.so.6.8.2 /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libQt6Widgets.so.6.8.2 /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libQt6Svg.so.6.8.2 /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libQt6Gui.so.6.8.2 /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libGL.so /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libQt6Network.so.6.8.2 /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libQt6Core.so.6.8.2 -pthread /home/emanuel/projects/LibreCAD/.pixi/envs/default/lib/libpython3.13.so && :  
> /home/emanuel/projects/LibreCAD/.pixi/envs/default/bin/…/lib/gcc/aarch64-conda-linux-gnu/13.3.0/…/…/…/…/aarch64-conda-linux-gnu/bin/ld: CMakeFiles/librecad.dir/librecad/src/lib/scripting/rs\_python.cpp.o: in function `RS_Python::RS_Python()': rs_python.cpp:(.text+0x48b4): undefined reference to `PyInit\_\_librecad’  
> /home/emanuel/projects/LibreCAD/.pixi/envs/default/bin/…/lib/gcc/aarch64-conda-linux-gnu/13.3.0/…/…/…/…/aarch64-conda-linux-gnu/bin/ld: rs\_python.cpp:(.text+0x48b8): undefined reference to `PyInit\_\_librecad’  
> collect2: error: ld returned 1 exit status  
> ninja: build stopped: subcommand failed.  
> emanuel@raspberrypi:~/projects/LibreCAD $

---

<div class="post-metadata">

### Author: ![emanuel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/ecc23a/32.png) [@emanuel](https://discourse.cmake.org/u/emanuel)
#### Post date: [March 23, 2025, 12:00pm UTC](https://discourse.cmake.org/t/need-help-using-swig/13791/2 "2025-03-23T12:00:55Z")

</div>

set\_property(TARGET librepython PROPERTY OUTPUT\_NAME librecad)

LOL
